idmtools_models.templated_script_task module

class idmtools_models.templated_script_task.TemplatedScriptTask(command: Union[str, idmtools.entities.command_line.CommandLine] = None, platform_requirements: Set[idmtools.entities.platform_requirements.PlatformRequirements] = <factory>, _ITask__pre_creation_hooks: List[Callable[[Union[Simulation, IWorkflowItem]], NoReturn]] = <factory>, _ITask__post_creation_hooks: List[Callable[[Union[Simulation, IWorkflowItem]], NoReturn]] = <factory>, common_assets: idmtools.assets.asset_collection.AssetCollection = <factory>, transient_assets: idmtools.assets.asset_collection.AssetCollection = <factory>, _task_log: logging.Logger = <factory>, script_path: str = None, template: str = None, template_file: str = None, template_is_common: bool = True, variables: Dict[str, Any] = <factory>, path_sep: str = '/', extra_command_arguments: str = '', gather_common_asset_hooks: List[Callable[[idmtools.entities.itask.ITask], idmtools.assets.asset_collection.AssetCollection]] = <factory>, gather_transient_asset_hooks: List[Callable[[idmtools.entities.itask.ITask], idmtools.assets.asset_collection.AssetCollection]] = <factory>)

Bases: idmtools.entities.itask.ITask

Defines a task to run a script using a template. Best suited to shell scripts

script_path: str = None

Name of script

template: str = None

The template contents

template_file: str = None

The template file. You can only use either template or template_file at once

template_is_common: bool = True

Controls whether a template should be an experiment or a simulation level asset

variables: Dict[str, Any]
path_sep: str = '/'

Platform Path Separator. For Windows execution platforms, use , otherwise use the default of /

extra_command_arguments: str = ''

Extra arguments to add to the command line

gather_common_asset_hooks: List[Callable[[ITask], AssetCollection]]

Hooks to gather common assets

gather_transient_asset_hooks: List[Callable[[ITask], AssetCollection]]

Hooks to gather transient assets

gather_common_assets()idmtools.assets.asset_collection.AssetCollection

Gather common(experiment-level) assets for task

Returns

AssetCollection containing common assets

gather_transient_assets()idmtools.assets.asset_collection.AssetCollection

Gather transient(experiment-level) assets for task

Returns

AssetCollection containing transient assets

reload_from_simulation(simulation: idmtools.entities.simulation.Simulation)

Reload a templated script task. When reloading, you will only have the rendered template available

Parameters

simulation

Returns:

pre_creation(parent: Union[idmtools.entities.simulation.Simulation, idmtools.entities.iworkflow_item.IWorkflowItem])

Before creating simulation, we need to set our command line

Parameters

parent – Parent object

Returns:

class idmtools_models.templated_script_task.ScriptWrapperTask(command: Union[str, idmtools.entities.command_line.CommandLine] = None, platform_requirements: Set[idmtools.entities.platform_requirements.PlatformRequirements] = <factory>, _ITask__pre_creation_hooks: List[Callable[[Union[Simulation, IWorkflowItem]], NoReturn]] = <factory>, _ITask__post_creation_hooks: List[Callable[[Union[Simulation, IWorkflowItem]], NoReturn]] = <factory>, common_assets: idmtools.assets.asset_collection.AssetCollection = <factory>, transient_assets: idmtools.assets.asset_collection.AssetCollection = <factory>, _task_log: logging.Logger = <factory>, template_script_task: idmtools_models.templated_script_task.TemplatedScriptTask = None, task: idmtools.entities.itask.ITask = None)

Bases: idmtools.entities.itask.ITask

Allows you to wrap a script with another script

Raises

ValueError if the template Script Task is not defined

template_script_task: idmtools_models.templated_script_task.TemplatedScriptTask = None
task: idmtools.entities.itask.ITask = None
gather_common_assets()

Gather all the common assets Returns:

gather_transient_assets()idmtools.assets.asset_collection.AssetCollection

Gather all the transient assets Returns:

reload_from_simulation(simulation: idmtools.entities.simulation.Simulation)

Reload from simulation

Parameters

simulation – simulation

Returns:

pre_creation(parent: Union[idmtools.entities.simulation.Simulation, idmtools.entities.iworkflow_item.IWorkflowItem])

Before creation, create the true command by adding the wrapper name

Parameters

parent

Returns:

