idmtools-models 0.0.0.dev0__py3-none-any.whl → 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- idmtools_models/__init__.py +18 -8
- idmtools_models/json_configured_task.py +337 -0
- idmtools_models/python/__init__.py +5 -0
- idmtools_models/python/json_python_task.py +154 -0
- idmtools_models/python/python_task.py +163 -0
- idmtools_models/r/__init__.py +5 -0
- idmtools_models/r/json_r_task.py +155 -0
- idmtools_models/r/r_task.py +146 -0
- idmtools_models/templated_script_task.py +587 -0
- idmtools_models-0.0.2.dist-info/METADATA +57 -0
- idmtools_models-0.0.2.dist-info/RECORD +15 -0
- idmtools_models-0.0.2.dist-info/entry_points.txt +8 -0
- idmtools_models-0.0.2.dist-info/licenses/LICENSE.TXT +3 -0
- idmtools_models-0.0.0.dev0.dist-info/METADATA +0 -41
- idmtools_models-0.0.0.dev0.dist-info/RECORD +0 -5
- {idmtools_models-0.0.0.dev0.dist-info → idmtools_models-0.0.2.dist-info}/WHEEL +0 -0
- {idmtools_models-0.0.0.dev0.dist-info → idmtools_models-0.0.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
"""Provides the TemplatedScriptTask.
|
|
2
|
+
|
|
3
|
+
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
import copy
|
|
6
|
+
import inspect
|
|
7
|
+
import os
|
|
8
|
+
from contextlib import suppress
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from functools import partial
|
|
11
|
+
from logging import getLogger, DEBUG
|
|
12
|
+
from typing import List, Callable, Type, Dict, Any, Union, TYPE_CHECKING
|
|
13
|
+
from jinja2 import Environment
|
|
14
|
+
from idmtools.assets import AssetCollection, Asset
|
|
15
|
+
from idmtools.entities import CommandLine
|
|
16
|
+
from idmtools.entities.itask import ITask
|
|
17
|
+
from idmtools.entities.iworkflow_item import IWorkflowItem
|
|
18
|
+
from idmtools.entities.simulation import Simulation
|
|
19
|
+
from idmtools.registry.task_specification import TaskSpecification
|
|
20
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
21
|
+
from idmtools.entities.iplatform import IPlatform
|
|
22
|
+
|
|
23
|
+
logger = getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
LINUX_DICT_TO_ENVIRONMENT = """{% for key, value in vars.items() %}
|
|
26
|
+
export {{key}}="{{value}}"
|
|
27
|
+
{% endfor %}
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
WINDOWS_DICT_TO_ENVIRONMENT = """{% for key, value in vars.items() %}
|
|
31
|
+
set {{key}}="{{value}}"
|
|
32
|
+
{% endfor %}
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# Define our common windows templates
|
|
36
|
+
WINDOWS_BASE_WRAPPER = """echo Running %*
|
|
37
|
+
%*"""
|
|
38
|
+
WINDOWS_PYTHON_PATH_WRAPPER = """set PYTHONPATH=%cd%\\Assets\\site-packages\\;%cd%\\Assets\\;%PYTHONPATH%
|
|
39
|
+
{}""".format(WINDOWS_BASE_WRAPPER)
|
|
40
|
+
WINDOWS_DICT_TO_ENVIRONMENT = WINDOWS_DICT_TO_ENVIRONMENT + WINDOWS_BASE_WRAPPER
|
|
41
|
+
|
|
42
|
+
# Define our linux common scripts
|
|
43
|
+
LINUX_BASE_WRAPPER = """echo Running args $@
|
|
44
|
+
\"$@\"
|
|
45
|
+
"""
|
|
46
|
+
LINUX_PYTHON_PATH_WRAPPER = """export PYTHONPATH=$(pwd)/Assets/site-packages:$(pwd)/Assets/:$PYTHONPATH
|
|
47
|
+
{}""".format(LINUX_BASE_WRAPPER)
|
|
48
|
+
LINUX_DICT_TO_ENVIRONMENT = LINUX_DICT_TO_ENVIRONMENT + LINUX_BASE_WRAPPER
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass()
|
|
52
|
+
class TemplatedScriptTask(ITask):
|
|
53
|
+
"""
|
|
54
|
+
Defines a task to run a script using a template. Best suited to shell scripts.
|
|
55
|
+
|
|
56
|
+
Examples:
|
|
57
|
+
In this example, we add modify the Python Path using TemplatedScriptTask and LINUX_PYTHON_PATH_WRAPPER
|
|
58
|
+
|
|
59
|
+
.. literalinclude:: ../../examples/cookbook/python/python-path/python-path.py
|
|
60
|
+
|
|
61
|
+
In this example, we modify environment variable using TemplatedScriptTask and LINUX_DICT_TO_ENVIRONMENT
|
|
62
|
+
|
|
63
|
+
.. literalinclude:: ../../examples/cookbook/environment/variables/environment-vars.py
|
|
64
|
+
"""
|
|
65
|
+
#: Name of script
|
|
66
|
+
script_path: str = field(default=None, metadata={"md": True})
|
|
67
|
+
#: If platform requires path to script executing binary(ie /bin/bash)
|
|
68
|
+
script_binary: str = field(default=None, metadata={"md": True})
|
|
69
|
+
#: The template contents
|
|
70
|
+
template: str = field(default=None, metadata={"md": True})
|
|
71
|
+
#: The template file. You can only use either template or template_file at once
|
|
72
|
+
template_file: str = field(default=None, metadata={"md": True})
|
|
73
|
+
#: Controls whether a template should be an experiment or a simulation level asset
|
|
74
|
+
template_is_common: bool = field(default=True, metadata={"md": True})
|
|
75
|
+
#: Template variables used for rendering the template
|
|
76
|
+
# Note: large amounts of variables will increase metadata size
|
|
77
|
+
variables: Dict[str, Any] = field(default_factory=dict, metadata={"md": True})
|
|
78
|
+
#: Platform Path Separator. For Windows execution platforms, use \, otherwise use the default of /
|
|
79
|
+
path_sep: str = field(default='/', metadata={"md": True})
|
|
80
|
+
#: Extra arguments to add to the command line
|
|
81
|
+
extra_command_arguments: str = field(default='', metadata={"md": True})
|
|
82
|
+
|
|
83
|
+
#: Hooks to gather common assets
|
|
84
|
+
gather_common_asset_hooks: List[Callable[[ITask], AssetCollection]] = field(default_factory=list)
|
|
85
|
+
#: Hooks to gather transient assets
|
|
86
|
+
gather_transient_asset_hooks: List[Callable[[ITask], AssetCollection]] = field(default_factory=list)
|
|
87
|
+
|
|
88
|
+
def __post_init__(self):
|
|
89
|
+
"""Constructor."""
|
|
90
|
+
super().__post_init__()
|
|
91
|
+
if self.script_path is None and self.template_file is None:
|
|
92
|
+
raise ValueError("Either script name or template file is required")
|
|
93
|
+
elif self.script_path is None: # Get name from the file
|
|
94
|
+
self.script_path = os.path.basename(self.template_file)
|
|
95
|
+
|
|
96
|
+
if self.template is None and self.template_file is None:
|
|
97
|
+
raise ValueError("Either template or template_file is required")
|
|
98
|
+
|
|
99
|
+
if self.template_file and not os.path.exists(self.template_file):
|
|
100
|
+
raise FileNotFoundError(f"Could not find the file the template file {self.template_file}")
|
|
101
|
+
|
|
102
|
+
# is the template a common(experiment) asset?
|
|
103
|
+
if self.template_is_common:
|
|
104
|
+
if logger.isEnabledFor(DEBUG):
|
|
105
|
+
logger.debug("Adding common asset hook")
|
|
106
|
+
# add hook to render it to common asset hooks
|
|
107
|
+
hook = partial(TemplatedScriptTask._add_template_to_asset_collection, asset_collection=self.common_assets)
|
|
108
|
+
self.gather_common_asset_hooks.append(hook)
|
|
109
|
+
else:
|
|
110
|
+
# it must be a simulation level asset
|
|
111
|
+
if logger.isEnabledFor(DEBUG):
|
|
112
|
+
logger.debug("Adding transient asset hook")
|
|
113
|
+
# create hook to render it to our transient assets
|
|
114
|
+
hook = partial(
|
|
115
|
+
TemplatedScriptTask._add_template_to_asset_collection,
|
|
116
|
+
asset_collection=self.transient_assets
|
|
117
|
+
)
|
|
118
|
+
# add the hook
|
|
119
|
+
self.gather_transient_asset_hooks.append(hook)
|
|
120
|
+
|
|
121
|
+
@staticmethod
|
|
122
|
+
def _add_template_to_asset_collection(task: 'TemplatedScriptTask', asset_collection: AssetCollection) -> \
|
|
123
|
+
AssetCollection:
|
|
124
|
+
"""
|
|
125
|
+
Add our rendered template to the asset collection.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
task: Task to add
|
|
129
|
+
asset_collection:Asset collection
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
Asset Collection with template added
|
|
133
|
+
"""
|
|
134
|
+
# setup our jinja environment
|
|
135
|
+
env = Environment()
|
|
136
|
+
# try to load template from string or file
|
|
137
|
+
if task.template:
|
|
138
|
+
template = env.from_string(task.template)
|
|
139
|
+
else:
|
|
140
|
+
template = env.get_template(task.template_file)
|
|
141
|
+
if logger.isEnabledFor(DEBUG):
|
|
142
|
+
logger.debug(f"Rendering Script template: {template}")
|
|
143
|
+
# render the template
|
|
144
|
+
result = template.render(vars=task.variables, env=os.environ)
|
|
145
|
+
if logger.isEnabledFor(DEBUG):
|
|
146
|
+
logger.debug(f"Rendered Template: {result}")
|
|
147
|
+
|
|
148
|
+
# create an asset
|
|
149
|
+
asset = Asset(filename=task.script_path, content=result)
|
|
150
|
+
asset_collection.add_asset(asset)
|
|
151
|
+
return asset_collection
|
|
152
|
+
|
|
153
|
+
def gather_common_assets(self) -> AssetCollection:
|
|
154
|
+
"""
|
|
155
|
+
Gather common(experiment-level) assets for task.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
AssetCollection containing common assets
|
|
159
|
+
"""
|
|
160
|
+
# TODO validate hooks have expected return type
|
|
161
|
+
ac = AssetCollection()
|
|
162
|
+
for x in self.gather_common_asset_hooks:
|
|
163
|
+
ac += x(self)
|
|
164
|
+
return ac
|
|
165
|
+
|
|
166
|
+
def gather_transient_assets(self) -> AssetCollection:
|
|
167
|
+
"""
|
|
168
|
+
Gather transient(experiment-level) assets for task.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
AssetCollection containing transient assets
|
|
172
|
+
"""
|
|
173
|
+
ac = AssetCollection()
|
|
174
|
+
for x in self.gather_transient_asset_hooks:
|
|
175
|
+
ac += x(self)
|
|
176
|
+
ac += self.transient_assets
|
|
177
|
+
if len(ac.assets) != 0:
|
|
178
|
+
self.transient_assets = ac
|
|
179
|
+
return ac
|
|
180
|
+
|
|
181
|
+
def reload_from_simulation(self, simulation: Simulation):
|
|
182
|
+
"""
|
|
183
|
+
Reload a templated script task. When reloading, you will only have the rendered template available.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
simulation:
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
None
|
|
190
|
+
"""
|
|
191
|
+
# check experiment level assets for our script
|
|
192
|
+
if simulation.parent.assets:
|
|
193
|
+
# prep new asset collection in case we have to remove our asset from the experiment level
|
|
194
|
+
new_assets = AssetCollection()
|
|
195
|
+
for _i, asset in enumerate(simulation.parent.assets.assets):
|
|
196
|
+
# is it our script?
|
|
197
|
+
if asset.filename != self.script_path and asset.absolute_path != self.script_path:
|
|
198
|
+
# nope keep it
|
|
199
|
+
new_assets.add_asset(asset)
|
|
200
|
+
# set filtered assets back to parent
|
|
201
|
+
simulation.parent.assets = new_assets
|
|
202
|
+
|
|
203
|
+
def pre_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
204
|
+
"""
|
|
205
|
+
Before creating simulation, we need to set our command line.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
parent: Parent object
|
|
209
|
+
platform: Platform item is being ran on
|
|
210
|
+
Returns:
|
|
211
|
+
|
|
212
|
+
"""
|
|
213
|
+
# are we experiment or simulation level asset?
|
|
214
|
+
if self.script_binary:
|
|
215
|
+
sn = self.script_binary + ' '
|
|
216
|
+
else:
|
|
217
|
+
sn = ''
|
|
218
|
+
if self.template_is_common:
|
|
219
|
+
sn += platform.join_path(platform.common_asset_path, self.script_path)
|
|
220
|
+
else:
|
|
221
|
+
sn += self.script_path
|
|
222
|
+
# set the command line to the rendered script
|
|
223
|
+
self.command = CommandLine.from_string(sn)
|
|
224
|
+
if self.path_sep != "/":
|
|
225
|
+
self.command.executable = self.command.executable.replace("/", self.path_sep)
|
|
226
|
+
self.command.is_windows = True
|
|
227
|
+
# set any extra arguments
|
|
228
|
+
if self.extra_command_arguments:
|
|
229
|
+
other_command = CommandLine.from_string(self.extra_command_arguments)
|
|
230
|
+
self.command._args.append(other_command.executable)
|
|
231
|
+
if other_command._options:
|
|
232
|
+
self.command._args += other_command._options
|
|
233
|
+
if other_command._args:
|
|
234
|
+
self.command._args += other_command._args
|
|
235
|
+
super().pre_creation(parent, platform)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@dataclass()
|
|
239
|
+
class ScriptWrapperTask(ITask):
|
|
240
|
+
"""
|
|
241
|
+
Allows you to wrap a script with another script.
|
|
242
|
+
|
|
243
|
+
See Also:
|
|
244
|
+
:py:class:`idmtools_models.templated_script_task.TemplatedScriptTask`
|
|
245
|
+
|
|
246
|
+
Raises:
|
|
247
|
+
ValueError if the template Script Task is not defined
|
|
248
|
+
"""
|
|
249
|
+
template_script_task: TemplatedScriptTask = field(default=None)
|
|
250
|
+
task: ITask = field(default=None)
|
|
251
|
+
|
|
252
|
+
def __post_init__(self):
|
|
253
|
+
"""Constructor."""
|
|
254
|
+
if self.template_script_task is None:
|
|
255
|
+
raise ValueError("Template Script Task is required")
|
|
256
|
+
|
|
257
|
+
if self.task is None:
|
|
258
|
+
raise ValueError("Task is required")
|
|
259
|
+
|
|
260
|
+
if isinstance(self.task, dict):
|
|
261
|
+
self.task = self.from_dict(self.task)
|
|
262
|
+
if isinstance(self.template_script_task, dict):
|
|
263
|
+
self.template_script_task = self.from_dict(self.template_script_task)
|
|
264
|
+
|
|
265
|
+
@staticmethod
|
|
266
|
+
def from_dict(task_dictionary: Dict[str, Any]):
|
|
267
|
+
"""Load the task from a dictionary."""
|
|
268
|
+
from idmtools.core.task_factory import TaskFactory
|
|
269
|
+
task_args = {k: v for k, v in task_dictionary.items() if k not in ['task_type']}
|
|
270
|
+
return TaskFactory().create(task_dictionary['task_type'], **task_args)
|
|
271
|
+
|
|
272
|
+
@property
|
|
273
|
+
def command(self):
|
|
274
|
+
"""Our task property. Again, we have to overload this because of wrapping a task."""
|
|
275
|
+
cmd = copy.deepcopy(self.template_script_task.command)
|
|
276
|
+
cmd.add_raw_argument(str(self.task.command))
|
|
277
|
+
return cmd
|
|
278
|
+
|
|
279
|
+
@command.setter
|
|
280
|
+
def command(self, value: Union[str, CommandLine]):
|
|
281
|
+
"""Set our command. because we are wrapping a task, we have to overload this."""
|
|
282
|
+
callers = []
|
|
283
|
+
with suppress(KeyError, IndexError):
|
|
284
|
+
callers = inspect.stack()[1:3]
|
|
285
|
+
if not callers or callers[0].filename == __file__ or callers[1].filename == __file__:
|
|
286
|
+
if isinstance(value, property):
|
|
287
|
+
self._command = None
|
|
288
|
+
elif isinstance(value, str):
|
|
289
|
+
self._command = CommandLine.from_string(value)
|
|
290
|
+
else:
|
|
291
|
+
self._command = value
|
|
292
|
+
else:
|
|
293
|
+
self.task.command = value
|
|
294
|
+
|
|
295
|
+
@property
|
|
296
|
+
def wrapped_task(self):
|
|
297
|
+
"""
|
|
298
|
+
Our task we are wrapping with a shell script.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
Our wrapped task
|
|
302
|
+
"""
|
|
303
|
+
return self.task
|
|
304
|
+
|
|
305
|
+
@wrapped_task.setter
|
|
306
|
+
def wrapped_task(self, value: ITask):
|
|
307
|
+
"""Set our wrapped task."""
|
|
308
|
+
return None if isinstance(value, property) else value
|
|
309
|
+
|
|
310
|
+
def gather_common_assets(self):
|
|
311
|
+
"""
|
|
312
|
+
Gather all the common assets.
|
|
313
|
+
|
|
314
|
+
Returns:
|
|
315
|
+
Common assets(Experiment Assets)
|
|
316
|
+
"""
|
|
317
|
+
self.common_assets.add_assets(self.template_script_task.gather_common_assets())
|
|
318
|
+
self.common_assets.add_assets(self.task.gather_common_assets())
|
|
319
|
+
return self.common_assets
|
|
320
|
+
|
|
321
|
+
def gather_transient_assets(self) -> AssetCollection:
|
|
322
|
+
"""
|
|
323
|
+
Gather all the transient assets.
|
|
324
|
+
|
|
325
|
+
Returns:
|
|
326
|
+
Transient Assets(Simulation level assets)
|
|
327
|
+
"""
|
|
328
|
+
self.transient_assets.add_assets(self.template_script_task.gather_transient_assets())
|
|
329
|
+
self.transient_assets.add_assets(self.task.gather_transient_assets())
|
|
330
|
+
return self.transient_assets
|
|
331
|
+
|
|
332
|
+
def reload_from_simulation(self, simulation: Simulation):
|
|
333
|
+
"""
|
|
334
|
+
Reload from simulation.
|
|
335
|
+
|
|
336
|
+
Args:
|
|
337
|
+
simulation: simulation
|
|
338
|
+
|
|
339
|
+
Returns:
|
|
340
|
+
None
|
|
341
|
+
"""
|
|
342
|
+
pass
|
|
343
|
+
|
|
344
|
+
def pre_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
345
|
+
"""
|
|
346
|
+
Before creation, create the true command by adding the wrapper name.
|
|
347
|
+
|
|
348
|
+
Here we call both our wrapped task and our template_script_task pre_creation
|
|
349
|
+
Args:
|
|
350
|
+
parent: Parent Task
|
|
351
|
+
platform: Platform Templated Task is executing on
|
|
352
|
+
|
|
353
|
+
Returns:
|
|
354
|
+
None
|
|
355
|
+
"""
|
|
356
|
+
self.task.pre_creation(parent, platform)
|
|
357
|
+
self.template_script_task.pre_creation(parent, platform)
|
|
358
|
+
|
|
359
|
+
def post_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
360
|
+
"""
|
|
361
|
+
Post creation of task.
|
|
362
|
+
|
|
363
|
+
Here we call both our wrapped task and our template_script_task post_creation
|
|
364
|
+
|
|
365
|
+
Args:
|
|
366
|
+
parent: Parent of task
|
|
367
|
+
platform: Platform we are running on
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
None
|
|
371
|
+
"""
|
|
372
|
+
self.task.post_creation(parent, platform)
|
|
373
|
+
self.template_script_task.post_creation(parent, platform)
|
|
374
|
+
|
|
375
|
+
def __getattr__(self, item):
|
|
376
|
+
"""Proxy get attr to child except for task item and items not in our object."""
|
|
377
|
+
if item not in self.__dict__:
|
|
378
|
+
return getattr(self.task, item)
|
|
379
|
+
else:
|
|
380
|
+
return super(ScriptWrapperTask, self).__getattr__(item)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def get_script_wrapper_task(task: ITask, wrapper_script_name: str, template_content: str = None,
|
|
384
|
+
template_file: str = None, template_is_common: bool = True,
|
|
385
|
+
variables: Dict[str, Any] = None, path_sep: str = '/') -> ScriptWrapperTask:
|
|
386
|
+
"""
|
|
387
|
+
Convenience function that will wrap a task for you with some defaults.
|
|
388
|
+
|
|
389
|
+
Args:
|
|
390
|
+
task: Task to wrap
|
|
391
|
+
wrapper_script_name: Wrapper script name
|
|
392
|
+
template_content: Template Content
|
|
393
|
+
template_file: Template File
|
|
394
|
+
template_is_common: Is the template experiment level
|
|
395
|
+
variables: Variables
|
|
396
|
+
path_sep: Path sep(Window or Linux)
|
|
397
|
+
|
|
398
|
+
Returns:
|
|
399
|
+
ScriptWrapperTask wrapping the task
|
|
400
|
+
|
|
401
|
+
See Also:
|
|
402
|
+
:class:`idmtools_models.templated_script_task.TemplatedScriptTask`
|
|
403
|
+
:func:`idmtools_models.templated_script_task.get_script_wrapper_windows_task`
|
|
404
|
+
:func:`idmtools_models.templated_script_task.get_script_wrapper_unix_task`
|
|
405
|
+
"""
|
|
406
|
+
if variables is None:
|
|
407
|
+
variables = dict()
|
|
408
|
+
template_task = TemplatedScriptTask(
|
|
409
|
+
script_path=wrapper_script_name,
|
|
410
|
+
template_file=template_file,
|
|
411
|
+
template=template_content,
|
|
412
|
+
template_is_common=template_is_common,
|
|
413
|
+
variables=variables,
|
|
414
|
+
path_sep=path_sep
|
|
415
|
+
)
|
|
416
|
+
return ScriptWrapperTask(template_script_task=template_task, task=task)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def get_script_wrapper_windows_task(task: ITask, wrapper_script_name: str = 'wrapper.bat',
|
|
420
|
+
template_content: str = WINDOWS_DICT_TO_ENVIRONMENT,
|
|
421
|
+
template_file: str = None, template_is_common: bool = True,
|
|
422
|
+
variables: Dict[str, Any] = None) -> ScriptWrapperTask:
|
|
423
|
+
"""
|
|
424
|
+
Get wrapper script task for windows platforms.
|
|
425
|
+
|
|
426
|
+
The default content wraps a another task with a batch script that exports the variables to the run environment defined in variables. To modify python path, use WINDOWS_PYTHON_PATH_WRAPPER
|
|
427
|
+
|
|
428
|
+
You can adapt this script to modify any pre-scripts you need or call others scripts in succession
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
task: Task to wrap
|
|
432
|
+
wrapper_script_name: Wrapper script name(defaults to wrapper.bat)
|
|
433
|
+
template_content: Template Content.
|
|
434
|
+
template_file: Template File
|
|
435
|
+
template_is_common: Is the template experiment level
|
|
436
|
+
variables: Variables for template
|
|
437
|
+
|
|
438
|
+
Returns:
|
|
439
|
+
ScriptWrapperTask
|
|
440
|
+
|
|
441
|
+
See Also::
|
|
442
|
+
:class:`idmtools_models.templated_script_task.TemplatedScriptTask`
|
|
443
|
+
:func:`idmtools_models.templated_script_task.get_script_wrapper_task`
|
|
444
|
+
:func:`idmtools_models.templated_script_task.get_script_wrapper_unix_task`
|
|
445
|
+
"""
|
|
446
|
+
return get_script_wrapper_task(task, wrapper_script_name, template_content, template_file, template_is_common,
|
|
447
|
+
variables, "\\")
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def get_script_wrapper_unix_task(task: ITask, wrapper_script_name: str = 'wrapper.sh', template_content: str = LINUX_DICT_TO_ENVIRONMENT,
|
|
451
|
+
template_file: str = None, template_is_common: bool = True,
|
|
452
|
+
variables: Dict[str, Any] = None):
|
|
453
|
+
"""
|
|
454
|
+
Get wrapper script task for unix platforms.
|
|
455
|
+
|
|
456
|
+
The default content wraps a another task with a bash script that exports the variables to the run environment defined in variables. To modify python path, you can use LINUX_PYTHON_PATH_WRAPPER
|
|
457
|
+
|
|
458
|
+
You can adapt this script to modify any pre-scripts you need or call others scripts in succession
|
|
459
|
+
|
|
460
|
+
Args:
|
|
461
|
+
task: Task to wrap
|
|
462
|
+
wrapper_script_name: Wrapper script name(defaults to wrapper.sh)
|
|
463
|
+
template_content: Template Content
|
|
464
|
+
template_file: Template File
|
|
465
|
+
template_is_common: Is the template experiment level
|
|
466
|
+
variables: Variables for template
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
ScriptWrapperTask
|
|
470
|
+
|
|
471
|
+
See Also:
|
|
472
|
+
:class:`idmtools_models.templated_script_task.TemplatedScriptTask`
|
|
473
|
+
:func:`idmtools_models.templated_script_task.get_script_wrapper_task`
|
|
474
|
+
:func:`idmtools_models.templated_script_task.get_script_wrapper_windows_task`
|
|
475
|
+
"""
|
|
476
|
+
return get_script_wrapper_task(task, wrapper_script_name, template_content, template_file, template_is_common,
|
|
477
|
+
variables, "/")
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
class TemplatedScriptTaskSpecification(TaskSpecification):
|
|
481
|
+
"""
|
|
482
|
+
TemplatedScriptTaskSpecification provides the plugin specs for TemplatedScriptTask.
|
|
483
|
+
"""
|
|
484
|
+
|
|
485
|
+
def get(self, configuration: dict) -> TemplatedScriptTask:
|
|
486
|
+
"""
|
|
487
|
+
Get instance of TemplatedScriptTask with configuration.
|
|
488
|
+
|
|
489
|
+
Args:
|
|
490
|
+
configuration: configuration for TemplatedScriptTask
|
|
491
|
+
|
|
492
|
+
Returns:
|
|
493
|
+
TemplatedScriptTask with configuration
|
|
494
|
+
"""
|
|
495
|
+
return TemplatedScriptTask(**configuration)
|
|
496
|
+
|
|
497
|
+
def get_description(self) -> str:
|
|
498
|
+
"""
|
|
499
|
+
Get description of plugin.
|
|
500
|
+
|
|
501
|
+
Returns:
|
|
502
|
+
Plugin description
|
|
503
|
+
"""
|
|
504
|
+
return "Defines a general command that provides user hooks. Intended for use in advanced scenarios"
|
|
505
|
+
|
|
506
|
+
def get_example_urls(self) -> List[str]:
|
|
507
|
+
"""
|
|
508
|
+
Get example urls related to TemplatedScriptTask.
|
|
509
|
+
|
|
510
|
+
Returns:
|
|
511
|
+
List of urls that have examples related to CommandTask
|
|
512
|
+
"""
|
|
513
|
+
return []
|
|
514
|
+
|
|
515
|
+
def get_type(self) -> Type[TemplatedScriptTask]:
|
|
516
|
+
"""
|
|
517
|
+
Get task type provided by plugin.
|
|
518
|
+
|
|
519
|
+
Returns:
|
|
520
|
+
TemplatedScriptTask
|
|
521
|
+
"""
|
|
522
|
+
return TemplatedScriptTask
|
|
523
|
+
|
|
524
|
+
def get_version(self) -> str:
|
|
525
|
+
"""
|
|
526
|
+
Returns the version of the plugin.
|
|
527
|
+
|
|
528
|
+
Returns:
|
|
529
|
+
Plugin Version
|
|
530
|
+
"""
|
|
531
|
+
from idmtools_models import __version__
|
|
532
|
+
return __version__
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
class ScriptWrapperTaskSpecification(TaskSpecification):
|
|
536
|
+
"""
|
|
537
|
+
ScriptWrapperTaskSpecification defines the plugin specs for ScriptWrapperTask.
|
|
538
|
+
"""
|
|
539
|
+
|
|
540
|
+
def get(self, configuration: dict) -> ScriptWrapperTask:
|
|
541
|
+
"""
|
|
542
|
+
Get instance of ScriptWrapperTask with configuration.
|
|
543
|
+
|
|
544
|
+
Args:
|
|
545
|
+
configuration: configuration for ScriptWrapperTask
|
|
546
|
+
|
|
547
|
+
Returns:
|
|
548
|
+
TemplatedScriptTask with configuration
|
|
549
|
+
"""
|
|
550
|
+
return ScriptWrapperTask(**configuration)
|
|
551
|
+
|
|
552
|
+
def get_description(self) -> str:
|
|
553
|
+
"""
|
|
554
|
+
Get description of plugin.
|
|
555
|
+
|
|
556
|
+
Returns:
|
|
557
|
+
Plugin description
|
|
558
|
+
"""
|
|
559
|
+
return "Defines a general command that provides user hooks. Intended for use in advanced scenarios"
|
|
560
|
+
|
|
561
|
+
def get_example_urls(self) -> List[str]:
|
|
562
|
+
"""
|
|
563
|
+
Get example urls related to ScriptWrapperTask.
|
|
564
|
+
|
|
565
|
+
Returns:
|
|
566
|
+
List of urls that have examples related to CommandTask
|
|
567
|
+
"""
|
|
568
|
+
return []
|
|
569
|
+
|
|
570
|
+
def get_type(self) -> Type[ScriptWrapperTask]:
|
|
571
|
+
"""
|
|
572
|
+
Get task type provided by plugin.
|
|
573
|
+
|
|
574
|
+
Returns:
|
|
575
|
+
TemplatedScriptTask
|
|
576
|
+
"""
|
|
577
|
+
return ScriptWrapperTask
|
|
578
|
+
|
|
579
|
+
def get_version(self) -> str:
|
|
580
|
+
"""
|
|
581
|
+
Returns the version of the plugin.
|
|
582
|
+
|
|
583
|
+
Returns:
|
|
584
|
+
Plugin Version
|
|
585
|
+
"""
|
|
586
|
+
from idmtools_models import __version__
|
|
587
|
+
return __version__
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: idmtools_models
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Core tools for modeling
|
|
5
|
+
Author-email: Ross Carter <rcarter@idmod.org>, Sharon Chen <shchen@idmod.org>, Clinton Collins <ccollins@idmod.org>, Zhaowei Du <zdu@idmod.org>, Mary Fisher <mafisher@idmod.org>, Mandy Izzo <mizzo@idmod.org>, Clark Kirkman IV <ckirkman@idmod.org>, Benoit Raybaud <braybaud@idmod.org>, Jen Schripsema <jschripsema@idmod.org>
|
|
6
|
+
Project-URL: Homepage, https://github.com/InstituteforDiseaseModeling/idmtools
|
|
7
|
+
Keywords: modeling,IDM
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE.TXT
|
|
16
|
+
Requires-Dist: idmtools<1.0.0,>=0.0.0
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: idmtools[test]; extra == "test"
|
|
19
|
+
Requires-Dist: pyCOMPS~=2.11; extra == "test"
|
|
20
|
+
Requires-Dist: idmtools_test; extra == "test"
|
|
21
|
+
Requires-Dist: matplotlib~=3.10; extra == "test"
|
|
22
|
+
Provides-Extra: packaging
|
|
23
|
+
Requires-Dist: flake8; extra == "packaging"
|
|
24
|
+
Requires-Dist: coverage; extra == "packaging"
|
|
25
|
+
Requires-Dist: bump2version; extra == "packaging"
|
|
26
|
+
Requires-Dist: twine; extra == "packaging"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
# idmtools-models
|
|
32
|
+
|
|
33
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
34
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
35
|
+
**Table of Contents**
|
|
36
|
+
|
|
37
|
+
- [Installing](#installing)
|
|
38
|
+
- [Development Tips](#development-tips)
|
|
39
|
+
|
|
40
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
41
|
+
|
|
42
|
+
## Installing
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install idmtools-models --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
# Development Tips
|
|
49
|
+
|
|
50
|
+
There is a Makefile file available for most common development tasks. Here is a list of commands
|
|
51
|
+
```bash
|
|
52
|
+
clean - Clean up temproary files
|
|
53
|
+
lint - Lint package and tests
|
|
54
|
+
test - Run All tests
|
|
55
|
+
coverage - Run tests and generate coverage report that is shown in browser
|
|
56
|
+
```
|
|
57
|
+
On Windows, you can use `pymake` instead of `make`
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
idmtools_models/__init__.py,sha256=mon1bwhJ3TNSGdH7TbyhVwPX753TewoHimaLmZ0FrvQ,560
|
|
2
|
+
idmtools_models/json_configured_task.py,sha256=CF01hESsYBpoDLiq37m-cW-i0bU8sdKFxuVH5me7M9I,12694
|
|
3
|
+
idmtools_models/templated_script_task.py,sha256=FubBiFE8XqI5Lwv8U3ykKs-BOrdpULxxTggO0JVdzUM,21412
|
|
4
|
+
idmtools_models/python/__init__.py,sha256=BgvmrALTe3jLZ7gCmM-UTO2NAjojrJF98iHA1qN0Qq8,120
|
|
5
|
+
idmtools_models/python/json_python_task.py,sha256=v3LQxbYgRubdlMjDnWA8_bRdDdcv5fYC0VXrhsE-bDk,4792
|
|
6
|
+
idmtools_models/python/python_task.py,sha256=Lo8t6J_tJm9efkoaFahwE9m1RJuKwUePvJFAQkg6IA4,5311
|
|
7
|
+
idmtools_models/r/__init__.py,sha256=Dn65UBnHJpSRr5MPYEkg_sN-iz--wEud52rm_lJGoQ4,126
|
|
8
|
+
idmtools_models/r/json_r_task.py,sha256=dhWsOUtrFn2js-T_PYEAD09Re0W9p5ZD0hYDkthUBYg,4589
|
|
9
|
+
idmtools_models/r/r_task.py,sha256=ThAF__zEWO7ZlW0MhoPHRavfRmS7bqY_UECNauD3rkg,4371
|
|
10
|
+
idmtools_models-0.0.2.dist-info/licenses/LICENSE.TXT,sha256=l9S8Ydr_LcejxKoqK8191ZAOsmVX-nJLSPoLKZDUgcg,197
|
|
11
|
+
idmtools_models-0.0.2.dist-info/METADATA,sha256=ranhabkEarO0sKx75g65OKtsti5JZpfeSyoEWf-2E90,2322
|
|
12
|
+
idmtools_models-0.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
13
|
+
idmtools_models-0.0.2.dist-info/entry_points.txt,sha256=Z21S8l7ybGEhupvv2r40Xx9H_zV5ZgthHnE-v7pyW9A,646
|
|
14
|
+
idmtools_models-0.0.2.dist-info/top_level.txt,sha256=PYxIyA0SlUulJBju977SBgbM4mJ1jIv6jV3_2gT6PxM,16
|
|
15
|
+
idmtools_models-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[idmtools_task]
|
|
2
|
+
idmtools_task_json = idmtools_models.json_configured_task:JSONConfiguredTaskSpecification
|
|
3
|
+
idmtools_task_python = idmtools_models.python.python_task:PythonTaskSpecification
|
|
4
|
+
idmtools_task_python_json = idmtools_models.python.json_python_task:JSONConfiguredPythonTaskSpecification
|
|
5
|
+
idmtools_task_r = idmtools_models.r.r_task:RTaskSpecification
|
|
6
|
+
idmtools_task_r_json = idmtools_models.r.json_r_task:JSONConfiguredRTaskSpecification
|
|
7
|
+
idmtools_task_templated_script = idmtools_models.templated_script_task:TemplatedScriptTaskSpecification
|
|
8
|
+
idmtools_task_wrapper_script = idmtools_models.templated_script_task:ScriptWrapperTaskSpecification
|