Skip to content

Commit

Permalink
Parameter models for optional data columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Aug 10, 2024
1 parent baee7f1 commit fcb0ebd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/galaxy/tool_util/parameters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ def _from_input_source_galaxy(input_source: InputSource) -> ToolParameterT:
)
elif param_type == "data_column":
multiple = input_source.get_bool("multiple", False)
optional = input_source.parse_optional()
return DataColumnParameterModel(
name=input_source.parse_name(),
multiple=multiple,
optional=optional,
)
elif param_type == "group_tag":
multiple = input_source.get_bool("multiple", False)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,14 @@ def py_type(self) -> Type:
py_type: Type = StrictInt
if self.multiple:
py_type = list_type(py_type)
return py_type
return optional_if_needed(py_type, self.optional)

def pydantic_template(self, state_representation: StateRepresentationT) -> DynamicModelInformation:
return dynamic_model_information_from_py_type(self, self.py_type)

@property
def request_requires_value(self) -> bool:
return False
return self.multiple and not self.optional


class GroupTagParameterModel(BaseGalaxyToolParameterModelDefinition):
Expand Down
28 changes: 28 additions & 0 deletions test/functional/tools/parameters/gx_data_column_optional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<tool id="gx_data_column_optional" name="gx_data_column_optional" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo 'parameter: $parameter' >> '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data" format="tabular" />
<param name="parameter" type="data_column" data_ref="ref_parameter" optional="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1" />
<expand macro="assert_output">
<has_line line="parameter: 1"/>
</expand>
</test>
<test>
<param name="ref_parameter" value="2.tabular" />
<expand macro="assert_output">
<has_line line="parameter: None"/>
</expand>
</test>
</tests>
</tool>
14 changes: 14 additions & 0 deletions test/unit/tool_util/parameter_specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,20 @@ gx_data_column:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: 0 }
request_invalid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: "0" }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: [ 0 ] }
request_internal_valid:
- { ref_parameter: {src: hda, id: 123}, parameter: 0 }
request_internal_invalid:
- { ref_parameter: {src: hda, id: 123}, parameter: "0" }

gx_data_column_optional:
request_valid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: 0 }
- { ref_parameter: {src: hda, id: abcdabcd} }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: null }
request_invalid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: "0" }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: [ 0 ] }
request_internal_valid:
- { ref_parameter: {src: hda, id: 123}, parameter: 0 }
request_internal_invalid:
Expand Down

0 comments on commit fcb0ebd

Please sign in to comment.