geoprior.cli._dispatch#
Low-level dispatch helpers for GeoPrior command-line entry points.
This module provides the internal building blocks used by the GeoPrior CLI frontends to resolve commands, import their implementation modules, and execute the appropriate entry callable with a uniform interface.
It is intentionally small and generic. The higher-level command registry, family routing, and user-facing help pages live elsewhere, while this module focuses on the reusable mechanics required by all CLI entry points.
Overview#
The dispatcher infrastructure revolves around a small command
description object, CommandSpec, and a set of helper
functions that perform four main tasks:
Import a command module from a registry entry.
Load the entry callable exposed by that module.
Execute the callable or module with the correct delegated
argvand program name.Build compact command/alias listings for help output.
Design goals#
This module is designed to keep CLI execution:
registry-driven so commands can be described declaratively rather than hard-coded,
lightweight so frontends such as
geoprior,geoprior-run,geoprior-build, andgeoprior-plotcan share the same dispatch machinery,backward-compatible so legacy command names and aliases can still resolve cleanly,
implementation-agnostic so a command may expose either a callable entrypoint or a module-style
__main__execution path.
Execution model#
A command is described by CommandSpec, which records the
target package, module, callable name, public command name, family,
and accepted aliases.
Given such a specification, the helpers in this module support two execution styles:
call_entryLoad a Python callable and invoke it using the most compatible calling convention discovered from its signature.
run_moduleExecute a module as
__main__after temporarily patchingsys.argv, which is useful for module-oriented CLI code.
The module also provides small helpers such as alias_map(),
public_items(), and print_help_table() to support
consistent help rendering across command families.
Notes
This module is primarily internal and is not intended to contain domain-specific workflow logic. It should remain focused on generic dispatch behavior only.
See also
geoprior.cli.__main__Family-aware public CLI frontends built on top of this module.
geoprior.scripts.registryRegistry definitions consumed by the dispatch layer.
Functions
|
Build alias -> public-name mapping. |
|
Call a command entrypoint. |
|
Load the entry callable from a command module. |
|
Import a module for a command spec. |
|
Print a compact help table. |
|
Return public registry items filtered by family. |
|
Execute a module as __main__ with delegated argv. |
Classes
|
Immutable command description used by the CLI dispatch layer. |
- class geoprior.cli._dispatch.CommandSpec(package, mod, fn, desc, mode='argv', family=None, public_name=None, aliases=(), legacy_names=())[source]#
Bases:
objectImmutable command description used by the CLI dispatch layer.
A
CommandSpecstores the minimal metadata needed to resolve and execute a command from the registry-driven GeoPrior CLI system.Each instance identifies
the Python package containing the command,
the module to import,
the callable name to execute,
a short human-readable description,
the execution mode,
the command family and public-facing names.
- Variables:
package (
str) – Package path used for relative imports. If empty,modis imported as an absolute module path.mod (
str) – Module name containing the command implementation.fn (
str) – Name of the callable entrypoint expected insidemodwhen the execution mode is callable-based.desc (
str) – Short help text shown in command listings.mode (
str, default"argv") –Execution strategy used by the dispatcher.
Supported values are typically:
family (
strorNone, defaultNone) – Optional command family such as"run","build", or"plot".public_name (
strorNone, defaultNone) – Canonical public command name exposed to users.aliases (
tupleofstr, default()) – Alternative spellings that resolve topublic_name.legacy_names (
tupleofstr, default()) – Backward-compatible historical command names.
- Parameters:
- geoprior.cli._dispatch.load_module(spec)[source]#
Import a module for a command spec.
- Parameters:
spec (CommandSpec)
- geoprior.cli._dispatch.load_callable(spec)[source]#
Load the entry callable from a command module.
- Parameters:
spec (CommandSpec)
- Return type:
Callable[[…], None]
- geoprior.cli._dispatch.run_module(spec, *, display_cmd, argv)[source]#
Execute a module as __main__ with delegated argv.
- Parameters:
spec (CommandSpec)
display_cmd (str)
- Return type:
None
- geoprior.cli._dispatch.call_entry(fn, *, argv, display_cmd)[source]#
Call a command entrypoint.
Preference order: 1) fn(argv, prog=…) 2) fn(argv) 3) fn() with patched sys.argv
- geoprior.cli._dispatch.public_items(registry, *, family=None)[source]#
Return public registry items filtered by family.
- Parameters:
registry (dict[str, CommandSpec])
family (str | None)
- Return type:
list[tuple[str, CommandSpec]]