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

12 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-14 15:25 +0000

1import os 

2import pathlib 

3from importlib import metadata as metadata_py 

4 

5# import setuptools_git_versioning 

6from .. import version_storage 

7 

8 

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

10 __version__ = metadata_py.version(package_name) 

11 __git_is_dirty__ = False 

12 

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

14 

15 version_storage.__version__ = __version__ 

16 version_storage.__git_is_dirty__ = __git_is_dirty__ 

17 version_storage.__git_short_hash__ = __git_short_hash__ 

18 

19 # # Get "__version__" 

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

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

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

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

24 # if use_pyproject_toml: 

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

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

27 # pwd = os.getcwd() 

28 # os.chdir(path_to_pyproject_toml) 

29 # __version__ = setuptools_git_versioning.version_from_git() 

30 # os.chdir(pwd) 

31 # else: 

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

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

34 # # pip install gas 

35 # # pip install . 

36 # # pip install -e . 

37 # __version__ = metadata_py.version(package_name) 

38 

39 # # Get git short hash 

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

41 # __git_is_dirty__ = '.dirty' in __version__ 

42 

43 return __git_is_dirty__, __git_short_hash__, __version__