8000 Adds the remainder of requirements (mostly spec'd) · illusional/python-cwlgen@ea22ec6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea22ec6

Browse files
committed
Adds the remainder of requirements (mostly spec'd)
1 parent af4208c commit ea22ec6

File tree

1 file changed

+292
-14
lines changed

1 file changed

+292
-14
lines changed

cwlgen/requirements.py

Lines changed: 292 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,208 @@ def get_dict(self):
4242
return base
4343

4444

45+
class SchemaDefRequirement(Requirement):
46+
"""
47+
This field consists of an array of type definitions which must be used when interpreting the inputs and
48+
outputs fields. When a type field contain a IRI, the implementation must check if the type is defined
49+
in schemaDefs and use that definition. If the type is not found in schemaDefs, it is an error.
50+
The entries in schemaDefs must be processed in the order listed such that later schema definitions
51+
may refer to earlier schema definitions.
52+
53+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#SchemaDefRequirement
54+
"""
55+
56+
def __init__(self, types):
57+
"""
58+
:param types: The list of type definitions.
59+
:type types: list[InputRecordSchema | InputEnumSchema | InputArraySchema]
60+
"""
61+
Requirement.__init__(self, "SchemaDefRequirement")
62+
self.types = types
63+
64+
< 8000 span class=pl-k>def get_dict(self):
65+
base = Requirement.get_dict(self)
66+
base['types'] = [t.get_dict() for t in self.types]
67+
68+
# class InputRecordSchema(object):
69+
# """
70+
# Documentation: https://www.commonwl.org/v1.0/Workflow.html#InputRecordSchema
71+
# """
72+
# def __init__(self, label=None, name=None):
73+
# """
74+
# :param fields: Defines the fields of the record.
75+
# :type fields: array<InputRecordField>
76+
# :param label: A short, human-readable label of this object.
77+
# :param name: NF (Name of the InputRecord)
78+
# """
79+
# self.fields = []
80+
# self.label = label
81+
# self.name = name
82+
#
83+
# def get_dict(self):
84+
# schema = {"type": "record"}
85+
# if self.fields:
86+
# schema["fields"] = {f.name: f.get_dict() for f in self.fields}
87+
# if self.label:
88+
# schema["label"] = self.label
89+
# if self.name:
90+
# schema["name"] = self.name
91+
# return schema
92+
93+
94+
class SoftwareRequirement(Requirement):
95+
"""
96+
A list of software packages that should be configured in the environment of the defined process.
97+
98+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#SoftwareRequirement
99+
"""
100+
def __init__(self):
101+
Requirement.__init__(self, "SoftwareRequirement")
102+
self.packages = [] # list[SoftwarePackage]
103+
104+
def get_dict(self):
105+
base = Requirement.get_dict(self)
106+
base["packages"] = [p.get_dict() for p in self.packages]
107+
108+
class SoftwarePackage(object):
109+
"""
110+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#SoftwarePackage
111+
"""
112+
def __init__(self, package, version=None, specs=None):
113+
"""
114+
:param package: The name of the software to be made available. If the name is common, inconsistent,
115+
or otherwise ambiguous it should be combined with one or more identifiers in the specs field
116+
:param version: The (optional) versions of the software that are known to be compatible.
117+
:param specs: One or more IRIs identifying resources for installing or enabling the software in 'package'
118+
"""
119+
self.package = package
120+
self.version = version
121+
self.specs = version
122+
123+
def get_dict(self):
124+
base = {"package": self.package}
125+
if self.version:
126+
base["version"] = self.version
127+
if self.specs:
128+
base["specs"] = self.specs
129+
130+
131+
class InitialWorkDirRequirement(Requirement):
132+
"""
133+
Define a list of files and subdirectories that must be created by the workflow
134+
platform in the designated output directory prior to executing the command line tool.
135+
136+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#InitialWorkDirRequirement
137+
"""
138+
def __init__(self, listing):
139+
"""
140+
:param listing: The list of files or subdirectories that must be placed in the
141+
designated output directory prior to executing the command line tool.
142+
:type listing: array<File | Directory | Dirent | string | Expression> | string | Expression
143+
"""
144+
Requirement.__init__(self, "InitialWorkDirRequirement")
145+
self.listing = listing
146+
147+
def get_dict(self):
148+
base = Requirement.get_dict(self)
149+
150+
if isinstance(self.listing, str):
151+
base["listing"] = self.listing
152+
elif isinstance(self.listing, list):
153+
if len(self.listing) == 1:
154+
raise Exception("InitialWorkDirRequirement.listing must have at least one element")
155+
base["listing"] = [r if isinstance(r, str) else r.get_dict() for r in self.listing]
156+
else:
157+
raise Exception("Couldn't recognise type of '{list_type}', expected: array<File | Directory | Dirent | "
158+
"string| Expression> | string | Expression".format(list_type=type(self.listing)))
159+
160+
return base
161+
162+
class Dirent(object):
163+
"""
164+
Define a file or subdirectory that must be placed in the designated output directory
165+
prior to executing the command line tool. May be the result of executing an expression,
166+
such as building a configuration file from a template.
167+
168+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#Dirent
169+
"""
170+
def __init__(self, entry, entryname=None, writable=None):
171+
self.entry = entry
172+
self.entryname = entryname
173+
self.writable = writable
174+
175+
def get_dict(self):
176+
return {k: v for k, v in vars(self).items() if v is not None}
177+
178+
179+
class SubworkflowFeatureRequirement(Requirement):
180+
"""
181+
Indicates that the workflow platform must support nested workflows in the run field of WorkflowStep.
182+
183+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#SubworkflowFeatureRequirement
184+
"""
185+
186+
def __init__(self):
187+
Requirement.__init__(self, 'SubworkflowFeatureRequirement')
188+
189+
def get_dict(self):
190+
return Requirement.get_dict(self)
191+
192+
193+
class ScatterFeatureRequirement(Requirement):
194+
"""
195+
Indicates that the workflow platform must support the scatter and scatterMethod fields of WorkflowStep.
196+
197+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#ScatterFeatureRequirement
198+
"""
199+
200+
def __init__(self):
201+
Requirement.__init__(self, 'ScatterFeatureRequirement')
202+
203+
def get_dict(self):
204+
return Requirement.get_dict(self)
205+
206+
207+
class MultipleInputFeatureRequirement(Requirement):
208+
"""
209+
Indicates that the workflow platform must support multiple
210+
inbound data links listed in the source field of WorkflowStepInput.
211+
212+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#MultipleInputFeatureRequirement
213+
"""
214+
215+
def __init__(self):
216+
Requirement.__init__(self, 'MultipleInputFeatureRequirement')
217+
218+
def get_dict(self):
219+
return Requirement.get_dict(self)
220+
221+
222+
class StepInputExpressionRequirement(Requirement):
223+
"""
224+
Indicate that the workflow platform must support the valueFrom field of WorkflowStepInput.
225+
226+
Documentation: https://www.commonwl.org/v1.0/Workflow.html#StepInputExpressionRequirement
227+
"""
228+
229+
def __init__(self):
230+
Requirement.__init__(self, 'StepInputExpressionRequirement')
231+
232+
def get_dict(self):
233+
return Requirement.get_dict(self)
45234

46235

47236
class DockerRequirement(Requirement):
48-
'''
49-
Workflow component should be run in a Docker container.
50-
This class specifies how to fetch or build the image.
51-
'''
237+
"""
238+
Indicates that a workflow component should be run in a Docker container,
239+
and specifies how to fetch or build the image.
240+
241+
Documentation: https://www.commonwl.org/v1.0/CommandLineTool.html#DockerRequirement
242+
"""
52243

53244
def __init__(self, docker_pull=None, docker_load=None, docker_file=None,
54245
docker_import=None, docker_image_id=None, docker_output_dir=None):
55-
'''
246+
"""
56247
:param docker_pull: image to retrive with docker pull
57248
:type docker_pull: STRING
58249
:param docker_load: HTTP URL from which to download Docker image
@@ -65,7 +256,7 @@ def __init__(self, docker_pull=None, docker_load=None, docker_file=None,
65256
:type docker_image_id: STRING
66257
:param docker_output_dir: designated output dir inside the Docker container
67258
:type docker_output_dir: STRING
68-
'''
259+
"""
69260
Requirement.__init__(self, 'DockerRequirement')
70261
self.dockerPull = docker_pull
71262
self.dockerLoad = docker_load
@@ -74,19 +265,106 @@ def __init__(self, docker_pull=None, docker_load=None, docker_file=None,
74265
self.dockerImageId = docker_image_id
75266
self.dockerOutputDir = docker_output_dir
76267

77-
def _to_dict(self):
268+
def get_dict(self):
269+
base = Requirement.get_dict(self)
270+
base.update({p: v for p, v in vars(self).items() if p.startswith('docker') and v is not None})
271+
return base
272+
273+
274+
class EnvVarRequirement(Requirement):
275+
"""
276+
Define a list of environment variables which will be set in the execution environment of the tool.
277+
See EnvironmentDef for details.
278+
279+
Documentation: https://www.commonwl.org/v1.0/CommandLineTool.html#EnvVarRequirement
280+
"""
281+
def __init__(self, env_def):
78282
"""
79-
Add this requirement to a dictionary description of a
80-
tool generated in an export method.
283+
:param env_def: The list of environment variables.
284+
:type env_def: list[EnvironmentDef]
285+
"""
286+
Requirement.__init__(self, 'ShellCommandRequirement')
287+
self.envDef = env_def
288+
289+
def get_dict(self):
290+
base = Requirement.get_dict(self)
291+
base["envDef"] = [e.get_dict() for e in self.envDef]
81292

293+
class EnvironmentDef(object):
82294
"""
83-
return {p: v for p, v in vars(self).items() if p.startswith('docker') and v is not None}
295+
Define an environment variable that will be set in the runtime environment
296+
by the workflow platform when executing the command line tool.
297+
May be the result of executing an expression, such as getting a parameter from input.
84298
299+
Documentation: https://www.commonwl.org/v1.0/CommandLineTool.html#EnvironmentDef
300+
"""
301+
def __init__(self, env_name, env_value):
302+
"""
303+
:param env_name: The environment variable name
304+
:type env_name: STRING
305+
:param env_value: The environment variable value
306+
:type env_value: STRING
307+
"""
308+
self.envName = env_name
309+
self.envValue = env_value
85310

86-
class SubworkflowFeatureRequirement(Requirement):
311+
def get_dict(self):
312+
return {"envName": self.envName, "envValue": self.envValue}
313+
314+
315+
class ShellCommandRequirement(Requirement):
316+
"""
317+
Modify the behavior of CommandLineTool to generate a single string containing a shell command line.
318+
319+
Documentation: https://www.commonwl.org/v1.0/CommandLineTool.html#ShellCommandRequirement
320+
"""
87321

88322
def __init__(self):
89-
Requirement.__init__(self, 'SubworkflowFeatureRequirement')
323+
Requirement.__init__(self, 'ShellCommandRequirement')
324+
325+
def get_dict(self):
326+
return Requirement.get_dict(self)
327+
328+
329+
class ResourceRequirement(Requirement):
330+
"""
331+
Specify basic hardware resource requirements.
332+
333+
Documentation: https://www.commonwl.org/v1.0/CommandLineTool.html#ResourceRequirement
334+
"""
90335

91-
def _to_dict(self):
92-
return dict()
336+
def __init__(self, cores_min=None, cores_max=None, ram_min=None, ram_max=None, tmpdir_min=None, tmpdir_max=None,
337+
outdir_min=None, outdir_max=None):
338+
"""
339+
:param cores_min: Minimum reserved number of CPU cores
340+
:type cores_min: string | float
341+
:param cores_max: Maximum reserved number of CPU cores
342+
:type cores_max: string | float
343+
:param ram_min: Minimum reserved RAM in mebibytes (2**20)
344+
:type ram_min: string | float
345+
:param ram_max: Maximum reserved RAM in mebibytes (2**20)
346+
:type ram_max: string | float
347+
:param tmpdir_min: Minimum reserved filesystem based storage for the designated temporary directory, in mebibytes (2**20)
348+
:type tmpdir_min: string | float
349+
:param tmpdir_max: Maximum reserved filesystem based storage for the designated temporary directory, in mebibytes (2**20)
350+
:type tmpdir_max: string | float
351+
:param outdir_min: Minimum reserved filesystem based storage for the designated output directory, in mebibytes (2**20)
352+
:type outdir_min: string | float
353+
:param outdir_max: Maximum reserved filesystem based storage for the designated output directory, in mebibytes (2**20)
354+
:type outdir_max: string | float
355+
"""
356+
Requirement.__init__(self, 'ResourceRequirement')
357+
358+
self.coresMin = cores_min
359+
self.coresMax = cores_max
360+
self.ramMin = ram_min
361+
self.ramMax = ram_max
362+
self.tmpdirMin = tmpdir_min
363+
self.tmpdirMax = tmpdir_max
364+
self.outdirMin = outdir_min
365+
self.outdirMax = outdir_max
366+
367+
def get_dict(self):
368+
base = Requirement.get_dict(self)
369+
base.update({p: v for p, v in vars(self).items() if v is not None})
370+
return base

0 commit comments

Comments
 (0)
0