Functions and decorators
The callables gpype exports beside its classes.
- gpype.canonicalize(document)[source]
Return document with every node’s id filled in.
Call this once, on the authoring side, and give the result to both halves of a distributed pipeline – or store it, which is the same thing done earlier. The ids are minted the way ioiocore mints them, so a canonicalized document is indistinguishable from one that came out of
serialize().Idempotent: a node that already has an id keeps it, so canonicalizing twice changes nothing and canonicalizing a document that gained a new node touches only the new node. That is the property that makes this safe to run in a save path.
The input is not modified. A caller holding a document it intends to reuse should not find it silently altered.
- Parameters:
document (
dict) – A pipeline document, as loaded from JSON.- Returns:
A copy with an id on every node.
- Return type:
- Raises:
TypeError – If document is not a mapping.
Note
Malformed nodes are left alone rather than repaired. Deciding what a node with no
modulemeans is the loader’s job, and it already refuses such a document with a message naming the field; a second opinion here would only produce a different error for the same mistake.
- gpype.common.document.node_ids(document)[source]
The id of every node in document, in order.
For checking that two halves really are reading the same document – the failure this module exists to prevent is silent, so being able to compare the two lists is worth the six lines.
- gpype.allow_modules(*modules)
Permit additional modules in documents loaded by this process.
For a host program that defines its own node classes and loads its own documents. Call it before deserializing.
This is not a hole in the policy the way a control-plane command would be: the caller is already executing in this interpreter.
- Parameters:
*modules (
str) – Fully qualified module names, such as"my_nodes.filters"; or a package,"my_nodes.*", which permits that package and everything under it.- Raises:
ValueError – If a name is not a non-empty string.
- Return type:
- gpype.deployment_report()[source]
Describe this process as the licence gate would judge it now.
Reading it decides nothing and latches nothing;
Pipeline.start()still makes the decision for a run. The licence is read from the local store, with no network. The residency is read as the gate will read it, and the process-wideLaunchConfigis left as it was found: a report taken before an application configures itself must not fix that configuration from the command line.- Returns:
gpype_version,api_versionfrozen: whether the process is a frozen application, read from the operating system rather than fromsys.process: one line on how that was decided, for a support question.residency:standalone,edgeorserver.licence:product, the product the gate asks about;state, one oflicensed,unlicensedorunknown;detail, the underlying verdict;permission, one offull,limitedorabort, what the licence gate (G1) would grant;reason, why, empty whenfull.
It does not say what a run would be granted. The device gate (G2) is decided at
start()from the pipeline’s own sources, and a run takes the stricter of the two: a fully licensed pipeline whose sources attest nothing, aGeneratorsay, still runs marked.- Return type:
- gpype.node(function)[source]
Turn a function into something a pipeline can be handed.
Sugar over
Apply, and nothing more: the decorated name becomes a factory, so the function stays callable in its own right and can be unit-tested without a pipeline anywhere near it.@gp.node def to_microvolts(block): return block * 1e6 p.connect(reader, to_microvolts()) assert to_microvolts.function(block).max() == ...
Batch only, for the reasons in
Apply.
- gpype.controllable(fn)
Declare
get_controlorset_controlas reachable.
- gpype.action(fn)
Declare a method as a named action.
An action is something the node does, which is why it cannot be a key in the control dict:
{"reset": True}is not idempotent, and a second identical update either does nothing or fires again depending on how the node reads it.