nomnomdata.engine.components¶
Engine¶
-
class
nomnomdata.engine.
Engine
(uuid: str, alias: str, description: str = '', categories: Optional[List[str]] = None, help_header_id: Optional[str] = None, help_md_path: Optional[str] = None, icons: Optional[Dict[str, str]] = None, mock=False)[source]¶ The engine object represents the model that will be presented to the Nominode UI, it also implements parameter validation.
- Example
from nomnomdata.engine import Engine engine = Engine( uuid="ENGINE-1", alias="engine-1", description="Some cool engine that does interesting things", categories=["cool", "powerful", "expensive"], help_md_path="s3://help-md-bucket/coolengine/help.md", icons={ "1x": "s3://icon-bucket/coolengine/coolengine-icon-256.png", "2x": "./some-local-dir/coolengine-icon-512.png", "3x": "../other-dir/coolengine-icon-1024.png" } ) general_settings = ParameterGroup( Parameter(Integer(), name="Maximum"), Parameter(Integer(), name="Minimum"), display_name="General Settings" ) @engine.action(display_name="Do Something") @engine.parameter_group(general_settings) def do_something(parameters): print(parameters) if __name__ == "__main__": engine.main()
-
action
(display_name: str, help_header_id: Optional[str] = None, help_md_path: Optional[str] = None, description='', as_kwargs=False) → Callable[[Any], Tuple[List[Tuple[str, requests.models.PreparedRequest]], Any]][source]¶ Use as a decorator on a function to add an ‘action’ to your engine.
- Parameters
display_name – Descriptive name that will be displayed in the UI
help_header_id – The header ID to scroll to in any parent MD files that are declared, cannot be used if help_md_path is not None.
help_md_path – A file path or URI to the location of an MD file to use as the help, cannot be used if help_header_id is not None.
description – The long form description of what this engine done.
as_kwargs – Will cause parameters to be passed to the wrapped function as kwargs instead of args, defaults to False
- Example
# note this example is not functional # as we do not declared any parameter_groups yet @engine.action( display_name="Do Something", help_header_id="Do Something", description="This action does something very helpful", ) def my_cool_engine_action(parameters): print(parameters)
-
main
()[source]¶ Entry point for the engine, your program should call this for your engine to function. Blocking and will only return once specified command is complete.
-
parameter_group
(parameter_group: nomnomdata.engine.components.ParameterGroup, name=None, display_name=None, description=None, collapsed=None) → Callable[source]¶ Decorate your action with this have it accept groups of parameters
- Parameters
parameter_group – Instantiated
ParameterGroup
classname – Override parameter group name
display_name – Override display name
description – Override discription
collapsed – Override collapsed status
- Example
general_settings = ParameterGroup( Parameter(Integer(), name="Maximum"), Parameter(Integer(), name="Minimum"), display_name="General Settings" ) @engine.action(display_name="Do Something") @engine.parameter_group(general_settings) def do_something(parameters): print(parameters)
-
update_parameter
(key: str, value: any)[source]¶ Update a specific task parameter on the nominode.
- Parameters
key – The given key for the parameter that is being updated.
value – The new value for the parameter, will be validated against the model.
- Raises
ValueError – if given parameter key does not exist in the action model.
TypeError – when trying to update a connection. Connections cannot be updated.
-
update_progress
(message: Optional[str] = None, progress: Optional[int] = None) → Dict[str, str][source]¶ Update nominode with current task progress
- Parameters
message – Message for to attach to current task progress
progress – Number representing the percentage complete of the task (0-100)
- Returns
Response data
Parameter¶
-
class
nomnomdata.engine.
Parameter
(type: nomnomdata.engine.components.ParameterType, name: str, display_name: str = '', help_header_id: Optional[str] = None, help_md_path: Optional[str] = None, required: bool = False, description: str = '', default: Optional[object] = None, many: bool = False, categories: Optional[List[str]] = None)[source]¶ Parameter for use in a ParameterGroup, also contains options to control the look in the Nominode UI
- Parameters
type – Set the type to allow validation of the parameter and so the UI understands how to render this parameter. Example valid parameter type
String
name – Parameter name, will be the key used in the final result passed to your function.
display_name – The name of the parameter to be displayed to the user.
help_header_id – Header ID in any MD file declared in upper scope that will be linked to this parameter.
help_md_path – Full path to an MD file that will be linked to this parameter. Cannot be used with help_header_id.
required – Setting this to true will require the user to set a value for this parameter, defaults to False
description – The long form description the UI will diplay next to the parameter
default – Default value of the parameter will be set as on task creation, valid values vary by the ParameterType you use, defaults to nothing
ParameterGroup¶
-
class
nomnomdata.engine.
ParameterGroup
(*args: nomnomdata.engine.components.Parameter, name: str = 'general', display_name: str = 'General Parameters', description: str = '', collapsed: bool = False, shared_parameter_group_uuid: str = '')[source]¶ ParameterGroup acts as a logical and visual grouping for parameters
- Parameters
name – Unique key for this group, defaults to “general”
display_name – Display name to render in the UI, defaults to “General Parameters”
description – UI description for this parameter group, defaults to “”
collapsed – If the UI should collapse this parameter group when rendering, defaults to False
shared_parameter_group_uuid – UUID of the shared parameter group defined for this parameter, can be safely left undefined in 95% of cases
- Warning
you cannot use parameter groups with the same name on one action