post_creation(parent: Union[idmtools.entities.simulation.Simulation, idmtools.entities.iworkflow_item.IWorkflowItem])

Optional Hook called at the after creation task. Can be used to setup simulation and experiment level hooks :param parent:

Returns:

idmtools_models.templated_script_task.get_script_wrapper_task(task: idmtools.entities.itask.ITask, wrapper_script_name: str, template_content: str = None, template_file: str = None, template_is_common: bool = True, variables: Dict[str, Any] = None, path_sep: str = '/')idmtools_models.templated_script_task.ScriptWrapperTask

Convenience function that will wrap a task for you with some defaults

Parameters
  • task – Task to wrap

  • wrapper_script_name – Wrapper script name

  • template_content – Template Content

  • template_file – Template File

  • template_is_common – Is the template experiment level

  • variables – Variables

  • path_sep – Path sep(Window or Linux)

Returns

ScriptWrapperTask wrapping the task

idmtools_models.templated_script_task.get_script_wrapper_windows_task(task: idmtools.entities.itask.ITask, wrapper_script_name: str = 'wrapper.bat', template_content: str = '\nset PYTHONPATH=%cd%\\Assets\\;%PYTHONPATH%\n%*\n', template_file: str = None, template_is_common: bool = True, variables: Dict[str, Any] = None)idmtools_models.templated_script_task.ScriptWrapperTask

Get wrapper script task for windows platforms

The default content wraps a bash script that adds the assets directory to the python path

set PYTHONPATH=%cd%/Assets/;%PYTHONPATH%
%*

You can adapt this script to modify any pre-scripts you need or call others scripts in succession

Parameters
  • task – Task to wrap

  • wrapper_script_name – Wrapper script name(defaults to wrapper.bat)

  • template_content – Template Content.

  • template_file – Template File

  • template_is_common – Is the template experiment level

  • variables – Variables for template

Returns

ScriptWrapperTask

See Also::

idmtools_models.templated_script_task.get_script_wrapper_task() idmtools_models.templated_script_task.get_script_wrapper_unix_task()

idmtools_models.templated_script_task.get_script_wrapper_unix_task(task: idmtools.entities.itask.ITask, wrapper_script_name: str = 'wrapper.sh', template_content: str = None, template_file: str = None, template_is_common: bool = True, variables: Dict[str, Any] = None)

Get wrapper script task for unix platforms

The default content wraps a bash script that adds the assets directory to the python path

set PYTHONPATH=$(pwd)/Assets/:$PYTHONPATH
%*

You can adapt this script to modify any pre-scripts you need or call others scripts in succession

Parameters
  • task – Task to wrap

  • wrapper_script_name – Wrapper script name(defaults to wrapper.sh)

  • template_content – Template Content

  • template_file – Template File

  • template_is_common – Is the template experiment level

  • variables – Variables for template

Returns

ScriptWrapperTask

See Also: idmtools_models.templated_script_task.get_script_wrapper_task() idmtools_models.templated_script_task.get_script_wrapper_windows_task()

class idmtools_models.templated_script_task.TemplatedScriptTaskSpecification

Bases: idmtools.registry.task_specification.TaskSpecification

get(configuration: dict)idmtools_models.templated_script_task.TemplatedScriptTask

Get instance of TemplatedScriptTask with configuration

Parameters

configuration – configuration for TemplatedScriptTask

Returns

TemplatedScriptTask with configuration

get_description() → str

Get description of plugin

Returns

Plugin description

get_example_urls() → List[str]

Get example urls related to TemplatedScriptTask

Returns

List of urls that have examples related to CommandTask

get_type() → Type[idmtools_models.templated_script_task.TemplatedScriptTask]

Get task type provided by plugin

Returns

TemplatedScriptTask

class idmtools_models.templated_script_task.ScriptWrapperTaskSpecification

Bases: idmtools.registry.task_specification.TaskSpecification

get(configuration: dict)idmtools_models.templated_script_task.ScriptWrapperTask

Get instance of ScriptWrapperTask with configuration

Parameters

configuration – configuration for ScriptWrapperTask

Returns

TemplatedScriptTask with configuration

get_description() → str

Get description of plugin

Returns

Plugin description

get_example_urls() → List[str]

Get example urls related to ScriptWrapperTask

Returns

List of urls that have examples related to CommandTask

get_type() → Type[idmtools_models.templated_script_task.ScriptWrapperTask]

Get task type provided by plugin

Returns

TemplatedScriptTask