htesp.config¶
Configuration loading for HTESP.
This module replaces the original check_json.config(), which
looked only in
./config.jsonand then blindly at../../config.json,returned
Nonewhen nothing was found (every caller then raisedTypeErrorseveral frames later),re-parsed the file on each of its ~40 call sites, and
carried the Materials Project API key in the file itself.
The replacement
searches the current directory and its parents (up to
SEARCH_DEPTHlevels) plus$HTESP_CONFIG,deep-merges whatever it finds over the packaged default (
htesp/data/config.json), so a configuration written for an older schema still has every key the current code reads,caches the result per resolved path, and
takes the API key from
$MP_API_KEYor~/.config/htesp/credentialsin preference to the file.
The public entry point keeps the old name and the old return type:
from htesp.config import config
cfg = config() # plain dict, never None
Module Attributes
file name looked for in the working directory and its parents |
|
how many parent directories are searched above the working directory. |
|
packaged fallback -- the canonical, fully-populated schema |
|
environment variable holding the Materials Project API key |
|
file consulted when |
|
placeholder shipped in every example configuration |
|
keys every configuration must resolve to something usable |
Functions
|
Materials Project API key: environment, then credentials file, then config. |
Forget every parsed configuration (used by the tests). |
|
|
Return the effective configuration as a plain |
|
The file |
|
Return the first |
|
|
|
Return a list of human-readable problems with |
Exceptions
Raised by |
- htesp.config.CONFIG_FILENAME = 'config.json'¶
file name looked for in the working directory and its parents
- htesp.config.SEARCH_DEPTH = 5¶
how many parent directories are searched above the working directory. The bash layer runs helpers from
R<id>-<comp>/<stage>/(two levels), fromR<id>-<comp>/pressure/R.../relax(four levels) and one level deeper again for phonopy supercells, hence five.
- htesp.config.DEFAULT_CONFIG_PATH = PosixPath('/home/runner/work/HTESP/HTESP/htesp/data/config.json')¶
packaged fallback – the canonical, fully-populated schema
- htesp.config.API_KEY_ENV = 'MP_API_KEY'¶
environment variable holding the Materials Project API key
- htesp.config.CREDENTIALS_PATH = PosixPath('/home/runner/.config/htesp/credentials')¶
file consulted when
API_KEY_ENVis unset
- htesp.config.API_KEY_PLACEHOLDER = 'use_your_API_KEY'¶
placeholder shipped in every example configuration
- exception htesp.config.ConfigError[source]¶
Raised by
config()in strict mode and byrequire_api_key().
- htesp.config.find_config(start: PathLike | str | None = None) Path | None[source]¶
Return the first
config.jsonat or abovestart.$HTESP_CONFIGwins over the directory search, so a whole campaign can share one file without copying it into every working directory.
- htesp.config.config(start: PathLike | str | None = None, strict: bool = False) dict[source]¶
Return the effective configuration as a plain
dict.Always returns a usable mapping: when no
config.jsonis found the packaged default is returned, so importing a module no longer depends on the working directory.strict=TrueraisesConfigErrorinstead, for commands that genuinely need the user’s own settings.
- htesp.config.config_path(start: PathLike | str | None = None) Path | None[source]¶
The file
config()would read, orNonefor the packaged default.
- htesp.config.api_key(cfg: Mapping[str, Any] | None = None) str | None[source]¶
Materials Project API key: environment, then credentials file, then config.
Returns
Nonewhen only the shipped placeholder is available, so callers can give a useful message rather than sendinguse_your_API_KEYto the MP servers.
- htesp.config.require_api_key(cfg: Mapping[str, Any] | None = None) str[source]¶
api_key(), but raise a message that says how to set it.
- htesp.config.REQUIRED_SECTIONS = ('job_script', 'mpi_key', 'download', 'conv_test', 'magmom', 'pseudo', 'substitute', 'pwscf_in', 'strain', 'wanniertools_input', 'kptden', 'chull_cutoff', 'kpt_opt', 'elph_mode', 'plot')¶
keys every configuration must resolve to something usable