Defaults
Calcipy-Invoke Defaults.
Classes⚓︎
Functions⚓︎
from_ctx ⚓︎
from_ctx(ctx, group, key)
Safely extract the value from the context or the defaults.
Instead of ctx.tests.out_dir use from_ctx(ctx, 'test', 'out_dir')
| RETURNS | DESCRIPTION |
|---|---|
str
|
The configuration value as a string. |
Source code in calcipy/tasks/defaults.py
def from_ctx(ctx: Context, group: str, key: str) -> str:
"""Safely extract the value from the context or the defaults.
Instead of `ctx.tests.out_dir` use `from_ctx(ctx, 'test', 'out_dir')`
Returns:
The configuration value as a string.
"""
with suppress(KeyError):
return str(ctx.config[group][key])
return str(DEFAULTS[group][key])
new_collection ⚓︎
new_collection()
Initialize a collection with the combination of merged and project-specific defaults.
| RETURNS | DESCRIPTION |
|---|---|
Collection
|
Configured Collection instance. |
Source code in calcipy/tasks/defaults.py
def new_collection() -> Collection:
"""Initialize a collection with the combination of merged and project-specific defaults.
Returns:
Configured Collection instance.
"""
ns = Collection('')
# Merge default and user configuration
ns.configure(DEFAULTS)
config_path = Path('.calcipy.json')
if config_path.is_file():
ns.configure(json.loads(config_path.read_text(encoding='utf-8')))
return ns