oarepo_config.base
oarepo_config.base
Base configuration utilities for oarepo-config.
DictWithGetAttr
Bases: dict
Dictionary that allows access to its items as attributes.
Source code in oarepo_config/base.py
__getattr__(item: str) -> Any
Get item from dictionary as attribute.
set_constants_in_caller(constants: dict[str, Any]) -> None
Set the constants in the caller's globals.
Example:
mymodule:
config:
Source code in oarepo_config/base.py
get_constant_from_caller(name: str, default: Any = None) -> Any
Get constant from the caller frame and optionally return a default value if not found.
Example:
mymodule:
config:
Source code in oarepo_config/base.py
merge_with_caller(name: str, to_merge: Any) -> Any
Merge the given value with an existing caller global of the same name.
Source code in oarepo_config/base.py
get_invenio_cfg_path() -> str | Path
Get the path to the invenio.cfg file.
Source code in oarepo_config/base.py
load_configuration_overrides() -> Config
cached
Read deployment configuration values from the current directory and the process environment.
This is the part of load_configuration_variables that does
not depend on the location of invenio.cfg: it merges, lowest
to highest priority, a variables file in the current working
directory, a .env file in the current working directory, any
.json/.yaml/.yml files under the directory named by the
INVENIO_CONFIG_PATH environment variable (if set), and finally
the actual process environment variables whose name starts with
INVENIO_.
Source code in oarepo_config/base.py
load_configuration_variables() -> DictWithGetAttr
cached
Read the deployment's configuration values (INVENIO_... variables).
Collects configuration values set by the deployment, from multiple places, each one able to override the previous (lowest to highest priority):
- a
variablesfile next toinvenio.cfg(the instance directory); - a
variablesfile in the current working directory; - a
.envfile in the current working directory; - any
.json/.yaml/.ymlfiles under the directory named by theINVENIO_CONFIG_PATHenvironment variable, if set; - the actual process environment variables (always wins).
Values such as "True"/"False" or JSON snippets are converted
to real Python types (booleans, numbers, lists, dicts) where
possible. The result can be accessed both as a dictionary and via
attribute access (e.g. env.INVENIO_SECRET_KEY); accessing a
variable that was never set raises AttributeError.
Source code in oarepo_config/base.py
transform_value(x: str | Any) -> Any
Convert string from environment to python type.
Source code in oarepo_config/base.py
find_files(directory: str | Path, extension: str) -> Iterator[Path]
Find all files with the given extension in the directory.
Source code in oarepo_config/base.py
load_config_from_directory(config_dir: str | Path, env: Config) -> Config
Load configuration from JSON/YAML files in the given directory.
Source code in oarepo_config/base.py
override_configuration(env: dict[str, Any] | None = None) -> None
Apply ad-hoc configuration overrides from the environment, without writing Python code.
Lets a deployment set (or override) any Invenio configuration value
directly from the variables/.env files or the process
environment, by prefixing its name with INVENIO_. For example,
setting INVENIO_RDM_ARCHIVE_DOWNLOAD_ENABLED=false in the
deployment's configuration will set the RDM_ARCHIVE_DOWNLOAD_ENABLED
setting to False, without needing to change invenio.cfg.
This is not applied automatically - call it explicitly from
invenio.cfg, typically as the very last step, so that these
overrides win over anything set by the configure_*() functions
above it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
dict[str, Any] | None
|
Normally left unset, in which case the values loaded from
|
None
|