clapper.config¶
Functionality to implement python-based config file parsing and loading.
Functions
|
Load a set of configuration files, in sequence. |
|
Convert the loaded module of |
|
Read and returns all resources that are registered on a entry-point group. |
- clapper.config.load(paths, context=None, entry_point_group=None, attribute_name=None)[source]¶
Load a set of configuration files, in sequence.
This method will load one or more configuration files. Every time a configuration file is loaded, the context (variables) loaded from the previous file is made available, so the new configuration file can override or modify this context.
- Parameters:
paths (
list
[str
|Path
]) – A list or iterable containing paths (relative or absolute) of configuration files that need to be loaded in sequence. Each configuration file is loaded by creating/modifying the context generated after each file readout.context (
dict
[str
,Any
] |None
) – If provided, start the readout of the first configuration file with the given context. Otherwise, create a new internal context.entry_point_group (
str
|None
) – If provided, it will treat non-existing file paths as entry point names under theentry_point_group
name.attribute_name (
str
|None
) – If provided, will look for theattribute_name
variable inside the loaded files. Paths ending withsome_path:variable_name
can override theattribute_name
. Theentry_point_group
must provided as wellattribute_name
is notNone
.
- Return type:
- Returns:
A module representing the resolved context, after loading the provided modules and resolving all variables. If
attribute_name
is given, the object with the givenattribute_name
name (or the name provided by user) is returned instead of the module.- Raises:
ImportError – If attribute_name is given but the object does not exist in the paths.
ValueError – If attribute_name is given but entry_point_group is not given.
- clapper.config.mod_to_context(mod)[source]¶
Convert the loaded module of
load()
to a dictionary context.This function removes all the variables that start and end with
__
.- Parameters:
mod (
ModuleType
) – a Python module, e.g., as returned byload()
.- Return type:
- Returns:
The context that was in
mod
, as a dictionary mapping strings to objects.
- clapper.config.resource_keys(entry_point_group, exclude_packages=(), strip=('dummy',))[source]¶
Read and returns all resources that are registered on a entry-point group.
Entry points from the given
exclude_packages
list are ignored. Notice we are usingimportlib.metadata
to load entry-points, and that that entry point distribution (.dist
attribute) was only added to Python in version 3.10. We therefore currently only verify if the named resource does not start with any of the strings provided in exclude_package`.- Parameters:
- Return type:
- Returns:
Alphabetically sorted list of resources matching your query