Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit 320d09c

Browse files
committed
Generate the YAML for the DockerRequirement entry
Add methods to the Requirements objects to include this in the output CWL. Subclasses must implement a _to_dict method for this to work - I have done this for the DockerRequirement one as an example.
1 parent 46f6ab0 commit 320d09c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cwlgen/__init__.py

+25
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ def export(self, outfile=None):
120120
for k, v in self.namespaces.__dict__.items():
121121
if '$' not in v:
122122
cwl_tool[self.namespaces.name][k] = v
123+
124+
# Add requirements.
125+
requirements = {}
126+
for requirement in self.requirements:
127+
requirement.add(requirements)
128+
129+
if requirements:
130+
cwl_tool['requirements'] = requirements
123131

124132
# Write CWL file in YAML
125133
if outfile is None:
@@ -365,6 +373,13 @@ def __init__(self, req_class):
365373
'''
366374
self.req_class = req_class
367375

376+
def add(self, tool):
377+
tool[self.req_class] = self._to_dict()
378+
379+
def _to_dict(self):
380+
raise NotImplementedError("Requirement subclass {} not fully implemented".format(
381+
self.req_class))
382+
368383

369384
class InlineJavascriptReq(Requirement):
370385
'''
@@ -410,6 +425,16 @@ def __init__(self, docker_pull=None, docker_load=None, docker_file=None,
410425
self.dockerImageId = docker_image_id
411426
self.dockerOutputDir = docker_output_dir
412427

428+
def _to_dict(self):
429+
"""
430+
Add this requirement to a dictionary description of a
431+
tool generated in an export method.
432+
433+
"""
434+
return {p:v for p,v in vars(self).items() if p.startswith('docker') and v is not None}
435+
436+
437+
413438

414439
class Namespaces(object):
415440
"""

0 commit comments

Comments
 (0)