@@ -102,16 +102,14 @@ def export(self, outfile=None):
102
102
if self .doc :
103
103
cwl_tool ['doc' ] = literal (self .doc )
104
104
# Add Inputs
105
- if self .inputs :
106
- cwl_tool ['inputs' ] = {}
107
- for in_param in self .inputs :
108
- cwl_tool ['inputs' ][in_param .id ] = in_param .get_dict ()
105
+ cwl_tool ['inputs' ] = {}
106
+ for in_param in self .inputs :
107
+ cwl_tool ['inputs' ][in_param .id ] = in_param .get_dict ()
109
108
110
109
# Add Outputs
111
- if self .outputs :
112
- cwl_tool ['outputs' ] = {}
113
- for out_param in self .outputs :
114
- cwl_tool ['outputs' ][out_param .id ] = out_param .get_dict ()
110
+ cwl_tool ['outputs' ] = {}
111
+ for out_param in self .outputs :
112
+ cwl_tool ['outputs' ][out_param .id ] = out_param .get_dict ()
115
113
116
114
# If metadata are present in the description
117
115
if getattr (self , 'metadata' , None ):
@@ -122,6 +120,14 @@ def export(self, outfile=None):
122
120
for k , v in self .namespaces .__dict__ .items ():
123
121
if '$' not in v :
124
122
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
125
131
126
132
# Write CWL file in YAML
127
133
if outfile is None :
@@ -367,6 +373,13 @@ def __init__(self, req_class):
367
373
'''
368
374
self .req_class = req_class
369
375
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
+
370
383
371
384
class InlineJavascriptReq (Requirement ):
372
385
'''
@@ -412,6 +425,16 @@ def __init__(self, docker_pull=None, docker_load=None, docker_file=None,
412
425
self .dockerImageId = docker_image_id
413
426
self .dockerOutputDir = docker_output_dir
414
427
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
+
415
438
416
439
class Namespaces (object ):
417
440
"""
0 commit comments