Skip to content

Commit

Permalink
Move _version to meta. (#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper authored Sep 12, 2022
1 parent cf4edf4 commit 496f250
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
src/gluonts/_static_version.py export-subst
src/gluonts/meta/_version.py export-subst
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from pkgutil import extend_path

from ._version import __version__
from .meta._version import __version__

__all__ = ["__version__", "__path__"]

Expand Down
22 changes: 12 additions & 10 deletions src/gluonts/_version.py → src/gluonts/meta/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -245,6 +250,3 @@ def make_release_tree(self, base_dir, files):


__version__ = get_version(fallback="0.0.0")

if __name__ == "__main__":
print(__version__)

0 comments on commit 496f250

Please sign in to comment.