From 745b40f3de4802972407b498113e70c864821ac5 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 4 Jun 2024 21:09:16 -0700 Subject: [PATCH] version tests --- tests/test_version.py | 5 +++++ ucp/_version.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/test_version.py b/tests/test_version.py index ffb5152e6..1b77632ef 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -9,6 +9,11 @@ def test_get_ucx_version(): assert ucp.core._ctx is None +def test_git_commit_constant(): + # __git_commit__ will only be non-empty in a built distribution + assert isinstance(ucp.__git_commit__, str) + + def test_version_constant(): assert isinstance(ucp.__version__, str) diff --git a/ucp/_version.py b/ucp/_version.py index ab2f6e9f8..3aa963c10 100644 --- a/ucp/_version.py +++ b/ucp/_version.py @@ -14,5 +14,18 @@ import importlib.resources -__version__ = importlib.resources.files("ucp").joinpath("VERSION").read_text().strip() -__git_commit__ = "" +__version__ = ( + importlib.resources.files(__package__).joinpath("VERSION").read_text().strip() +) + +try: + __git_commit__ = ( + importlib.resources.files(__package__) + .joinpath("GIT_COMMIT") + .read_text() + .strip() + ) +except FileNotFoundError: + __git_commit__ = "" + +__all__ = ["__git_commit__", "__version__"]