pygada_runtime.node Module
Package containing everything for manipulating nodes.
- class pygada_runtime.node.Param(name, *, value=None, type=None, help=None)[source]
Represent an input or output of a node.
- Parameters
name (
str) – name of parametertype (
Optional[Type]) – it’s typehelp (
Optional[str]) – description of the parameter
- class pygada_runtime.node.Node(name, *, module=None, file=None, lineno=None, runner=None, is_pure=None, inputs=None, outputs=None, extras=None)[source]
Represent a node definition.
- Parameters
name – name of the node
module – parent module
file – absolute path to the source code
lineno – line number in the source code
runner – name of runner
is_pure – if the node is pure
inputs – inputs of the node
outputs – outputs of the node
extra – extra parameters
- extras: dict
Absolute path to Python package containing the node.
- static from_dict(o, /, *, module=None)[source]
Create a new Node from a JSON dict.
>>> from pygada_runtime.node import Node >>> >>> Node.from_dict({ ... "name": "min", ... "inputs": [ ... {"name": "a", "type": "int"}, ... {"name": "b", "type": "int"} ... ], ... "outputs": [ ... {"name": "out", "type": "int"} ... ] ... }) ... Node(name='min', ...) >>>
- Parameters
o (
dict) – JSON dictmodule (
Optional[str]) – parent module
- Return type
- Returns
loaded Node
- class pygada_runtime.node.NodeCall(name, *, id=None, file=None, lineno=None, inputs=None)[source]
Represent the call to a node in a program.
- Parameters
name – name of the node
id – unique id of the call
file – absolute path to the source code
lineno – line number in the source code
inputs – inputs for the call
- static from_dict(o, /)[source]
Create a new NodeCall from a JSON dict.
>>> from pygada_runtime.node import NodeCall >>> >>> NodeCall.from_dict({ ... "name": "min", ... "inputs": { ... "a": 1, ... "b": 2 ... } ... }) ... NodeCall(name='min', ...) >>>
- Parameters
o (
dict) – JSON dict- Return type
- Returns
new NodeCall
- class pygada_runtime.node.NodeLoader(mod, name, node=None)[source]
Class for loading a node defined in a module.
- name: str
Absolute path to Python package containing the node.
- pygada_runtime.node.load()[source]
Load a node by its path.
- Parameters
path (
str) – node path- Return type
- pygada_runtime.node.from_module()[source]
Yield top-level nodes of a module.
Imagine you have the following package:
sample/ ├─ __init__.py ├─ gada.yml ├─ foo/ │ ├─ __init__.py │ ├─ gada.yml │ ├─ bar/ │ │ ├─ __init__.py │ │ ├─ gada.yml ├─ baz/ │ ├─ __init__.py │ ├─ gada.yml
This is what you would get in the different scenarios:
from_module(“sample”): nodes from sample module.
from_module(“sample.foo”): nodes from foo module.
from_module(“sample.foo.bar”): nodes from bar module.
from_module(“sample.baz”): nodes from baz module.
- Parameters
mod (
Union[ModuleInfo,module,str]) – a module-like object- Return type
Iterable[NodeLoader]
- pygada_runtime.node.iter_nodes()[source]
Yield nodes from top-level modules of a parent module or PYTHONPATH.
This function only returns nodes from top-level modules. See
walk_nodes()for a fully recursive version.Imagine you have the following package:
sample/ ├─ __init__.py ├─ gada.yml ├─ foo/ │ ├─ __init__.py │ ├─ gada.yml │ ├─ bar/ │ │ ├─ __init__.py │ │ ├─ gada.yml ├─ baz/ │ ├─ __init__.py │ ├─ gada.yml
This is what you would get in the different scenarios:
iter_nodes(): nodes from sample module.
iter_nodes(“sample”): nodes from foo and baz modules.
iter_nodes(“sample.foo”): nodes from bar module.
iter_nodes(“sample.foo.bar”): an empty list.
iter_nodes(“sample.baz”): an empty list.
- Parameters
mod (
Union[ModuleInfo,module,str,None]) – a module-like object- Return type
Iterable[NodeLoader]
- pygada_runtime.node.walk_nodes()[source]
Yield nodes from all submodules of a parent module or PYTHONPATH.
This function not only returns nodes from top-level modules, but also from submodules. See
iter_nodes()for a non recursive version.Imagine you have the following package:
sample/ ├─ __init__.py ├─ gada.yml ├─ foo/ │ ├─ __init__.py │ ├─ gada.yml │ ├─ bar/ │ │ ├─ __init__.py │ │ ├─ gada.yml ├─ baz/ │ ├─ __init__.py │ ├─ gada.yml
This is what you would get in the different scenarios:
walk_nodes(): nodes from sample, foo, bar and baz modules.
walk_nodes(“sample”): nodes from foo, bar and baz modules.
walk_nodes(“sample.foo”): nodes from bar module.
walk_nodes(“sample.foo.bar”): an empty list.
walk_nodes(“sample.baz”): an empty list.
- Parameters
mod (
Union[ModuleInfo,module,str,None]) – a module-like object- Return type
Iterable[NodeLoader]