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

Commit 52df2b3

Browse files
authored
Merge pull request #17 from illusional/fix-base-command
Ensures base command is exported if it's a list
2 parents 7123c2a + 02a2632 commit 52df2b3

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

cwlgen/__init__.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, tool_id=None, base_command=None, label=None, doc=None,
3939
:param tool_id: unique identifier for this tool
4040
:type tool_id: STRING
4141
:param base_command: command line for the tool
42-
:type base_command: STRING
42+
:type base_command: STRING | list[STRING]
4343
:param label: label of this tool
4444
:type label: STRING
4545
:param doc: documentation for the tool, usually longer than the label
@@ -82,19 +82,17 @@ def __init__(self, tool_id=None, base_command=None, label=None, doc=None,
8282
self._path = path
8383
self.namespaces = Namespaces()
8484

85-
def export(self, outfile=None):
86-
"""
87-
Export the tool in CWL either on STDOUT or in outfile.
88-
"""
89-
# First add representer (see .utils.py) for multiline writting
90-
ruamel.yaml.add_representer(literal, literal_presenter)
85+
def get_dict(self):
9186
cwl_tool = {k: v for k, v in vars(self).items() if v is not None and
9287
type(v) is str}
9388
cwl_tool['class'] = self.__CLASS__
9489
# Treat doc for multiline writting
9590
if self.doc:
9691
cwl_tool['doc'] = literal(self.doc)
9792

93+
if self.baseCommand:
94+
cwl_tool['baseCommand'] = self.baseCommand
95+
9896
# Add Arguments
9997
cwl_tool['arguments'] = [in_arg.get_dict() for in_arg in self.arguments]
10098

@@ -108,6 +106,13 @@ def export(self, outfile=None):
108106
for out_param in self.outputs:
109107
cwl_tool['outputs'][out_param.id] = out_param.get_dict()
110108

109+
if self.successCodes:
110+
cwl_tool['successCodes'] = self.successCodes
111+
if self.temporaryFailCodes:
112+
cwl_tool['temporaryFailCodes'] = self.temporaryFailCodes
113+
if self.permanentFailCodes:
114+
cwl_tool['permanentFailCodes'] = self.permanentFailCodes
115+
111116
# If metadata are present in the description
112117
if getattr(self, 'metadata', None):
113118
for key, value in self.metadata.__dict__.items():
@@ -125,6 +130,15 @@ def export(self, outfile=None):
125130

126131
if requirements:
127132
cwl_tool['requirements'] = requirements
133+
return cwl_tool
134+
135+
def export(self, outfile=None):
136+
"""
137+
Export the tool in CWL either on STDOUT or in outfile.
138+
"""
139+
# First add representer (see .utils.py) for multiline writting
140+
ruamel.yaml.add_representer(literal, literal_presenter)
141+
cwl_tool = self.get_dict()
128142

129143
# Write CWL file in YAML
130144
if outfile is None:

test/test_unit_cwlgen.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def setUp(self):
2222
self.cwl = cwlgen.CommandLineTool(tool_id='an_id', label='a description '+\
2323
'with spaces.', base_command='a_command')
2424

25+
self.array_basecommand = cwlgen.CommandLineTool(tool_id="base-command-array", base_command=["base", "command"])
26+
2527
def test_init(self):
2628
self.assertEqual(self.cwl.id, 'an_id')
2729
self.assertEqual(self.cwl.label, 'a description with spaces.')
@@ -30,6 +32,23 @@ def test_init(self):
3032
self.assertListEqual(self.cwl.outputs, [])
3133
self.assertIsNone(self.cwl.doc)
3234

35+
def test_array_basecommand(self):
36+
dict_test = self.array_basecommand.get_dict()
37+
self.assertIn('baseCommand', dict_test)
38+
39+
def test_codes(self):
40+
code_tool = cwlgen.CommandLineTool()
41+
code_tool.permanentFailCodes.extend([400, 401, 500])
42+
code_tool.temporaryFailCodes.append(408)
43+
code_tool.successCodes = [] # empty (falsy)
44+
45+
dict_test = code_tool.get_dict()
46+
self.assertIn('permanentFailCodes', dict_test)
47+
self.assertEqual(len(dict_test['permanentFailCodes']), 3)
48+
self.assertIn('temporaryFailCodes', dict_test)
49+
self.assertEqual(len(dict_test['temporaryFailCodes']), 1)
50+
self.assertNotIn('successCodes', dict_test)
51+
3352
"""
3453
def test_export(self):
3554
tmp_file = 'test_export.tmp'

0 commit comments

Comments
 (0)