Coverage for /builds/debichem-team/python-ase/ase/dependencies.py: 100.00%

19 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-03-06 04:00 +0000

1import importlib 

2from typing import List, Tuple 

3 

4from ase.utils import ( 

5 get_python_package_path_description, 

6 search_current_git_hash, 

7) 

8 

9 

10def format_dependency(modname: str) -> Tuple[str, str]: 

11 """Return (name, info) for given module. 

12 

13 If possible, info is the path to the module's package.""" 

14 try: 

15 module = importlib.import_module(modname) 

16 except ImportError: 

17 return modname, 'not installed' 

18 

19 version = getattr(module, '__version__', '?') 

20 name = f'{modname}-{version}' 

21 if modname == 'ase': 

22 githash = search_current_git_hash(module) 

23 if githash: 

24 name += f'-{githash:.10}' 

25 

26 # (only packages have __path__, but we are importing packages.) 

27 info = get_python_package_path_description(module) 

28 return name, info 

29 

30 

31def all_dependencies() -> List[Tuple[str, str]]: 

32 names = ['ase', 'numpy', 'scipy', 'matplotlib', 'spglib', 

33 'ase_ext', 'flask', 'psycopg2', 'pyamg'] 

34 return [format_dependency(name) for name in names]