Skip to content

Commit

Permalink
Merge pull request galaxyproject#16966 from nsoranzo/issue_16960
Browse files Browse the repository at this point in the history
Allow non-optional integer/float params without value attribute
  • Loading branch information
dannon authored Nov 3, 2023
2 parents aa1702d + 1e86672 commit 0db0444
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(self, tool, input_source, context=None):
self.validators.append(validation.Validator.from_element(self, elem))

@property
def visible(self):
def visible(self) -> bool:
"""Return true if the parameter should be rendered on the form"""
return True

Expand Down Expand Up @@ -219,7 +219,7 @@ def get_dependencies(self):
"""
return []

def to_json(self, value, app, use_security):
def to_json(self, value, app, use_security) -> str:
"""Convert a value to a string representation suitable for persisting"""
return unicodify(value)

Expand Down Expand Up @@ -249,12 +249,12 @@ def value_from_basic(self, value, app, ignore_errors=False):
else:
return self.to_python(value, app)

def value_to_display_text(self, value):
def value_to_display_text(self, value) -> str:
if is_runtime_value(value):
return "Not available."
return self.to_text(value)

def to_text(self, value):
def to_text(self, value) -> str:
"""
Convert a value to a text representation suitable for displaying to
the user
Expand Down Expand Up @@ -292,7 +292,7 @@ def to_param_dict_string(self, value, other_values=None) -> str:
value = sanitize_param(value)
return value

def validate(self, value, trans=None):
def validate(self, value, trans=None) -> None:
if value in ["", None] and self.optional:
return
for validator in self.validators:
Expand Down Expand Up @@ -435,8 +435,6 @@ def __init__(self, tool, input_source):
int(self.value)
except ValueError:
raise ParameterValueError("the attribute 'value' must be an integer", self.name)
elif self.value is None and not self.optional:
raise ParameterValueError("the attribute 'value' must be set for non optional parameters", self.name, None)
self.min = input_source.get("min")
self.max = input_source.get("max")
if self.min:
Expand Down Expand Up @@ -511,8 +509,6 @@ def __init__(self, tool, input_source):
float(self.value)
except ValueError:
raise ParameterValueError("the attribute 'value' must be a real number", self.name, self.value)
elif self.value is None and not self.optional:
raise ParameterValueError("the attribute 'value' must be set for non optional parameters", self.name, None)
if self.min:
try:
self.min = float(self.min)
Expand Down Expand Up @@ -1317,7 +1313,7 @@ def get_options(self, trans, other_values):
def get_initial_value(self, trans, other_values):
if self.default_value is not None:
return self.default_value
return SelectToolParameter.get_initial_value(self, trans, other_values)
return super().get_initial_value(trans, other_values)

def get_legal_values(self, trans, other_values, value):
if self.data_ref not in other_values and not trans.workflow_building_mode:
Expand Down Expand Up @@ -2606,7 +2602,7 @@ class DirectoryUriToolParameter(SimpleTextToolParameter):

def __init__(self, tool, input_source, context=None):
input_source = ensure_input_source(input_source)
SimpleTextToolParameter.__init__(self, tool, input_source)
super().__init__(tool, input_source)

def validate(self, value, trans=None):
super().validate(value, trans=trans)
Expand All @@ -2629,7 +2625,7 @@ class RulesListToolParameter(BaseJsonToolParameter):

def __init__(self, tool, input_source, context=None):
input_source = ensure_input_source(input_source)
BaseJsonToolParameter.__init__(self, tool, input_source)
super().__init__(tool, input_source)
self.data_ref = input_source.get("data_ref", None)

def to_dict(self, trans, other_values=None):
Expand Down
33 changes: 33 additions & 0 deletions test/functional/tools/integer_default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<tool id="integer_default" name="Test integer default" version="0.1.0">
<command><![CDATA[
echo ${int($input1) + int($input2) + int($input3)} > '$out_file1'
]]></command>
<inputs>
<param name="input1" type="integer" value="0" label="Integer with default 0" />
<param name="input2" type="integer" value="" label="Integer with default empty string" />
<!-- Not needed any more to have `value=""` when there is no good default -->
<param name="input3" type="integer" label="Integer with no default value" />
</inputs>
<outputs>
<data name="out_file1" format="txt"/>
</outputs>
<tests>
<test>
<param name="input1" value="1" />
<param name="input2" value="2" />
<param name="input3" value="3" />
<output name="out_file1">
<assert_contents>
<has_line line="6" />
</assert_contents>
</output>
</test>
<!-- Test that it fails if a non-optional integer param is not set -->
<test expect_failure="true">
<param name="input1" value="1" />
<param name="input2" value="2" />
</test>
</tests>
<help>
</help>
</tool>
1 change: 1 addition & 0 deletions test/functional/tools/sample_tool_conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<tool file="config_vars.xml" />
<tool file="expect_num_outputs.xml" />
<tool file="text_repeat.xml" />
<tool file="integer_default.xml" />

<tool file="multiple_versions_v01.xml" />
<tool file="multiple_versions_v01galaxy6.xml" />
Expand Down

0 comments on commit 0db0444

Please sign in to comment.