hpcflow.sdk.core.command_files.InputFileGenerator#

class hpcflow.sdk.core.command_files.InputFileGenerator(input_file, inputs, script=None, environment=None, script_pass_env_spec=False, abortable=False, rules=<factory>)#

Bases: JSONLike

Represents a script that is run to generate input files for an action.

Parameters:
  • input_file (FileSpec) – The file to generate.

  • inputs (list[Parameter]) – The input parameters to the generator.

  • script (str | None) – The script that generates the input.

  • environment (Environment | None) – The environment in which to run the generator.

  • script_pass_env_spec (bool) – Whether to pass in the environment.

  • abortable (bool) – Whether the generator can be stopped early. Quick-running scripts tend to not need this.

  • rules (list[ActionRule]) – User-specified rules for whether to run the generator.

Methods

compose_source

Generate the file contents of this input file generator source.

from_json_like

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

get_action_rules

Get the rules that allow testing if this input file generator must be run or not for a given element.

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.

write_source

Write the script if it is specified as a snippet script, otherwise we assume the script already exists in the working directory.

Attributes

abortable

Whether the generator can be stopped early.

environment

The environment in which to run the generator.

script

The script that generates the inputs.

script_pass_env_spec

Whether to pass in the environment.

input_file

The file to generate.

inputs

The input parameters to the generator.

rules

User-specified rules for whether to run the generator.

abortable: bool = False#

Whether the generator can be stopped early. Quick-running scripts tend to not need this.

compose_source(snip_path)#

Generate the file contents of this input file generator source.

Parameters:

snip_path (Path) –

Return type:

str

environment: Environment | None = None#

The environment in which to run the generator.

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.

get_action_rules()#

Get the rules that allow testing if this input file generator must be run or not for a given element.

Return type:

list[ActionRule]

input_file: FileSpec#

The file to generate.

inputs: list[Parameter]#

The input parameters to the generator.

rules: list[ActionRule]#

User-specified rules for whether to run the generator.

script: str | None = None#

The script that generates the inputs.

script_pass_env_spec: bool = False#

Whether to pass in the environment.

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]

write_source(action, env_spec)#

Write the script if it is specified as a snippet script, otherwise we assume the script already exists in the working directory.

Parameters:
  • action (Action) –

  • env_spec (Mapping[str, Any]) –

Return type:

None