Skip to content

Commit 767f148

Browse files
ommit optional if default
1 parent fb5a6c5 commit 767f148

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

ctdconverter/galaxy/converter.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,6 @@ def create_inputs(tool, model, **kwargs):
10631063
fmt_select_attrib = OrderedDict([
10641064
("name", param.name + "_type"),
10651065
("type", "select"),
1066-
("optional", "false"),
10671066
("label", f"File type of output {param.name} ({param.description})")
10681067
])
10691068
fmt_select = add_child_node(parent_node, "param", fmt_select_attrib)
@@ -1241,11 +1240,21 @@ def create_param_attribute_list(param, model, supported_file_formats, parameter_
12411240
optional = False
12421241
else:
12431242
optional = not param.required
1244-
param_node.attrib["optional"] = str(optional).lower()
12451243

1246-
if is_selection_parameter(param):
1247-
if param.is_list:
1248-
param_node.attrib["multiple"] = "true"
1244+
# set multiple for select parameters if needed
1245+
# also set optional if it's not the default
1246+
# - for select with multiple=true optional defaults to true, i.e. we set it if the parameter is not optional
1247+
# - never set it for bool
1248+
# - otherwise the default is false, i.e. we set the attribute if the parameter is optional
1249+
if is_selection_parameter(param) and param.is_list:
1250+
param_node.attrib["multiple"] = "true"
1251+
if not optional:
1252+
param_node.attrib["optional"] = str(optional).lower()
1253+
if param_type == "boolean":
1254+
pass
1255+
else:
1256+
if optional:
1257+
param_node.attrib["optional"] = str(optional).lower()
12491258

12501259
# check for parameters with restricted values (which will correspond to a "select" in galaxy)
12511260
if param.restrictions is not None or param_type == "boolean":
@@ -1278,8 +1287,8 @@ def create_param_attribute_list(param, model, supported_file_formats, parameter_
12781287
if is_default(choice, param):
12791288
option_node.attrib["selected"] = "true"
12801289

1281-
# add validator to check that "nothing selected" is not seletcedto mandatory options w/o default
1282-
if param_node.attrib["optional"] == "False" and (param.default is None or type(param.default) is _Null):
1290+
# add validator to check that "nothing selected" is not seleted to mandatory options w/o default
1291+
if param_node.attrib.get("optional", "false") in ["false", "False"] and (param.default is None or type(param.default) is _Null):
12831292
validator_node = add_child_node(param_node, "validator", OrderedDict([("type", "expression"), ("message", "A value needs to be selected")]))
12841293
validator_node.text = 'value != "select a value"'
12851294

@@ -1412,7 +1421,7 @@ def create_param_attribute_list(param, model, supported_file_formats, parameter_
14121421
when_no = add_child_node(conditional, "when", attributes={"value": "no"})
14131422
when_no.append(copy.deepcopy(param_node))
14141423
when_yes = add_child_node(conditional, "when", attributes={"value": "yes"})
1415-
param_node.attrib["multiple"] = "false"
1424+
del param_node.attrib["multiple"]
14161425
when_yes.append(param_node)
14171426
return conditional
14181427

0 commit comments

Comments
 (0)