Merge pull request #13094 from bernt-matthias/topic/duplicated_option

Allow duplicated static options
This commit is contained in:
Marius van den Beek
2022-01-14 19:34:14 +01:00
committed by GitHub
4 changed files with 59 additions and 7 deletions
+13 -3
View File
@@ -77,7 +77,6 @@ def lint_inputs(tool_xml, lint_ctx):
options = param.findall("./options")
filters = param.findall("./options/filter")
select_options = param.findall('./option')
select_options_text = [option.text.strip() if option.text is not None else option.attrib.get("value", "").capitalize() for option in select_options]
if dynamic_options is not None:
lint_ctx.warn(f"Select parameter [{param_name}] uses deprecated 'dynamic_options' attribute.")
@@ -137,9 +136,20 @@ def lint_inputs(tool_xml, lint_ctx):
lint_ctx.error(f"Select parameter [{param_name}] has option without value")
if any(option.text is None for option in select_options):
lint_ctx.warn(f"Select parameter [{param_name}] has option without text")
if len(set(select_options_text)) != len(select_options_text):
select_options_texts = list()
select_options_values = list()
for option in select_options:
value = option.attrib.get("value", "")
if option.text is None:
text = value.capitalize()
else:
text = option.text
select_options_texts.append((text, option.attrib.get("selected", "false")))
select_options_values.append((value, option.attrib.get("selected", "false")))
if len(set(select_options_texts)) != len(select_options_texts):
lint_ctx.error(f"Select parameter [{param_name}] has multiple options with the same text content")
if len({option.attrib.get("value") for option in select_options}) != len(select_options):
if len(set(select_options_values)) != len(select_options_values):
lint_ctx.error(f"Select parameter [{param_name}] has multiple options with the same value")
multiple = string_as_bool(param_attrib.get("multiple", "false"))
+20 -1
View File
@@ -1124,12 +1124,31 @@ class XmlInputSource(InputSource):
return options_elem
def parse_static_options(self):
"""
>>> from galaxy.util import parse_xml_string_to_etree
>>> xml = '<param><option value="a">A</option><option value="b">B</option></param>'
>>> xis = XmlInputSource(parse_xml_string_to_etree(xml).getroot())
>>> xis.parse_static_options()
[('A', 'a', False), ('B', 'b', False)]
>>> xml = '<param><option value="a"/><option value="b"/><option value="a" selected="true"/></param>'
>>> xis = XmlInputSource(parse_xml_string_to_etree(xml).getroot())
>>> xis.parse_static_options()
[('a', 'a', True), ('b', 'b', False)]
"""
static_options = list()
elem = self.input_elem
for option in elem.findall("option"):
value = option.get("value")
text = option.text or value
selected = string_as_bool(option.get("selected", False))
static_options.append((option.text or value, value, selected))
present = False
for i, o in enumerate(static_options):
if o[1] == value:
present = True
static_options[i] = (text, value, selected)
break
if not present:
static_options.append((text, value, selected))
return static_options
def parse_optional(self, default=None):
+9 -3
View File
@@ -3372,17 +3372,23 @@ value is ``select`` (i.e. ``<param type="select" ...>``).
```
An option can also be annotated with ``selected="true"`` to specify a
default option.
default option (note that the first option is selected automatically
if ``optional="false"``).
```xml
<param name="col" type="select" label="From">
<option value="0" selected="true">Column 1 / Sequence name</option>
<option value="1">Column 2 / Source</option>
<option value="0">Column 1 / Sequence name</option>
<option value="1" selected="true">Column 2 / Source</option>
<option value="2">Column 3 / Feature</option>
<option value="6">Column 7 / Strand</option>
<option value="7">Column 8 / Frame</option>
</param>
```
In general the values and the texts for the options need to be unique,
but it is possible to specify an option two times if the 2nd has a different
value for the ``selected`` attribute. This is handy if an option list is
defined in a macro and different default value(s) are used.
]]>
</xs:documentation>
</xs:annotation>
+17
View File
@@ -107,6 +107,17 @@ SELECT_DUPLICATED_OPTIONS = """
</tool>
"""
SELECT_DUPLICATED_OPTIONS_WITH_DIFF_SELECTED = """
<tool>
<inputs>
<param name="select" type="select" optional="true" multiple="true">
<option value="v">x</option>
<option value="v" selected="true">x</option>
</param>
</inputs>
</tool>
"""
SELECT_DEPRECATIONS = """
<tool name="BWA Mapper" id="bwa" version="1.0.1" display_interface="true" require_login="true" hidden="true">
<description>The BWA Mapper</description>
@@ -331,6 +342,11 @@ TESTS = [
and 'Select parameter [select] has multiple options with the same value' in x.error_messages
and len(x.warn_messages) == 0 and len(x.error_messages) == 2
),
(
SELECT_DUPLICATED_OPTIONS_WITH_DIFF_SELECTED, inputs.lint_inputs,
lambda x:
len(x.warn_messages) == 0 and len(x.error_messages) == 0
),
(
SELECT_DEPRECATIONS, inputs.lint_inputs,
lambda x:
@@ -407,6 +423,7 @@ TEST_IDS = [
'lint no when',
'radio select incompatibilities',
'select duplicated options',
'select duplicated options with different selected',
'select deprecations',
'select option definitions',
'validator imcompatibilities',