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 hmp command.

728

environment.py

The CLI arguments that build an hydromodpy.project.environment.Environment.

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 [sites] launch: what is prepared, running, done and left.

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

hmp calibrate - run a calibration from a TOML file.

493

check.py

hmp check - check a run, a calibration or a whole [sites] project.

183

completion.py

hmp completion - print the shell completion script for hmp and hydromodpy.

51

config.py

hmp config - configuration TOML template + schema + validator.

578

diff.py

hmp diff - compare runs.

209

doctor.py

hmp doctor - diagnose the local environment.

158

export.py

hmp export - write data of a run to files, the words of an [[export]] block.

321

install_binaries.py

hmp install-binaries - pre-warm the solver binary cache.

145

ls.py

hmp ls - list the runs of a project, or where its plan stands.

288

privacy.py

hmp privacy - remove a run for good with a purge certificate, and verify one.

148

publish.py

hmp publish - copy a run, the summary or a whole project out of the tree.

323

replay.py

hmp replay REF - play a sealed run or a published copy again, and class its values.

132

run.py

hmp run - execute the workflow of a TOML file or of a JSON run request.

1 109

show.py

hmp show - read one thing of a run, a session or a project.

803

spinup.py

hmp spinup - run a cyclic spin-up from a TOML file.

176

stop.py

hmp stop REF - ask a running run or calibration session to stop.

53

commands/campaign/

Module

What it does

Lines

array.py

hmp campaign array - write the array job of the current plan for a scheduler.

127

case.py

hmp campaign case: the case file one task of a scheduler job runs.

38

collect.py

hmp campaign collect - write summary/ of a project from its runs.

101

promote.py

hmp campaign promote - turn one trial of a calibration session into a run.

107

prune.py

hmp campaign prune - trash the kept trials of a session, all but the best.

98

commands/catalog/

Module

What it does

Lines

delete.py

hmp catalog delete - move a run or a session to the project trash.

110

gc.py

hmp catalog gc - collect what a project no longer needs, and say what it weighs.

223

import_archive.py

hmp catalog import - bring a run published by hmp publish into the project.

116

note.py

hmp catalog note - append a timestamped note to a run, in its annotations.json.

55

query.py

hmp catalog query - run a SQL statement against the index of a project.

56

reindex.py

hmp catalog reindex - build the project index from the run directories.

74

rename.py

hmp catalog rename - move a run, and its session, to a new name.

71

rerun.py

hmp catalog rerun - launch a run again from its frozen configuration.

137

restore.py

hmp catalog restore - move a trashed run or session back where it was.

64

tag.py

hmp catalog tag - add or remove tags on a run, in its annotations.json.

90

trash.py

hmp catalog trash - move a run to the project trash, list the trash, or empty it.

146

watch.py

hmp catalog watch - the running attempts of a project and the age of their pulse.

78

commands/data/

Module

What it does

Lines

archive.py

hmp data archive - thin wrapper around hydromodpy.data.request.cache_verbs.archive_data_cache.

42

get.py

hmp data get - serve a data request into a folder.

144

lock.py

hmp data lock - write hydromodpy.lock, or check the files against it.

134

ls.py

hmp data ls - thin wrapper around hydromodpy.data.request.cache_verbs.list_data_cache.

68

prune.py

hmp data prune - drop the old rows of the cache, never a file a run or a lockfile cites.

88

remove.py

hmp data remove - thin wrapper around hydromodpy.data.request.cache_verbs.remove_data_entries.

72

restore.py

hmp data restore - thin wrapper around hydromodpy.data.request.cache_verbs.restore_data_cache.

48

commands/example/

Module

What it does

Lines

add.py

hmp example add - fetch one, several or every example into a workspace.

120

list_cmd.py

hmp example list - the shipped catalog, read offline from the wheel.

48

show.py

hmp example show - one example, file by file, cached or missing.

58

commands/process/

Module

What it does

Lines

describe.py

hmp process describe <id> - print the description of one process.

35

ls.py

hmp process ls - list the processes this build describes.

39

run.py

hmp process run <id> <job> - run one process in a job folder.

53

commands/project/

Module

What it does

Lines

delete.py

hmp project delete - remove a project directory and everything it holds.

94

import_package.py

hmp project import: install a package written by hmp publish --package.

94

list_cmd.py

hmp project list - the projects under projects/ of a workspace.

47

log.py

hmp project log: the journal of the latest launch, or its failed cases.

101

new.py

hmp project new - scaffold a project under projects/ of a workspace.

46

plan.py

hmp project plan: expand a [sites] project and write plan/<hash>/.

108

commands/site/

Module

What it does

Lines

add.py

hmp site add: declare one site in the catalog of the workspace.

78

import_sites.py

hmp site import: declare sites from a table, a layer or Hub’Eau.

172

ls.py

hmp site ls: list the sites declared in the workspace.

43

show.py

hmp site show: print one site declared in the workspace.

44

commands/workspace/

Module

What it does

Lines

clean.py

hmp workspace clean - remove what a workspace can rebuild, and trash its results.

178

init_cmd.py

hmp workspace init - thin wrapper around hydromodpy.init_workspace.

84

list_cmd.py

hmp workspace list - the sealed runs of every project under a workspace.

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/ with NAME, HELP, register and run, named in ALL_COMMANDS of commands/__init__.py. An action of a family is a module of the family sub-package with the same four symbols, listed in the ACTIONS tuple of its __init__.py.

  • A shared option is a parser of conventions.py, passed through parents=.

  • A new verb declares what it writes in OUTPUTS of output.py, and a form that moved gets its line in OLD_CLI_FORMS.

  • An exit code is a Category on the exception class, and a new category is a value of Category and a line of EXIT_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.