CodeEntropy.config.argparse module

Configuration and CLI argument management for CodeEntropy.

This module provides:

  1. A declarative argument specification (ARG_SPECS) used to build an argparse.ArgumentParser.

  2. A ConfigResolver that:

    • loads YAML configuration if present,

    • merges YAML values with CLI values, with CLI values taking precedence,

    • fills missing defaults,

    • auto-detects conda/mamba settings for HPC runs,

    • adjusts logging verbosity,

    • validates a subset of runtime inputs against the trajectory.

Notes:

  • Boolean arguments are parsed via str2bool to support YAML/CLI interop and common string forms like “true”/”false”.

class CodeEntropy.config.argparse.ArgSpec(help: str, default: Any = None, type: Any = None, action: str | None = None, nargs: str | None = None)[source]

Bases: object

Argument specification used to build an argparse parser.

Variables:
  • help (str) – Help text shown in CLI usage.

  • default (Any) – Default value if not provided via CLI or YAML.

  • type (Any) – Python type for parsing, such as int, float, str, or bool.

  • action (str | None) – Optional argparse action, such as “store_true”.

  • nargs (str | None) – Optional nargs spec, such as “+”.

action: str | None = None
default: Any = None
help: str
nargs: str | None = None
type: Any = None
class CodeEntropy.config.argparse.ConfigResolver(arg_specs: dict[str, ArgSpec] | None = None)[source]

Bases: object

Load, merge, and validate CodeEntropy configuration.

build_parser() ArgumentParser[source]

Build an ArgumentParser from the argument specs.

Returns:

Configured argparse.ArgumentParser.

load_config(directory_path: str) dict[str, Any][source]

Load the first YAML config file found in a directory.

Parameters:

directory_path – Directory to search for YAML files.

Returns:

Configuration dictionary.

resolve(args: Namespace, run_config: dict[str, Any] | None) Namespace[source]

Merge CLI arguments with YAML configuration and fill defaults.

Merge rule:
  • CLI explicitly provided values take precedence.

  • YAML values fill in values not provided by CLI.

  • Defaults fill in anything still unset.

  • HPC conda/mamba settings are auto-detected if missing.

Parameters:
  • args – Parsed CLI arguments.

  • run_config – Dict of YAML values for a specific run, or None.

Returns:

Mutated argparse.Namespace with merged values.

Raises:

TypeError – If run_config is not a dict or None.

static str2bool(value: Any) bool[source]

Convert a string or boolean input into a boolean.

Parameters:

value – Input value to convert.

Returns:

Corresponding boolean value.

Raises:

argparse.ArgumentTypeError – If the input cannot be interpreted as a boolean.

validate_inputs(u: Any, args: Namespace) None[source]

Validate user inputs against sensible runtime constraints.

Parameters:
  • u – MDAnalysis Universe or compatible object with a trajectory.

  • args – Parsed and merged arguments.

Raises:

ValueError – If a parameter is invalid.