Configuration Enums
Enums for runtime mode and conda implementation type.
source
CondaType
def CondaType(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
Type of conda implementation to use.
source
RuntimeMode
def RuntimeMode(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
Runtime mode for the plugin system.
Configuration Dataclasses
RuntimeConfig holds conda/environment settings. CJMConfig is the main configuration container with paths and runtime settings.
source
RuntimeConfig
def RuntimeConfig(
mode:RuntimeMode=<RuntimeMode.SYSTEM: 'system'>, conda_type:CondaType=<CondaType.CONDA: 'conda'>,
prefix:Optional=None, binaries:Dict=<factory>
)->None:
Runtime environment configuration.
source
CJMConfig
def CJMConfig(
runtime:RuntimeConfig=<factory>, data_dir:Path=<factory>, plugins_config:Path=<factory>,
models_dir:Optional=None
)->None:
Main configuration for cjm-plugin-system.
Configuration Loading
Functions for loading configuration with layered resolution:
- CLI flags (highest priority)
- Environment variables
cjm.yaml file
- Defaults (backward compatible)
source
load_config
def load_config(
config_path:Optional=None, # CLI --cjm-config
data_dir:Optional=None, # CLI --data-dir
conda_prefix:Optional=None, # CLI --conda-prefix
conda_type:Optional=None, # CLI --conda-type
)->CJMConfig: # Resolved configuration
Load config with layered resolution (CLI > env vars > yaml > defaults).
Global Config Access
Functions for getting and setting the module-level configuration singleton.
source
reset_config
def reset_config(
)->None:
Reset to unloaded state (for testing).
source
set_config
def set_config(
config:CJMConfig, # Configuration to set as current
)->None:
Set current config (called by CLI callback).
source
get_config
def get_config(
)->CJMConfig: # Current configuration
Get current config (loads defaults if not set).
Examples
# Test default configuration
reset_config()
cfg = get_config()
print("Default configuration:")
print(f" data_dir: {cfg.data_dir}")
print(f" manifests_dir: {cfg.manifests_dir}")
print(f" plugin_data_dir: {cfg.plugin_data_dir}")
print(f" logs_dir: {cfg.logs_dir}")
print(f" plugins_config: {cfg.plugins_config}")
print(f" runtime.mode: {cfg.runtime.mode}")
print(f" runtime.conda_type: {cfg.runtime.conda_type}")
Default configuration:
data_dir: /home/innom-dt/.cjm
manifests_dir: /home/innom-dt/.cjm/manifests
plugin_data_dir: /home/innom-dt/.cjm/data
logs_dir: /home/innom-dt/.cjm/logs
plugins_config: plugins.yaml
runtime.mode: RuntimeMode.SYSTEM
runtime.conda_type: CondaType.CONDA
# Test CLI override
reset_config()
cfg = load_config(data_dir=Path("/custom/path"))
print("With CLI override:")
print(f" data_dir: {cfg.data_dir}")
print(f" manifests_dir: {cfg.manifests_dir}")
print(f" plugin_data_dir: {cfg.plugin_data_dir}")
With CLI override:
data_dir: /custom/path
manifests_dir: /custom/path/manifests
plugin_data_dir: /custom/path/data
# Test dataclass creation
runtime = RuntimeConfig(
mode=RuntimeMode.LOCAL,
conda_type=CondaType.MINIFORGE,
prefix=Path("./runtime")
)
config = CJMConfig(
runtime=runtime,
data_dir=Path("./.cjm")
)
print("Custom configuration:")
print(f" runtime.mode: {config.runtime.mode}")
print(f" runtime.conda_type: {config.runtime.conda_type}")
print(f" runtime.prefix: {config.runtime.prefix}")
print(f" data_dir: {config.data_dir}")
Custom configuration:
runtime.mode: RuntimeMode.LOCAL
runtime.conda_type: CondaType.MINIFORGE
runtime.prefix: runtime
data_dir: .cjm
# Test conda_binary_path property
runtime_with_binaries = RuntimeConfig(
conda_type=CondaType.MICROMAMBA,
mode=RuntimeMode.LOCAL,
prefix=Path("./runtime"),
binaries={"linux-x64": Path("./runtime/bin/micromamba")}
)
config_with_binaries = CJMConfig(runtime=runtime_with_binaries)
print(f"conda_binary_path (from binaries): {config_with_binaries.conda_binary_path}")
# Test default path generation when binaries not specified
runtime_no_binaries = RuntimeConfig(
conda_type=CondaType.MICROMAMBA,
mode=RuntimeMode.LOCAL,
prefix=Path("./runtime")
)
config_no_binaries = CJMConfig(runtime=runtime_no_binaries)
print(f"conda_binary_path (default): {config_no_binaries.conda_binary_path}")
conda_binary_path (from binaries): runtime/bin/micromamba
conda_binary_path (default): runtime/bin/micromamba