pyrevs.core.config
A configuration class to expose limited configuration.
Classes
MergePolicy
|
A merge policy for configuration dataclasses. |
Config
|
Lightweight structured access to configuration. |
Functions
collect_sections(*configs) → dict[str, Any]
|
Build a TOML-ready dict from config dataclasses. |
merge_config(old, new) → T
|
Merge two configuration dataclass objects. |
print_config_help(cls) → None
|
Print a help for a pyREVS config dataclass. |
Module Contents
-
T[source]
-
class MergePolicy[source]
A merge policy for configuration dataclasses.
-
IMMUTABLE = 'immutable'[source]
-
REPLACE = 'replace'[source]
-
class Config(data: collections.abc.Mapping[str, Any])[source]
Lightweight structured access to configuration.
pyREVS input parameters are mostly handled through dataclasses
to ensure default values are available and types are enforced:
TOML file -> Config -> Typed dataclass.
The typed dataclass are the final object used to instanciate
pyREVS objects (Sampler, Database, Trajectories, …)
The Config class provides a simple interface to access configuration
parameters in a more structured way. To add a new section to
the TOML input file, create a new dataclass with a __section__
class attribute set to the name of the section.
-
section(name: str) → Config[source]
Return a configuration section.
-
section_dict(name: str) → dict[str, Any][source]
Return a section as dict.
-
require(section: str, key: str) → Any[source]
Get a required parameter.
-
get(section: str, key: str, default: Any = None) → Any[source]
Get an optional parameter.
-
as_dict() → dict[str, Any][source]
Return the config Mapping as a dict.
-
load(cls: type[T]) → T[source]
Load a dataclass of the provided type from this config section.
-
collect_sections(*configs: Any) → dict[str, Any][source]
Build a TOML-ready dict from config dataclasses.
Each dataclass must define __section__.
-
merge_config(old: T, new: T) → T[source]
Merge two configuration dataclass objects.
-
print_config_help(cls: type) → None[source]
Print a help for a pyREVS config dataclass.