8000 cover more field for import_cwl and add appropriate unit tests · illusional/python-cwlgen@cd5198f · GitHub
[go: up one dir, main page]

Skip to content

Commit cd5198f

Browse files
committed
cover more field for import_cwl and add appropriate unit tests
1 parent 3d1db80 commit cd5198f

File tree

4 files changed

+365
-4
10000 lines changed

4 files changed

+365
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/__pycache__
2+
cwlgen/__pycache__

cwlgen/import_cwl.py

Lines changed: 263 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
logging.basicConfig(level=logging.INFO)
1919
logger = logging.getLogger(__name__)
2020

21-
# Class(es) ------------------------------
21+
# Class(es) ------------------------------
22+
2223

2324
class CWLToolParser(object):
2425
"""
@@ -28,7 +29,7 @@ class CWLToolParser(object):
2829
def _init_tool(self, cwl_dict):
2930
"""
3031
Init tool from existing CWL tool.
31-
32+
3233
:param cwl_dict: Full content of CWL file
3334
:type cwl_dict: DICT
3435
"""
@@ -161,7 +162,7 @@ def _load_outputs(self, tool, outputs_el):
161162
def import_cwl(self, cwl_path):
162163
"""
163164
Load content of cwl into the :class:`cwlgen.CommandLineTool` object.
164-
165+
165166
:param cwl_path: Path of the CWL tool to be loaded.
166167
:type cwl_path: STRING
167168
:return: CWL tool content in cwlgen model.
@@ -172,7 +173,7 @@ def import_cwl(self, cwl_path):
172173
tool = self._init_tool(cwl_dict)
173174
for key, element in cwl_dict.items():
174175
try:
175-
getattr(self, '_load_{}'.format(key))(tool, element)
176+
getattr(self, '_load_{}'.format(key))(tool, element)
176177
except AttributeError:
177178
logger.warning(key + " content is not processed (yet).")
178179
return tool
@@ -183,6 +184,95 @@ class InputsParser(object):
183184
Class to parse content of inputs from an existing CWL Tool.
184185
"""
185186

187+
def _load_label(self, input_obj, label_el):
188+
"""
189+
Load the content of type into the input object.
190+
191+
:param input_obj: input obj
192+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
193+
:param label_el: Content of label
194+
:type label_el: STRING
195+
"""
196+
input_obj.label = label_el
197+
198+
def _load_secondaryFiles(self, input_obj, secfile_el):
199+
"""
200+
Load the content of secondaryFiles into the input object.
201+
202+
:param input_obj: input obj
203+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
204+
:param secfile_el: Content of secondaryFile
205+
:type secfile_el: STRING
206+
"""
207+
input_obj.secondary_file = secfile_el
208+
209+
def _load_format(self, input_obj, format_el):
210+
"""
6D4E
211+
Load the content of format into the input object.
212+
213+
:param input_obj: input obj
214+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
215+
:param format_el: Content of format
216+
:type format_el: STRING
217+
"""
218+
input_obj.format = format_el
219+
220+
def _load_streamable(self, input_obj, stream_el):
221+
"""
222+
Load the content of streamable into the input object.
223+
224+
:param input_obj: input obj
225+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
226+
:param stream_el: Content of streamable
227+
:type type_el: BOOLEAN
228+
"""
229+
input_obj.streamable = stream_el
230+
231+
def _load_doc(self, input_obj, doc_el):
232+
"""
233+
Load the content of doc into the input object.
234+
235+
:param input_obj: input obj
236+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
237+
:param doc_el: Content of doc
238+
:type doc_el: STRING
239+
"""
240+
input_obj.doc = doc_el
241+
242+
def _load_inputBinding(self, input_obj, inpb_el):
243+
"""
244+
Load the content of inputBinding into the input object.
245+
246+
:param input_obj: input obj
247+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
248+
:param inpb_el: Content of inputBinding
249+
:type inpb_el: DICT
250+
"""
251+
ibparser = InputBindingParser()
252+
ibparser.load_inbinding(input_obj, inpb_el)
253+
254+
def _load_default(self, input_obj, def_el):
255+
"""
256+
Load the content of default into the input object.
257+
258+
:param input_obj: input obj
259+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
260+
:param default_el: Content of default
261+
:type default_el: STRING
262+
"""
263+
input_obj.default = def_el
264+
265+
def _load_type(self, input_obj, type_el):
266+
"""
267+
Load the content of type into the input object.
268+
269+
:param input_obj: input obj
270+
:type input_obj: : :class:`cwlgen.CommandInputParameter`
271+
:param type_el: Content of type
272+
:type type_el: STRING
273+
"""
274+
input_obj.type = type_el
275+
186276
def load_inputs(self, inputs, inputs_el):
187277
"""
188278
Load the content of inputs into the inputs list.
@@ -203,11 +293,180 @@ def load_inputs(self, inputs, inputs_el):
203293
inputs.append(input_obj)
204294

