gws.config.loader¶
Configuration loader: configure, save and load the root object.
Source code: gws.config.loader
Module Contents¶
- gws.config.loader.configure(manifest_path='', config_path='', specs: gws.SpecRuntime | None = None, raw_config: dict | gws.Data = None, fallback_config: dict | gws.Data = None, with_spec_cache=False, hooks: list = None) gws.ConfigResult¶
Parse the configuration and create the root object.
- Parameters:
manifest_path – Path to the application manifest.
config_path – Path to the configuration file.
specs – Specs to use. If not given, specs are created from the manifest.
raw_config – Configuration dict, used instead of the configuration file.
fallback_config – Configuration used when the main configuration fails.
with_spec_cache – Read and write the specs cache.
hooks – List of
(event, fn)pairs, seeObject.configure.
- Returns:
The configuration result. Its
rootisNoneif configuration failed.
- gws.config.loader.initialize(specs: gws.SpecRuntime, config: gws.Config) gws.Root¶
Create the root object and the application from a parsed configuration.
- Parameters:
specs – Specs runtime.
config – Parsed application configuration.
- Returns:
The initialized, not yet activated root object.
- gws.config.loader.load(path=None) gws.Root¶
Load a saved root object, see
gws.load_root, and log the user, time and memory used.- Parameters:
path – File path. Defaults to
config.picklein the config directory.- Returns:
The root object.
- Raises:
gws.ConfigurationError – If the root cannot be loaded or activated.
- gws.config.loader.log_report(cr: gws.ConfigResult)¶
Log a summary of the configuration result and all errors and warnings.
- Parameters:
cr – Configuration result.
- class gws.config.loader.Object(manifest_path='', config_path='', specs=None, raw_config=None, fallback_config=None, with_spec_cache=False, hooks=None)¶
Configuration loader.
Holds the state of one configuration run: the specs, the parsed config, the root object and the collected errors and warnings.
- config = None¶
- ctx: gws.ConfigContext¶
Context with specs, errors, warnings and read paths.
- fallbackConfig: gws.Config | None¶
Configuration used when the main configuration fails, if the manifest allows it.
- hooks = []¶
- rawConfig = None¶
- root = None¶
- specs = None¶
- tm1¶
- configure() gws.ConfigResult¶
Parse the configuration and create the root object.
Hooks are called with the loader object at the events
preConfigure,postConfigure(around parsing),preInitializeandpostInitialize(around creating the root). Exceptions in hooks are recorded as errors.If no root can be created, the fallback config is used, provided the manifest sets
withFallbackConfig. If there are errors and the manifest setswithStrictConfig, the root is discarded.- Returns:
The configuration result.
- parse() gws.ConfigResult¶
Parse and validate the configuration without creating objects.
- Returns:
The configuration result, without the root object.
- gws.config.loader.parse(manifest_path='', config_path='', specs: gws.SpecRuntime | None = None) gws.ConfigResult¶
Parse and validate the configuration without creating objects.
- Parameters:
manifest_path – Path to the application manifest.
config_path – Path to the configuration file.
specs – Specs to use. If not given, specs are created from the manifest.
- Returns:
The configuration result with the parsed config, errors and warnings.
- gws.config.loader.real_config_path(config_path: str) str¶
Find the configuration file.
- Parameters:
config_path – Comma-separated list of paths. Defaults to the
GWS_CONFIGenvironment variable. If neither is given, the default paths are checked.- Returns:
The first path that is an existing file, or an empty string.
- gws.config.loader.real_manifest_path(manifest_path: str) str¶
Find the application manifest.
- Parameters:
manifest_path – Manifest path. Defaults to the
GWS_MANIFESTenvironment variable. If neither is given, the default path/data/MANIFEST.jsonis used if it exists.- Returns:
The manifest path, or an empty string.
- gws.config.loader.save(root: gws.Root, path=None) str¶
Save the root object to a file, see
gws.save_root.- Parameters:
root – Root object.
path – File path. Defaults to
config.picklein the config directory.
- Returns:
The file path.
- Raises:
gws.ConfigurationError – If the root cannot be saved.