From 97e60abb37126bb7165ec66197459f0b08320f88 Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Fri, 20 Sep 2024 00:11:09 +0200 Subject: [PATCH] First try to get version from installed package. If packate is not installed, try to get it from the git tree --- eessi/testsuite/__init__.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/eessi/testsuite/__init__.py b/eessi/testsuite/__init__.py index 0cc13fa5..0e08b1a1 100644 --- a/eessi/testsuite/__init__.py +++ b/eessi/testsuite/__init__.py @@ -1,10 +1,14 @@ +from importlib.metadata import version, PackageNotFoundError try: - from setuptools_scm import get_version - # Using a relative path for relative_to doesn't work, because it will be relative to the current working - # directory (which could be anywhere) - # __file__ is the location of this init file (a full path), and this gives us a predictable path to the root - # (namely: two levels up) - # Note that if we ever move this __init__ file relative to the root of the git tree, we'll need to adjust this - __version__ = get_version(root='../..', relative_to=__file__) -except ImportError: - __version__ = "0.0.0" # fallback version if setuptools_scm is not available + __version__ = version("eessi-testsuite") +except PackageNotFoundError: + try: + from setuptools_scm import get_version + # Using a relative path for relative_to doesn't work, because it will be relative to the current working + # directory (which could be anywhere) + # __file__ is the location of this init file (a full path), and this gives us a predictable path to the root + # (namely: two levels up) + # Note that if we ever move this __init__ file relative to the root of the git tree, we'll need to adjust this + __version__ = get_version(root='../..', relative_to=__file__) + except ImportError: + __version__ = "0.0.0" # fallback version if setuptools_scm is not available