205295

296+
class InputBindingParser(object):
297+
"""
298+
Class to parse content of inputBinding of input from existing CWL Tool.
299+
"""
300+
301+
def _load_loadContents(self, inbinding_obj, loadcontents_el):
302+
"""
303+
Load the content of loadContents into the input object.
304+
305+
:param inbinding_obj: input_binding object
306+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
307+
:param loadcontents_el: Content of loadContents
308+
:loadContents loadcontents_el: BOOLEAN
309+
"""
310+
inbinding_obj.load_contents = loadcontents_el
311+
312+
def _load_position(self, inbinding_obj, position_el):
313+
"""
314+
Load the content of position into the input object.
315+
316+
:param inbinding_obj: input_binding object
317+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
318+
:param position_el: Content of loadContents
319+
:loadContents position_el: INT
320+
"""
321+
inbinding_obj.position = position_el
322+
323+
def _load_prefix(self, inbinding_obj, prefix_el):
324+
"""
325+
Load the content of prefix into the input object.
326+
327+
:param inbinding_obj: input_binding object
328+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
329+
:param prefix_el: Content of loadContents
330+
:loadContents prefix_el: STRING
331+
"""
332+
inbinding_obj.prefix = prefix_el
333+
334+
def _load_separate(self, inbinding_obj, separate_el):
335+
"""
336+
Load the content of separate into the input object.
337+
338+
:param inbinding_obj: input_binding object
339+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
340+
:param separate_el: Content of loadContents
341+
:loadContents separate_el: BOOLEAN
342+
"""
343+
inbinding_obj.separate = separate_el
344+
345+
def _load_itemSeparator(self, inbinding_obj, itemsep_el):
346+
"""
347+
Load the content of itemSeparator into the input object.
348+
349+
:param inbinding_obj: input_binding object
350+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
351+
:param itemsep_el: Content of loadContents
352+
:loadContents itemsep_el: STRING
353+
"""
354+
inbinding_obj.item_separator = itemsep_el
355+
356+
def _load_valueFrom(self, inbinding_obj, valuefrom_el):
357+
"""
358+
Load the content of valueFrom into the input object.
359+
360+
:param inbinding_obj: input_binding object
361+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
362+
:param valuefrom_el: Content of loadContents
363+
:loadContents valuefrom_el: STRING
364+
"""
365+
inbinding_obj.value_from = valuefrom_el
366+
367+
def _load_shellQuote(self, inbinding_obj, shellquote_el):
368+
"""
369+
Load the content of shellQuote into the input object.
370+
371+
:param inbinding_obj: input_binding object
372+
:loadContents inbinding_obj: : :class:`cwlgen.CommandLineBinding`
373+
:param shellquote_el: Content of loadContents
374+
:loadContents shellquote_el: BOOLEAN
375+
"""
376+
inbinding_obj.shell_quote = shellquote_el
377+
378+
def load_inbinding(self, input_obj, inbinding_el):
379+
"""
380+
Load the content of inputBinding into the input object.
381+
382+
:param input_obj: input object
383+
:type input_obj: :class:`cwlgen.CommandInputParameter`
384+
:param inbinding_el: Content of inputs
385+
:type inbinding_el: DICT
386+
"""
387+
inbinding_obj = cwlgen.CommandLineBinding()
388+
for key, value in inbinding_el.items():
389+
try:
390+
getattr(self, '_load_{}'.format(key))(inbinding_obj, value)
391+
except AttributeError:
392+
logger.warning(key + " content for inputBinding is not processed (yet).")
393+
input_obj.input_binding = inbinding_obj
394+
395+
206396
class OutputsParser(object):
207397
"""
208398
Class to parse content of outputs from an existing CWL Tool.
209399
"""
210400

