Plug into a port#
A port is a place where HydroModPy takes a class it does not know in advance: a solver
backend, an output extractor, a data source, a trial evaluator, an optimizer, a terrain
engine, a mesh engine, an export format or a figure. Each port is one instance of
PluginRegistry (hydromodpy/core/plugin_registry.py), so they all resolve a name the
same way.
The ports#
The table is read from the registries when the docs are built. Each row gives the registry, the noun it uses in its messages, the names it serves in this build, the entry-point group, the members a plugin declares, the README that holds the contract of the port, and the test files that import the registry.
Built from the PluginRegistry instances of hydromodpy each time the site is built. Fix a wrong row there.
Registry |
Kind |
A plugin declares |
Joins by |
Served |
README |
Tests |
|---|---|---|---|---|---|---|
hydromodpy.calibration.evaluation.registry.evaluators |
trial evaluator |
|
entry-point group |
2 |
hydromodpy/calibration/evaluation/README.md |
9 |
hydromodpy.calibration.optim.optimizer.optimizers |
optimizer |
|
entry-point group |
11 |
hydromodpy/calibration/optim/README.md |
30 |
hydromodpy.catchment.terrain.registry.terrain_engines |
terrain engine |
|
entry-point group |
2 |
hydromodpy/catchment/terrain/README.md |
9 |
hydromodpy.data.source.registry.data_sources |
data source |
|
entry-point group |
89 |
hydromodpy/data/source/README.md |
9 |
hydromodpy.mesh.registry.mesh_engines |
mesh engine |
|
entry-point group |
4 |
hydromodpy/mesh/README.md |
15 |
hydromodpy.results.exporters.registry.export_formats |
export format |
|
entry-point group |
9 |
hydromodpy/results/exporters/README.md |
5 |
hydromodpy.solver.base.registry.extractors |
output extractor |
|
entry-point group |
8 |
hydromodpy/solver/base/README.md |
19 |
hydromodpy.solver.base.registry.solvers |
solver backend |
|
entry-point group |
8 |
hydromodpy/solver/base/README.md |
19 |
How a plugin is registered#
A registry looks a name up in three steps. It serves the classes registered by hand.
Then it imports the dotted path of that name from its table of built-in paths,
a _BUILTIN_PATHS dict of "<module>:<Class>" strings in the registry module.
Last, if the name is still unknown, it scans its entry-point group once and loads every
class declared there. Nothing is imported before a lookup asks for it.
So there are two ways in. A class of this repository is one line in the
_BUILTIN_PATHS table of its registry module. A class of another package publishes an
entry point in the group of the port, in the pyproject.toml of that package. The name
of the entry point is the key of the class in the registry:
[project.entry-points."hydromodpy.mesh.engine"]
my_engine = "my_package.engine:MyEngine"
The registry never splits a key. It joins the id attributes of the loaded class with
_ and compares the result with the entry-point name. A solver of key
flow_mysolver is the process_type flow and the name mysolver, and a
name that holds an underscore, such as modflow_nwt, stays whole. An entry point named like a built-in is ignored with a
warning, two entry points that name different targets for one key are refused by name,
and an entry point that cannot be imported is refused with its target and the reason.
The groups, read from the registry modules, are:
Group |
Registry |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register refuses a class that leaves out a member the port table names, and says
which. A key of a document that names a plugin is read by check_registered_name. It
refuses a name nothing serves, lists the names this installation serves and gives the
group a third party joins through.
Steps for a new class#
Write the class with the members the port table names. The README of the port says what each member receives and returns, and the Protocol of the port module types them.
Register it as above. The README of the port gives the form of the key.
If the port is new, write its README.
python -m tools.docs.check_readmesfinds the ports from the code and checks that each has one.Run the suite of the port. The tests of
tests/ports/run overnames()of their registry, never over a list written intests/, so an installed plugin meets the same cases as a built-in one.
The figure port has no entry-point group. A figure is a request. A new kind of plot is a
frame in hydromodpy/display/frames/, and a new named request is a preset of
hydromodpy/display/presets.py.
The two closed tables#
Two lists are tables of the code and take no plugin. The metric names are the rows of
METRIC_SPECS in hydromodpy/core/scoring/metric_table.py, one MetricSpec per
name, and the boundary ids are the rows of FLOW_BOUNDARY_DEFINITIONS in
hydromodpy/model/boundaries/boundary_condition_registry.py, one
FlowBoundaryDefinition per id. A new metric or a new boundary is a row added in the
code, with its kernel or its binder. The Literal of the names a TOML may write is built
from the rows, so a document that writes another name is refused when it is read. The
README of each folder is the contract of its table.
See also#
Recipes of one port: Add a solver, Add a data source, Add a calibration method, Add an exporter and Add a figure. The mesh port is described in Mesh engines.