CLI Architecture¶
CLI Architecture¶
rgpycrumbs uses a dispatcher pattern where each CLI command is a standalone
script with PEP 723 inline metadata. The entry point rgpycrumbs dispatches
to these scripts at runtime, avoiding a monolithic CLI with heavy imports.
Dispatcher Pattern¶
The main rgpycrumbs command maps each subpackage to a command group and each script in it to a command.
When invoked, it runs the script with uv run, so uv resolves the dependencies in its PEP 723 header.
It uses the active interpreter instead under --dev or RGPYCRUMBS_DEV, or when uv is not on the path.
It does the same when that interpreter already has readcon, matplotlib, polars, ASE and chemparseplot.
RGPKGS_FORCE_UV, RGPYCRUMBS_FORCE_UV or force_uv in the suite configuration forces uv run.
Only --dev and RGPYCRUMBS_DEV override that.
A public module is a script only when it carries the inline script metadata block of Python Enhancement Proposal (PEP) 723.
Modules without that block stay library code, and so do modules whose names start with _.
The command name is the module name with - for _, minus any cli_ prefix.
# Simplified dispatcher logic (see rgpycrumbs/cli.py)
def dispatch(cmd: str, args: list[str]):
script = SCRIPT_MAP[cmd] # e.g. rgpycrumbs/eon/plt_neb.py
subprocess.run(["uv", "run", "--script", str(script), *args])
Key Benefits¶
Each script declares only its own dependencies (click, matplotlib, etc.)
No global import of JAX/scipy/ASE at startup
Scripts are runnable standalone:
uv run rgpycrumbs/eon/plt_neb.py --helpA module with a PEP 723
scriptblock in a subpackage is a new command