Skip to content

Commit aabfa17

Browse files
make optional multiple data paramaters [] in case nothing is selected
instead of [None]
1 parent c87ef79 commit aabfa17

File tree

6 files changed

+38
-47
lines changed

6 files changed

+38
-47
lines changed

lib/galaxy/tool_util/xsd/galaxy.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ List of behavior changes associated with profile versions:
7878
7979
### 26.0
8080
81-
- The ``len`` function applied on optional data parameters without a selected dataset gives ``0``. For smaller profiles ``1``
81+
- Optional data parameters without a selected dataset are now empty lists, i.e. ``[]``. For smaller profiles it was ``[None]``
8282
8383
### Examples
8484

lib/galaxy/tools/evaluation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,8 @@ def __populate_wrappers(self, param_dict, input_datasets, job_working_directory)
466466
def wrap_input(input_values, input):
467467
value = input_values[input.name]
468468
if isinstance(input, DataToolParameter) and input.multiple:
469-
dataset_instances = DatasetListWrapper.to_dataset_instances(value)
469+
dataset_instances = DatasetListWrapper.to_dataset_instances(value, self.tool.profile)
470470
input_values[input.name] = DatasetListWrapper(
471-
input,
472471
job_working_directory,
473472
dataset_instances,
474473
compute_environment=self.compute_environment,

lib/galaxy/tools/parameters/wrapped.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ def wrap_values(self, inputs: "ToolInputsT", input_values: dict, skip_missing_va
118118
values = value
119119
self.wrap_values(input.inputs, values, skip_missing_values=skip_missing_values)
120120
elif isinstance(input, DataToolParameter) and input.multiple:
121-
dataset_instances = DatasetListWrapper.to_dataset_instances(value)
121+
dataset_instances = DatasetListWrapper.to_dataset_instances(value, self.tool.profile)
122122
input_values[input.name] = DatasetListWrapper(
123-
input,
124123
None,
125124
dataset_instances,
126125
datatypes_registry=trans.app.datatypes_registry,

lib/galaxy/tools/wrappers.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
from galaxy.tools import Tool
5757
from galaxy.tools.evaluation import ToolEvaluator
5858
from galaxy.tools.parameters.basic import (
59-
DataToolParameter,
6059
SelectToolParameter,
6160
ToolParameter,
6261
)
@@ -560,7 +559,6 @@ class DatasetListWrapper(list[DatasetFilenameWrapper], ToolParameterValueWrapper
560559

561560
def __init__(
562561
self,
563-
input: "DataToolParameter",
564562
job_working_directory: Optional[str],
565563
datasets: Union[
566564
Sequence[
@@ -575,7 +573,6 @@ def __init__(
575573
],
576574
**kwargs: Any,
577575
) -> None:
578-
self.input = input
579576
self._dataset_elements_cache: dict[str, list[DatasetFilenameWrapper]] = {}
580577
if not isinstance(datasets, Sequence):
581578
datasets = [datasets]
@@ -601,13 +598,15 @@ def to_wrapper(
601598
@staticmethod
602599
def to_dataset_instances(
603600
dataset_instance_sources: Any,
601+
profile: Optional[float],
604602
) -> list[Union[None, DatasetInstance]]:
605603
dataset_instances: list[Optional[DatasetInstance]] = []
606604
if not isinstance(dataset_instance_sources, list):
607605
dataset_instance_sources = [dataset_instance_sources]
608606
for dataset_instance_source in dataset_instance_sources:
609607
if dataset_instance_source is None:
610-
dataset_instances.append(dataset_instance_source)
608+
if profile is None or Version(str(profile)) < Version("26.0"):
609+
dataset_instances.append(dataset_instance_source)
611610
elif getattr(dataset_instance_source, "history_content_type", None) == "dataset":
612611
dataset_instances.append(dataset_instance_source)
613612
elif getattr(dataset_instance_source, "hda", None):
@@ -638,15 +637,6 @@ def __bool__(self) -> bool:
638637
# Fail `#if $param` checks in cheetah if optional input is not provided
639638
return any(self)
640639

641-
def __len__(self) -> int:
642-
# optional data parameters are [None] if no input is given
643-
# note: not self relies on the __bool__ method
644-
profile = self.input.tool.profile if self.input.tool else None
645-
if not self and profile is not None and Version(str(profile)) >= Version("26.0"):
646-
return 0
647-
else:
648-
return super().__len__()
649-
650640
__nonzero__ = __bool__
651641

652642

@@ -849,11 +839,6 @@ def __iter__(
849839
return [].__iter__()
850840
return self.__element_instance_list.__iter__()
851841

852-
# def __len__(self) -> int:
853-
# if not self.__input_supplied:
854-
# return 0
855-
# return self.__element_instance_list.__len__()
856-
857842
def __bool__(self) -> bool:
858843
# Fail `#if $param` checks in cheetah is optional input
859844
# not specified or if resulting collection is empty.

test/functional/tools/multi_len.xml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<tool id="multi_select" name="multi_select" version="1.0.0" profile="26.0">
22
<description>test len() parameters allowing multiple</description>
33
<command><![CDATA[
4-
echo 'select_ex #echo len($select_ex) #' > '$output' &&
5-
echo 'select_ex_optional #echo len($select_ex_optional) #' >> '$output' &&
4+
echo '|select_ex| = #echo len($select_ex) #' > '$output' &&
5+
echo '|select_ex_optional| = #echo len($select_ex_optional) #' >> '$output' &&
66
7-
echo 'data_ex #echo len($data_ex) #' >> '$output' &&
8-
echo 'data_ex_optional #echo len($data_ex_optional) #' >> '$output'
7+
echo '|data_ex| = #echo len($data_ex) #' >> '$output' &&
8+
echo '|data_ex_optional| = #echo len($data_ex_optional) #' >> '$output'
99
10+
#for i, e in enumerate($data_ex_optional)
11+
&& echo "data_ex_optional element $i is $e"
12+
#end for
1013
]]></command>
1114
<inputs>
1215
<param name="select_ex" type="select" multiple="true">
@@ -37,10 +40,10 @@ echo 'data_ex_optional #echo len($data_ex_optional) #' >> '$output'
3740
<param name="data_ex_optional" value="1.tabular,2.tabular"/>
3841
<output name="output">
3942
<assert_contents>
40-
<has_line line="select_ex 3" />
41-
<has_line line="select_ex_optional 3" />
42-
<has_line line="data_ex 2" />
43-
<has_line line="data_ex_optional 2" />
43+
<has_line line="|select_ex| = 3" />
44+
<has_line line="|select_ex_optional| = 3" />
45+
<has_line line="|data_ex| = 2" />
46+
<has_line line="|data_ex_optional| = 2" />
4447
</assert_contents>
4548
</output>
4649
</test>
@@ -51,10 +54,11 @@ echo 'data_ex_optional #echo len($data_ex_optional) #' >> '$output'
5154
<param name="data_ex_optional" value_json="null"/>
5255
<output name="output">
5356
<assert_contents>
54-
<has_line line="select_ex 3" />
55-
<has_line line="select_ex_optional 0" />
56-
<has_line line="data_ex 2" />
57-
<has_line line="data_ex_optional 0" />
57+
<has_line line="|select_ex| = 3" />
58+
<has_line line="|select_ex_optional| = 0" />
59+
<has_line line="|data_ex| = 2" />
60+
<has_line line="|data_ex_optional| = 0" />
61+
<has_line_matching expression="^data_ex_optional: element" negate="true" />
5862
</assert_contents>
5963
</output>
6064
</test>

test/functional/tools/multi_len_legacy.xml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<tool id="multi_select" name="multi_select" version="1.0.0" profile="25.1">
22
<description>test len() parameters allowing multiple for 25.1</description>
33
<command><![CDATA[
4-
echo 'select_ex #echo len($select_ex) #' > '$output' &&
5-
echo 'select_ex_optional #echo len($select_ex_optional) #' >> '$output' &&
4+
echo '|select_ex| = #echo len($select_ex) #' > '$output' &&
5+
echo '|select_ex_optional| = #echo len($select_ex_optional) #' >> '$output' &&
66
7-
echo 'data_ex #echo len($data_ex) #' >> '$output' &&
8-
echo 'data_ex_optional #echo len($data_ex_optional) #' >> '$output'
7+
echo '|data_ex| = #echo len($data_ex) #' >> '$output' &&
8+
echo '|data_ex_optional| = #echo len($data_ex_optional) #' >> '$output'
9+
#for i, e in enumerate($data_ex_optional)
10+
&& echo "data_ex_optional: element $i is $e"
11+
#end for
912
1013
]]></command>
1114
<inputs>
@@ -37,10 +40,10 @@ echo 'data_ex_optional #echo len($data_ex_optional) #' >> '$output'
3740
<param name="data_ex_optional" value="1.tabular,2.tabular"/>
3841
<output name="output">
3942
<assert_contents>
40-
<has_line line="select_ex 3" />
41-
<has_line line="select_ex_optional 3" />
42-
<has_line line="data_ex 2" />
43-
<has_line line="data_ex_optional 2" />
43+
<has_line line="|select_ex| = 3" />
44+
<has_line line="|select_ex_optional| = 3" />
45+
<has_line line="|data_ex| = 2" />
46+
<has_line line="|data_ex_optional| = 2" />
4447
</assert_contents>
4548
</output>
4649
</test>
@@ -51,10 +54,11 @@ echo 'data_ex_optional #echo len($data_ex_optional) #' >> '$output'
5154
<param name="data_ex_optional" value_json="null"/>
5255
<output name="output">
5356
<assert_contents>
54-
<has_line line="select_ex 3" />
55-
<has_line line="select_ex_optional 0" />
56-
<has_line line="data_ex 2" />
57-
<has_line line="data_ex_optional 1" /> <!-- profile behavior giving the length of [None] -->
57+
<has_line line="|select_ex| = 3" />
58+
<has_line line="|select_ex_optional| = 0" />
59+
<has_line line="|data_ex| = 2" />
60+
<has_line line="|data_ex_optional| = 1" /> <!-- profile behavior giving the length of [None] -->
61+
<has_line line="data_ex_optional: element 0 is None"/>
5862
</assert_contents>
5963
</output>
6064
</test>

0 commit comments

Comments
 (0)