Coverage for ase / dependencies.py: 100.00%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-30 08:22 +0000

1# fmt: off 

2 

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 import importlib.metadata 

15 

16 try: 

17 module = importlib.import_module(modname) 

18 except ImportError: 

19 return modname, 'not installed' 

20 

21 if modname == 'flask': 

22 version = importlib.metadata.version('flask') 

23 else: 

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

25 

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

27 

28 if modname == 'ase': 

29 githash = search_current_git_hash(module) 

30 if githash: 

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

32 

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

34 info = get_python_package_path_description(module) 

35 return name, info 

36 

37 

38def all_dependencies() -> list[tuple[str, str]]: 

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

40 'ase_ext', 'flask', 'psycopg2', 'pyamg'] 

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