Coverage for calorine/env.py: 100%
7 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-23 12:50 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-23 12:50 +0000
1from os import getenv
4def calorine_getenv(variable) -> str:
5 """Get value of environment variable, or default.
7 Possible environment variables are:
9 - `CALORINE_GPUMD_COMMAND` - Command used by
10 :class:`GPUNEP <calorine.calculators.GPUNEP>` to invoke the ``gpumd``
11 executable. Default: ``'gpumd'``.
12 - `CALORINE_NEP_COMMAND` - Command used by :func:`batch_predict_properties
13 <calorine.tools.batch_predict_properties>` to invoke the ``nep``
14 executable. Default: ``'nep'``.
16 Parameters
17 ----------
18 variable
19 Name of variable, without the ``'CALORINE_'`` prefix.
21 Returns
22 -------
23 Value of variable as string.
24 """
25 defaults = {'GPUMD_COMMAND': 'gpumd', 'NEP_COMMAND': 'nep'}
27 if variable not in defaults:
28 allowed = '\n'.join(f' CALORINE_{var}' for var in defaults)
29 raise ValueError(f'Environment variable CALORINE_{variable} is unknown. '
30 f'Allowed variables are:\n{allowed}')
32 return getenv(f'CALORINE_{variable}', defaults[variable])