Coverage for python/diagnostic_and_simulation_base/utility/get_version.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-07 13:12 +0000

1import os 

2import pathlib 

3from importlib import metadata as metadata_py 

4 

5# import setuptools_git_versioning 

6 

7from .. import version_storage 

8 

9 

10def get_version(package_name: str) -> tuple[bool, str, str]: 

11 __version__ = metadata_py.version(package_name) 

12 __git_is_dirty__ = False 

13 

14 __git_short_hash__ = __version__.split("git.")[1].replace(".dirty", "") if "git." in __version__ else "" 

15 

16 version_storage.__version__ = __version__ 

17 version_storage.__git_is_dirty__ = __git_is_dirty__ 

18 version_storage.__git_short_hash__ = __git_short_hash__ 

19 

20 # # Get "__version__" 

21 # # BUXTON: THIS WON'T WORK AS __file__ is no longer this file 

22 # path_to_pyproject_toml = os.path.dirname(__file__) + '/../../' 

23 # path_to_pyproject_toml = str(pathlib.Path(path_to_pyproject_toml).resolve()) 

24 # use_pyproject_toml = os.path.isfile(path_to_pyproject_toml + '/pyproject.toml') 

25 # if use_pyproject_toml: 

26 # # get "__version__" from "pyproject.toml" if "pyproject.toml" exists 

27 # # this will work if running locally, i.e. not installed 

28 # pwd = os.getcwd() 

29 # os.chdir(path_to_pyproject_toml) 

30 # __version__ = setuptools_git_versioning.version_from_git() 

31 # os.chdir(pwd) 

32 # else: 

33 # # Get "__version__" from python's package metadata 

34 # # This will work for all pip installation settings: 

35 # # pip install gas 

36 # # pip install . 

37 # # pip install -e . 

38 # __version__ = metadata_py.version(package_name) 

39 

40 # # Get git short hash 

41 # __git_short_hash__ = __version__.split("git.")[1].replace('.dirty', '') 

42 # __git_is_dirty__ = '.dirty' in __version__ 

43 

44 return __git_is_dirty__, __git_short_hash__, __version__