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')
Source code in calcipy/tasks/defaults.py
@beartype
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')`
"""
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.
Source code in calcipy/tasks/defaults.py
@beartype
def new_collection() -> Collection:
"""Initialize a collection with the combination of merged and project-specific defaults."""
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