401+
def _load_label(self, output_obj, label_el):
402+
"""
403+
Load the content of type into the output object.
404+
405+
:param output_obj: output obj
406+
:type output_obj: : :class:`cwlgen.CommandInputParameter`
407+
:param label_el: Content of label
408+
:type label_el: STRING
409+
"""
410+
output_obj.label = label_el
411+
412+
def _load_secondaryFiles(self, output_obj, secfile_el):
413+
"""
414+
Load the content of secondaryFiles into the output object.
415+
416+
:param output_obj: output obj
417+
:type output_obj: : :class:`cwlgen.CommandInputParameter`
418+
:param secfile_el: Content of secondaryFile
419+
:type secfile_el: STRING
420+
"""
421+
output_obj.secondary_file = secfile_el
422+
423+
def _load_format(self, output_obj, format_el):
424+
"""
425+
Load the content of format into the output object.
426+
427+
:param output_obj: output obj
428+
:type output_obj: : :class:`cwlgen.CommandInputParameter`
429+
:param format_el: Content of format
430+
:type format_el: STRING
431+
"""
432+
output_obj.format = format_el
433+
434+
def _load_streamable(self, output_obj, stream_el):
435+
"""
436+
Load the content of streamable into the output object.
437+
438+
:param output_obj: output obj
439+
:type output_obj: : :class:`cwlgen.CommandInputParameter`
440+
:param stream_el: Content of streamable
441+
:type type_el: BOOLEAN
442+
"""
443+
output_obj.streamable = stream_el
444+
445+
def _load_doc(self, output_obj, doc_el):
446+
"""
447+
Load the content of doc into the output object.
448+
449+
:param output_obj: output obj
450+
:type output_obj: : :class:`cwlgen.CommandInputParameter`
451+
:param doc_el: Content of doc
452+
:type doc_el: STRING
453+
"""
454+
output_obj.doc = doc_el
455+
456+
def _load_outputBinding(self, output_obj, inpb_el):
457+
pass
458+
459+
def _load_type(self, output_obj, type_el):
460+
"""
461+
Load the content of type into the output object.
462+
463+
:param output_obj: output obj
464+
:type output_obj: : :class:`cwlgen.CommandInputParameter`
465+
:param type_el: Content of type
466+
:type type_el: STRING
467+
"""
468+
output_obj.type = type_el
469+
211470
def load_outputs(self, outputs, outputs_el):
212471
"""
213472
Load the content of outputs into the outputs list.

test/import_cwl.cwl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,28 @@ doc: "super_doc"
99
stdin: "in"
1010
stderr: "err"
1111
stdout: "out"
12+
inputs:
13+
INPUT1:
14+
label: label_in
15+
secondaryFiles: 'sec_file_in'
16+
format: format_1930
17+
streamable: True
18+
default: 'def_in'
19+
doc: 'documentation_in'
20+
inputBinding:
21+
loadContents: True
22+
position: 0
23+
prefix: --input
24+
separate: True
25+
itemSeparator: ';'
26+
valueFrom: here
27+
shellQuote: True
28+
type: File
29+
outputs:
30+
OUTPUT1:
31+
label: label_out
32+
secondaryFiles: 'sec_file_out'
33+
format: format_1930
34+
streamable: True
35+
doc: 'documentation_out'
36+
type: File

0 commit comments

Comments
 (0)
0