nirs4all.core.logging.context module

Run context management for nirs4all logging.

This module provides context managers for tracking run state, phases, branches, sources, and stacking operations in the logging system.

class nirs4all.core.logging.context.BranchContext(name: str, path: list[str] = <factory>, index: int | None = None, total: int | None = None, parent: str | None = None, depth: int = 0)[source]

Bases: object

Context for a branch in the pipeline.

Variables:
  • name (str) – Branch name.

  • path (list[str]) – Full branch path (for nested branches).

  • index (int | None) – Branch index (0-based).

  • total (int | None) – Total number of branches at this level.

  • parent (str | None) – Parent branch name (for nested branches).

  • depth (int) – Nesting depth (0 for top-level).

depth: int = 0
index: int | None = None
name: str
parent: str | None = None
path: list[str]
total: int | None = None
class nirs4all.core.logging.context.RunState(run_id: str, run_name: str | None = None, project: str | None = None, start_time: datetime = <factory>, current_phase: Phase | None = None, branch_stack: list[BranchContext] = <factory>, source_context: SourceContext | None = None, stack_context: StackContext | None = None, extra: dict[str, ~typing.Any]=<factory>)[source]

Bases: object

State for a single run.

Variables:
property branch_depth: int

Get the current branch nesting depth.

property branch_path: list[str]

Get the full branch path.

branch_stack: list[BranchContext]
property current_branch: BranchContext | None

Get the current (innermost) branch context.

current_phase: Phase | None = None
extra: dict[str, Any]
project: str | None = None
run_id: str
run_name: str | None = None
source_context: SourceContext | None = None
stack_context: StackContext | None = None
start_time: datetime
class nirs4all.core.logging.context.SourceContext(name: str, index: int | None = None, total: int | None = None)[source]

Bases: object

Context for a source in multi-source pipelines.

Variables:
  • name (str) – Source name.

  • index (int | None) – Source index (0-based).

  • total (int | None) – Total number of sources.

index: int | None = None
name: str
total: int | None = None
class nirs4all.core.logging.context.StackContext(n_branches: int, meta_model: str | None = None, branch_sources: list[str] = <factory>)[source]

Bases: object

Context for stacking operations.

Variables:
  • n_branches (int) – Number of branches being stacked.

  • meta_model (str | None) – Meta-model name/description.

  • branch_sources (list[str]) – List of branch names being stacked.

branch_sources: list[str]
meta_model: str | None = None
n_branches: int
nirs4all.core.logging.context.get_run_id() → str | None[source]

Get the current run ID.

Returns:

Current run ID or None if not in a run context.