Package: cli#
The command line, with the hmp and hydromodpy entry points. It parses arguments, calls the code that does the work, formats the output and turns an exception into a typed exit code. It holds no scientific logic, so a result that the command line gives is the one that hydromodpy.project.api gives. Fourteen of the fifteen verbs have a command, and open has none. Under their names status is ls --disk, compare is diff and trash is catalog trash. The families workspace, project, campaign, data, site, process, config and privacy, and catalog apart from trash, call the lower packages directly because no verb covers them.
The top-level commands follow the order of ALL_COMMANDS. A command is one module of commands/, or one sub-package for a family of actions such as catalog or data. A command module and each action module of a family expose NAME, HELP, register and run. The __init__.py of a family exposes NAME, HELP, ACTIONS and register. conventions.py holds the shared argparse grammar, output.py the one way a command writes JSON or CSV for a program, and exit_codes.py the map from an exception category to an exit code, which is 1, 2 or 10 to 23, with 130 for an interruption.
cli sits above the layer matrix. It reads every package below it, and only the entry points of pyproject.toml, hydromodpy/__main__.py and the tools under tools/ read it. hmp <verb> --help prints the options of each verb, and the CLI reference of the docs is generated from the same parsers.
The page of the package in the developer docs lists the modules, gives which command calls which verb, tells how a run starts and says where to add a command.
Modules#
top level
Module |
What it does |
Lines |
|---|---|---|
auth.py |
Who is acting, for the commands that sign what they write. |
46 |
banner.py |
HydroModPy ASCII banner. |
58 |
conventions.py |
Reusable argparse conventions shared by every |
728 |
environment.py |
The CLI arguments that build an |
109 |
exit_codes.py |
Exit codes of the hmp CLI and the functions that end a command with one. |
244 |
launch_board.py |
The board of a |
306 |
main.py |
Top-level CLI dispatcher for HydroModPy. |
147 |
output.py |
The one way a command writes its result for a program. |
796 |
profiling.py |
The –profile flag: where the report goes and the pyinstrument wrapper. |
107 |
refs.py |
Resolution of the workspace, the project and the TOML file a command is given. |
144 |
commands/
Module |
What it does |
Lines |
|---|---|---|
calibrate.py |
|
493 |
check.py |
|
183 |
completion.py |
|
51 |
config.py |
|
578 |
diff.py |
|
209 |
doctor.py |
|
158 |
export.py |
|
321 |
install_binaries.py |
|
145 |
ls.py |
|
288 |
privacy.py |
|
148 |
publish.py |
|
323 |
replay.py |
|
132 |
run.py |
|
1 109 |
show.py |
|
803 |
spinup.py |
|
176 |
stop.py |
|
53 |
commands/campaign/
Module |
What it does |
Lines |
|---|---|---|
array.py |
|
127 |
case.py |
|
38 |
collect.py |
|
101 |
promote.py |
|
107 |
prune.py |
|
98 |
commands/catalog/
Module |
What it does |
Lines |
|---|---|---|
delete.py |
|
110 |
gc.py |
|
223 |
import_archive.py |
|
116 |
note.py |
|
55 |
query.py |
|
56 |
reindex.py |
|
74 |
rename.py |
|
71 |
rerun.py |
|
137 |
restore.py |
|
64 |
tag.py |
|
90 |
trash.py |
|
146 |
watch.py |
|
78 |
commands/data/
Module |
What it does |
Lines |
|---|---|---|
archive.py |
|
42 |
get.py |
|
144 |
lock.py |
|
134 |
ls.py |
|
68 |
prune.py |
|
88 |
remove.py |
|
72 |
restore.py |
|
48 |
commands/example/
Module |
What it does |
Lines |
|---|---|---|
add.py |
|
120 |
list_cmd.py |
|
48 |
show.py |
|
58 |
commands/process/
Module |
What it does |
Lines |
|---|---|---|
describe.py |
|
35 |
ls.py |
|
39 |
run.py |
|
53 |
commands/project/
Module |
What it does |
Lines |
|---|---|---|
delete.py |
|
94 |
import_package.py |
|
94 |
list_cmd.py |
|
47 |
log.py |
|
101 |
new.py |
|
46 |
plan.py |
|
108 |
commands/site/
Module |
What it does |
Lines |
|---|---|---|
add.py |
|
78 |
import_sites.py |
|
172 |
ls.py |
|
43 |
show.py |
|
44 |
commands/workspace/
Module |
What it does |
Lines |
|---|---|---|
clean.py |
|
178 |
init_cmd.py |
|
84 |
list_cmd.py |
|
58 |
Inside the package#
A command calls a verb. commands/*.py parse arguments, call one verb of
hydromodpy.project.api or the package that the verb serves, format the output and map errors
to exit codes. Reusable behaviour belongs in hydromodpy.project.api or in its domain
package. Work that a Python user needs too is a verb first, which the command then calls.
hmp run calls the verb run for a simulation and an overview, and dispatch_workflow
of project/dispatch/workflow.py for a calibration. This package never calls
fill_trial_pipeline. Each library entry that reads the pipeline fills it.
How a run starts#
hmp run config.toml or hmp run request.json --base /project goes to commands/run.py,
which builds the RunRequest with request_of of project/request.py. A .json file
is the request itself, and --overlay is refused with it. --set, --overlay and
--case join the request. The command then calls project.api.run, and the workflow is the
declared [workflow].mode, or for a file written before 2.0.1 the one its sections imply. An exception that leaves the
handler goes to fail in exit_codes.py, which prints its message on stderr and exits with
the code of its class.
--format table|json|csv is on every verb except the ones that print a document. Under
json, stdout holds one object and nothing else, because main.py points stdout at stderr
while the verb works and output.emit writes the result once it is over.
The grammar of a verb has a few fixed words. A destination is --to, a preview is
--dry-run, a verb that removes something takes -y, and a name is --name.
--force has one meaning, to go past a refusal because of what is already there or what
protects it, and it never skips a question.
Where to add what#
A leaf verb is a module of
commands/withNAME,HELP,registerandrun, named inALL_COMMANDSofcommands/__init__.py. An action of a family is a module of the family sub-package with the same four symbols, listed in theACTIONStuple of its__init__.py.A shared option is a parser of
conventions.py, passed throughparents=.A new verb declares what it writes in
OUTPUTSofoutput.py, and a form that moved gets its line inOLD_CLI_FORMS.An exit code is a
Categoryon the exception class, and a new category is a value ofCategoryand a line ofEXIT_CODE_OF.
tests/unit/cli/test_main.py walks ALL_COMMANDS, checks the help of each verb and holds
the list of verbs the command line must expose, so a verb added or removed is a line there.
tests/unit/cli/test_machine_output.py walks the tree for the grammar and the envelope. Start
reading at main.py, then commands/run.py, then project/api.py.