Skip to content

Commit c9dd7e4

Browse files
authored
Merge pull request #104 from hmenager/enum_impl
implement enum type in cwltool this is, among other things, a fix to #101
2 parents 6dab84b + 332196a commit c9dd7e4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

cwltool/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ def generate_parser(toolparser, tool, namemap):
287287
action = cast(argparse.Action, FileAppendAction)
288288
else:
289289
action = "append"
290-
290+
elif isinstance(inptype, dict) and inptype["type"] == "enum":
291+
atype = str
291292
if inptype == "string":
292293
atype = str
293294
elif inptype == "int":

cwltool/process.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,22 @@ def fillInDefaults(inputs, job):
223223
else:
224224
raise validate.ValidationException("Missing input parameter `%s`" % shortname(inp["id"]))
225225

226+
227+
def avroize_type(field_type, name_prefix=""):
228+
"""
229+
adds missing information to a type so that CWL types are valid in schema_salad.
230+
"""
231+
if type(field_type) == list:
232+
field_type_result = []
233+
for idx, field_type_item in enumerate(field_type):
234+
field_type_result.append(avroize_type(field_type_item, name_prefix+"_"+str(idx)))
235+
return field_type_result
236+
elif type(field_type) == dict and "type" in field_type and field_type["type"] == "enum":
237+
if "name" not in field_type:
238+
field_type["name"] = name_prefix+"_type_enum"
239+
return field_type
240+
241+
226242
class Process(object):
227243
__metaclass__ = abc.ABCMeta
228244

@@ -252,7 +268,7 @@ def __init__(self, toolpath_object, **kwargs):
252268

253269
if sd:
254270
sdtypes = sd["types"]
255-
av = schema_salad.schema.make_valid_avro(sdtypes, {t["name"]: t for t in sdtypes}, set())
271+
av = schema_salad.schema.make_valid_avro(sdtypes, {t["name"]: t for t in avroize_type(sdtypes)}, set())
256272
for i in av:
257273
self.schemaDefs[i["name"]] = i
258274
avro.schema.make_avsc_object(av, self.names)
@@ -278,7 +294,7 @@ def __init__(self, toolpath_object, **kwargs):
278294
c["type"] = ["null"] + aslist(c["type"])
279295
else:
280296
c["type"] = c["type"]
281-
297+
c["type"] = avroize_type(c["type"],c["name"])
282298
if key == "inputs":
283299
self.inputs_record_schema["fields"].append(c) # type: ignore
284300
elif key == "outputs":

0 commit comments

Comments
 (0)