Coverage for ase/dependencies.py: 100.00%
27 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1from functools import cache
3import ase
4from ase.utils import (
5 get_python_package_path_description,
6 search_current_git_hash,
7)
10def format_dependency(modname: str) -> tuple[str, str]:
11 """Return (name, info) for given module.
13 If possible, info is the path to the module's package."""
14 import importlib.metadata
16 try:
17 module = importlib.import_module(modname)
18 except ImportError:
19 return modname, 'not installed'
21 if modname == 'flask':
22 version = importlib.metadata.version('flask')
23 else:
24 version = getattr(module, '__version__', '?')
26 if modname == 'ase':
27 name = ase_version_info()
28 else:
29 name = f'{modname}-{version}'
31 # (only packages have __path__, but we are importing packages.)
32 info = get_python_package_path_description(module)
33 return name, info
36def all_dependencies() -> list[tuple[str, str]]:
37 names = [
38 'ase',
39 'numpy',
40 'scipy',
41 'matplotlib',
42 'spglib',
43 'ase_ext',
44 'flask',
45 'psycopg2',
46 'pyamg',
47 ]
48 return [format_dependency(name) for name in names]
51@cache
52def ase_version_info() -> str:
53 """Return "ase-<version>".
55 If ASE is installed from source, version includes shortened git hash."""
56 version = f'ase-{ase.__version__}'
57 githash = search_current_git_hash(ase)
58 if githash:
59 version += f'-{githash:.10}'
60 return version