hpcflow.app.ActionRule#

class hpcflow.app.ActionRule(rule=None, check_exists=None, check_missing=None, path=None, condition=None, cast=None, doc=None)#

Bases: ActionRule

Class to represent a rule/condition that must be True if an action is to be included.

Parameters:
  • rule (Rule) – The rule to apply.

  • check_exists (str) – A special rule that is enabled if this named attribute is present.

  • check_missing (str) – A special rule that is enabled if this named attribute is absent.

  • path (str) – Where to find the attribute to check.

  • condition (dict | ConditionLike) – A more complex condition to apply.

  • cast (str) – The name of a class to cast the attribute to before checking.

  • doc (str) – Documentation for this rule, if any.

Methods

check_exists

Make an action rule that checks if a named attribute is present.

check_missing

Make an action rule that checks if a named attribute is absent.

from_json_like

Make an instance of this class from JSON (or YAML) data.

test

Test if this rule holds for a particular iteration.

to_dict

Serialize this object as a dictionary.

to_json_like

Serialize this object as an object structure that can be trivially converted to JSON.

Attributes

rule

The rule to apply.

action

The action that contains this rule.

command

The command that is guarded by this rule.

action: Action | None#

The action that contains this rule.

classmethod check_exists(check_exists)#

Make an action rule that checks if a named attribute is present.

Parameter#

check_exists:

The path to the attribute to check for.

Parameters:

check_exists (str) –

Return type:

ActionRule

classmethod check_missing(check_missing)#

Make an action rule that checks if a named attribute is absent.

Parameter#

check_missing:

The path to the attribute to check for.

Parameters:

check_missing (str) –

Return type:

ActionRule

command: Command | None#

The command that is guarded by this rule.

classmethod from_json_like(json_like, shared_data=None)#

Make an instance of this class from JSON (or YAML) data.

Parameters:
  • json_like (str | Mapping[str, JSONed] | Sequence[Mapping[str, JSONed]] | None) – The data to deserialise.

  • shared_data (Mapping[str, ObjectList[JSONable]] | None) – Shared context data.

Return type:

The deserialised object.

rule#

The rule to apply.

test(element_iteration)#

Test if this rule holds for a particular iteration.

Parameter#

element_iteration:

The iteration to apply this rule to.

Parameters:

element_iteration (ElementIteration) –

Return type:

bool

to_dict()#

Serialize this object as a dictionary.

Return type:

dict[str, Any]

to_json_like(dct=None, shared_data=None, exclude=(), path=None)#

Serialize this object as an object structure that can be trivially converted to JSON. Note that YAML can also be produced from the result of this method; it just requires a different final serialization step.

Parameters:
  • dct (dict[str, JSONable] | None) –

  • shared_data (_JSONDeserState) –

  • exclude (Container[str | None]) –

  • path (list | None) –

Return type:

tuple[JSONDocument, _JSONDeserState]