Skip to content

implement enum type in cwltool #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ def generate_parser(toolparser, tool, namemap):
action = cast(argparse.Action, FileAppendAction)
else:
action = "append"

elif isinstance(inptype, dict) and inptype["type"] == "enum":
atype = str
if inptype == "string":
atype = str
elif inptype == "int":
Expand Down
20 changes: 18 additions & 2 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ def fillInDefaults(inputs, job):
else:
raise validate.ValidationException("Missing input parameter `%s`" % shortname(inp["id"]))


def avroize_type(field_type, name_prefix=""):
"""
adds missing information to a type so that CWL types are valid in schema_salad.
"""
if type(field_type) == list:
field_type_result = []
for idx, field_type_item in enumerate(field_type):
field_type_result.append(avroize_type(field_type_item, name_prefix+"_"+str(idx)))
return field_type_result
elif type(field_type) == dict and "type" in field_type and field_type["type"] == "enum":
if "name" not in field_type:
field_type["name"] = name_prefix+"_type_enum"
return field_type


class Process(object):
__metaclass__ = abc.ABCMeta

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

if sd:
sdtypes = sd["types"]
av = schema_salad.schema.make_valid_avro(sdtypes, {t["name"]: t for t in sdtypes}, set())
av = schema_salad.schema.make_valid_avro(sdtypes, {t["name"]: t for t in avroize_type(sdtypes)}, set())
for i in av:
self.schemaDefs[i["name"]] = i
avro.schema.make_avsc_object(av, self.names)
Expand All @@ -278,7 +294,7 @@ def __init__(self, toolpath_object, **kwargs):
c["type"] = ["null"] + aslist(c["type"])
else:
c["type"] = c["type"]

c["type"] = avroize_type(c["type"],c["name"])
if key == "inputs":
self.inputs_record_schema["fields"].append(c) # type: ignore
elif key == "outputs":
Expand Down