6
6
7
7
# General libraries
8
8
import os
9
- import argparse
10
- import sys
9
+ import six
11
10
import logging
12
11
13
12
# External libraries
14
13
import ruamel .yaml as ryaml
15
- import six
16
14
import cwlgen
17
15
import cwlgen .workflow
18
16
19
17
logging .basicConfig (level = logging .INFO )
20
- logger = logging .getLogger (__name__ )
18
+ _LOGGER = logging .getLogger (__name__ )
21
19
22
20
# Class(es) ------------------------------
23
21
22
+
24
23
def parse_cwl (cwl_path ):
24
+ """
25
+ Method that parse a CWL file.
26
+
27
+ :param cwl_path: PATH to the CWL file
28
+ :type cwl_path: STRING
29
+ """
25
30
with open (cwl_path ) as yaml_file :
26
31
cwl_dict = ryaml .load (yaml_file , Loader = ryaml .Loader )
27
32
cl = cwl_dict ['class' ]
@@ -34,6 +39,7 @@ def parse_cwl(cwl_path):
34
39
return p .import_cwl (cwl_path )
35
40
return None
36
41
42
+
37
43
class CWLToolParser (object ):
38
44
"""
39
45
Class to import content from an existing CWL Tool.
@@ -152,7 +158,7 @@ def _load_class(self, tool, class_el):
152
158
:type class_el: STRING
153
159
"""
154
160
if class_el != 'CommandLineTool' :
155
- logger .warning ('cwlgen library only handle CommandLineTool for the moment' )
161
+ _LOGGER .warning ('cwlgen library only handle CommandLineTool for the moment' )
156
162
157
163
def _load_inputs (self , tool , inputs_el ):
158
164
"""
@@ -194,20 +200,26 @@ def import_cwl(self, cwl_path):
194
200
try :
195
201
getattr (self , '_load_{}' .format (key ))(tool , element )
196
202
except AttributeError :
197
- logger .warning (key + " content is not processed (yet)." )
203
+ _LOGGER .warning (key + " content is not processed (yet)." )
198
204
tool ._path = cwl_path
199
205
return tool
200
206
207
+
201
208
def dict_or_idlist_items (v ):
209
+ """
210
+ :param v:
211
+ :type v: DICT of [DICT]
212
+ """
202
213
if isinstance (v , dict ):
203
214
return v .items ()
204
215
o = []
205
216
for i in v :
206
217
e = dict (i )
207
218
del e ['id' ]
208
- o .append ( (i ['id' ], e ) )
219
+ o .append ((i ['id' ], e ))
209
220
return o
210
221
222
+
211
223
class InputsParser (object ):
212
224
"""
213
225
Class to parse content of inputs from an existing CWL Tool.
@@ -318,7 +330,7 @@ def load_inputs(self, inputs, inputs_el):
318
330
try :
319
331
getattr (self , '_load_{}' .format (key ))(input_obj , element )
320
332
except AttributeError :
321
- logger .warning (key + " content for input is not processed (yet)." )
333
+ _LOGGER .warning (key + " content for input is not processed (yet)." )
322
334
inputs .append (input_obj )
323
335
324
336
@@ -418,7 +430,7 @@ def load_inbinding(self, input_obj, inbinding_el):
418
430
try :
419
431
getattr (self , '_load_{}' .format (key ))(inbinding_obj , value )
420
432
except AttributeError :
421
- logger .warning (key + " content for inputBinding is not processed (yet)." )
433
+ _LOGGER .warning (key + " content for inputBinding is not processed (yet)." )
422
434
input_obj .inputBinding = inbinding_obj
423
435
424
436
@@ -532,7 +544,7 @@ def load_outputs(self, outputs, outputs_el):
532
544
try :
533
545
getattr (self , '_load_{}' .format (key ))(output_obj , element )
534
546
except AttributeError :
535
- logger .warning (key + " content for output is not processed (yet)." )
547
+ _LOGGER .warning (key + " content for output is not processed (yet)." )
536
548
outputs .append (output_obj )
537
549
538
550
@@ -588,7 +600,7 @@ def load_outbinding(self, output_obj, outbinding_el):
588
600
try :
589
601
getattr (self , '_load_{}' .format (key ))(outbinding_obj , value )
590
602
except AttributeError :
591
- logger .warning (key + " content for outputBinding is not processed (yet)." )
603
+ _LOGGER .warning (key + " content for outputBinding is not processed (yet)." )
592
604
output_obj .outputBinding = outbinding_obj
593
605
594
606
@@ -597,10 +609,22 @@ class StepsParser(object):
597
609
Class to parse content of steps of workflow from existing CWL Workflow.
598
610
"""
599
611
def __init__ (self , basedir = None , expand_run = True ):
612
+ """
613
+ :param basedir:
614
+ :type basedir:
615
+ :param expand_run:
616
+ :type: expand_run:
617
+ """
600
618
self .basedir = basedir
601
619
self .expand_run = expand_run
602
620
603
621
def _load_in (self , step_obj , in_el ):
622
+ """
623
+ :param step_obj:
624
+ :type step_obj:
625
+ :param in_el:
626
+ :type in_el:
627
+ """
604
628
for key , val in in_el .items ():
605
629
o = cwlgen .workflow .WorkflowStepInput (key )
606
630
if isinstance (val , dict ) and 'default' in val :
@@ -615,14 +639,13 @@ def _load_out(self, step_obj, in_el):
615
639
step_obj .outputs .append (o )
616
640
617
641
def _load_run (self , step_obj , in_el ):
618
- if isinstance (in_el , basestring ) and self .expand_run :
642
+ if isinstance (in_el , six . string_types ) and self .expand_run :
619
643
path = os .path .join (self .basedir , in_el )
620
- #logger.info("Parsing: %s", path)
644
+ # logger.info("Parsing: %s", path)
621
645
step_obj .run = parse_cwl (path )
622
646
else :
623
647
step_obj .run = in_el
624
648
625
-
626
649
def load_steps (self , steps_obj , steps_elm ):
627
650
"""
628
651
Load the content of step into the output object.
@@ -638,7 +661,7 @@ def load_steps(self, steps_obj, steps_elm):
638
661
try :
639
662
getattr (self , '_load_{}' .format (key ))(step_obj , element )
640
663
except AttributeError :
641
- logger .warning (key + " content for input is not processed (yet)." )
664
+ _LOGGER .warning (key + " content for input is not processed (yet)." )
642
665
steps_obj .append (step_obj )
643
666
644
667
@@ -674,7 +697,7 @@ def import_cwl(self, cwl_path):
674
697
try :
675
698
getattr (self , '_load_{}' .format (key ))(tool , element )
676
699
except AttributeError :
677
- logger .warning (key + " workflow content is not processed (yet)." )
700
+ _LOGGER .warning (key + " workflow content is not processed (yet)." )
678
701
tool ._path = cwl_path
679
702
return tool
680
703
@@ -700,7 +723,6 @@ def _load_cwlVersion(self, tool, cwl_version_el):
700
723
"""
701
724
tool .cwlVersion = cwl_version_el
702
725
703
-
704
726
def _load_class (self , tool , class_el ):
705
727
"""
706
728
Display message to inform that cwlgen only deal with Workflow for the moment.
@@ -711,7 +733,7 @@ def _load_class(self, tool, class_el):
711
733
:type class_el: STRING
712
734
"""
713
735
if class_el != 'Workflow' :
714
- logger .warning ('cwlgen library only handle Workflow for the moment' )
736
+ _LOGGER .warning ('cwlgen library only handle Workflow for the moment' )
715
737
716
738
def _load_requirements (self , tool , req_el ):
717
739
pass
@@ -740,7 +762,6 @@ def _load_outputs(self, tool, outputs_el):
740
762
inp_parser = OutputsParser ()
741
763
inp_parser .load_outputs (tool .outputs , outputs_el )
742
764
743
-
744
765
def _load_steps (self , tool , outputs_el ):
745
766
"""
746
767
Load the content of inputs into the tool.
0 commit comments