diff --git a/.gitattributes b/.gitattributes index afda78adb2..10490b33e0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -src/gluonts/_static_version.py export-subst \ No newline at end of file +src/gluonts/meta/_version.py export-subst diff --git a/setup.py b/setup.py index 307d5c904e..09214726ed 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,9 @@ def get_version_and_cmdclass(version_file): return globals_["__version__"], globals_["cmdclass"]() -version, version_cmdclass = get_version_and_cmdclass("src/gluonts/_version.py") +version, version_cmdclass = get_version_and_cmdclass( + "src/gluonts/meta/_version.py" +) class TypeCheckCommand(distutils.cmd.Command): diff --git a/src/gluonts/__init__.py b/src/gluonts/__init__.py index baa592ab11..30cbec2654 100644 --- a/src/gluonts/__init__.py +++ b/src/gluonts/__init__.py @@ -16,7 +16,7 @@ from pkgutil import extend_path -from ._version import __version__ +from .meta._version import __version__ __all__ = ["__version__", "__path__"] diff --git a/src/gluonts/_version.py b/src/gluonts/meta/_version.py similarity index 92% rename from src/gluonts/_version.py rename to src/gluonts/meta/_version.py index 8c8241431f..e5743986f0 100644 --- a/src/gluonts/_version.py +++ b/src/gluonts/meta/_version.py @@ -81,7 +81,7 @@ def get_version_and_cmdclass(version_file): "--match=v[0-9]*", ] -SEARCH_PACKAGE_LEVELS = 2 +SEARCH_PACKAGE_LEVELS = 4 def search_for(name: str, where: Path, levels: int = 0): @@ -90,21 +90,21 @@ def search_for(name: str, where: Path, levels: int = 0): if candidate.exists(): return candidate - if levels == 0 or where == where.parent: - return None + if levels == 0 or where == where.parent or where is None: + raise RuntimeError(f"Can not find {name}.") levels -= 1 where = where.parent file_name = Path(__file__).name # this files name -package_root = Path(__file__).resolve().parent +package_root = Path(__file__).resolve().parents[1] # 2 levels up def dist_root(): return search_for( - "setup.py", package_root, levels=SEARCH_PACKAGE_LEVELS - ).parent + "setup.py", Path(__file__).parent, levels=SEARCH_PACKAGE_LEVELS + ).parent.resolve() class GitRepo: @@ -231,7 +231,12 @@ def write_version(target): class build_py(setuptools.command.build_py.build_py): def run(self): super().run() - write_version(Path(self.build_lib) / package_root.name) + + write_version( + Path(self.build_lib) + / package_root.name + / Path(__file__).parent.resolve().relative_to(package_root) + ) class sdist(setuptools.command.sdist.sdist): def make_release_tree(self, base_dir, files): @@ -245,6 +250,3 @@ def make_release_tree(self, base_dir, files): __version__ = get_version(fallback="0.0.0") - -if __name__ == "__main__": - print(__version__)