micm_nlp.bootstrap

Process-level setup: .env loading, typed settings, and init().

Importing this module reads .env into os.environ, so libraries that consult environment variables directly (huggingface_hub, transformers, wandb) see the same values that Env exposes as typed settings.

init() is the one call an application makes at startup. It sets the workspace root, strips the distributed-training variables that would otherwise push accelerate into MULTI_GPU mode for a single-process run, and optionally installs Rich pretty-printing and tracebacks.

Formerly split across env.py and setup.py; merged here in 0.2.0.

Attributes

env

Classes

Env

Typed view of the environment, read from .env and the process env.

MicmNlpConfig

What init() accepts.

RichConfig

Settings for Rich's pretty-printer and traceback handler.

Functions

init(→ None)

Set up the process: workspace root, distributed env, optional Rich output.

init_rich(→ None)

Install Rich's pretty-printer and traceback handler.

Module Contents

class micm_nlp.bootstrap.Env

Bases: pydantic_settings.BaseSettings

Typed view of the environment, read from .env and the process env.

extra='allow' and case_sensitive=True: unknown variables are kept rather than rejected, so a project can put its own settings in the same .env. The module-level env instance is built at import time; nothing re-reads the file afterwards.

APP_ENV: str = 'local'
HF_TOKEN: str | None = None
PROJECT_ROOT_PATH: pathlib.Path | None = None
SHOW_LOCALS: int = 0
WANDB_API_KEY: str | None = None
model_config
class micm_nlp.bootstrap.MicmNlpConfig

Bases: pydantic.BaseModel

What init() accepts.

root_path defaults to PROJECT_ROOT_PATH from the environment, so init() with no arguments works when .env sets it. pretty_output takes True for Rich defaults, or a RichConfig to tune it.

pretty_output: RichConfig | bool = False
root_path: str | None
class micm_nlp.bootstrap.RichConfig

Bases: pydantic.BaseModel

Settings for Rich’s pretty-printer and traceback handler.

show_locals renders local variables in tracebacks — useful when debugging, noisy in a training log.

extra_lines: int = 1
show_locals: bool = False
width: int = 120
micm_nlp.bootstrap.init(config: MicmNlpConfig | dict) None

Set up the process: workspace root, distributed env, optional Rich output.

Call once before any pipeline call. Not triggered on import — until it runs, every accessor in micm_nlp.path raises, so artefacts/ can never land in the wrong place by accident.

Three things happen, in order: the workspace root is set from root_path (falling back to PROJECT_ROOT_PATH); the distributed-training variables are stripped when this is a single-process run, see _disable_distributed_if_single_process; and Rich is installed if pretty_output asks for it.

Parameters:

config – a MicmNlpConfig or a plain dict of its fields.

micm_nlp.bootstrap.init_rich(rich_config: RichConfig | dict | bool) None

Install Rich’s pretty-printer and traceback handler.

Usually reached through init() rather than called directly. Rich is imported inside the function, so a project that never asks for pretty output does not pay the import.

Parameters:

rich_configTrue for defaults, or a RichConfig / dict.

micm_nlp.bootstrap.env