Skip to content

Commit

Permalink
Fix param models for dynamic options and truevalue/falsevalue
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 8, 2024
1 parent 90ce472 commit f37c889
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/galaxy/tool_util/parameters/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def _fill_default_for(tool_state: Dict[str, Any], parameter: ToolParameterT) ->
)
test_value = validate_explicit_conditional_test_value(test_parameter_name, explicit_test_value)
when = _select_which_when(conditional, test_value, conditional_state)
test_parameter = conditional.test_parameter
_fill_default_for(conditional_state, test_parameter)
_fill_defaults(conditional_state, when)
elif parameter_type in ["gx_repeat"]:
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/tool_util/parameters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ def _from_input_source_galaxy(input_source: InputSource, profile: float) -> Tool
default_test_value = cond_test_parameter_default_value(test_parameter)
for value, case_inputs_sources in input_source.parse_when_input_sources():
if isinstance(test_parameter, BooleanParameterModel):
# TODO: investigate truevalue/falsevalue when...
true_value = test_param_input_source.get("truevalue")
false_value = test_param_input_source.get("falsevalue")
if isinstance(value, str) and value == true_value:
value = True
elif isinstance(value, str) and value == false_value:
value = False
typed_value = string_as_bool(value)
else:
typed_value = value
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ def elem(self) -> Element:
# used with other tool sources.
raise NotImplementedError(NOT_IMPLEMENTED_MESSAGE)

@abstractmethod
def get_dynamic_options_code(self) -> Optional[str]:
"""If dynamic options are a piece of code to eval, return it."""

@abstractmethod
def get_data_table_name(self) -> Optional[str]:
"""If dynamic options are loaded from a data table, return the name."""
Expand Down
14 changes: 12 additions & 2 deletions lib/galaxy/tool_util/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,12 +1300,17 @@ def parse_input_sources(self):

class XmlDynamicOptions(DynamicOptions):

def __init__(self, options_elem: Element):
def __init__(self, options_elem: Element, dynamic_option_code: Optional[str]):
self._options_elem = options_elem
self._dynamic_options_code = dynamic_option_code

def elem(self) -> Element:
return self._options_elem

def get_dynamic_options_code(self) -> Optional[str]:
"""If dynamic options are a piece of code to eval, return it."""
return self._dynamic_options_code

def get_data_table_name(self) -> Optional[str]:
"""If dynamic options are loaded from a data table, return the name."""
return self._options_elem.get("from_data_table")
Expand Down Expand Up @@ -1349,7 +1354,12 @@ def parse_validators(self) -> List[AnyValidatorModel]:
def parse_dynamic_options(self) -> Optional[XmlDynamicOptions]:
"""Return a XmlDynamicOptions to describe dynamic options if options elem is available."""
options_elem = self.input_elem.find("options")
return XmlDynamicOptions(options_elem) if options_elem is not None else None
dynamic_option_code = self.input_elem.get("dynamic_options")
is_dynamic = options_elem is not None or dynamic_option_code is not None
if is_dynamic:
return XmlDynamicOptions(options_elem, dynamic_option_code)
else:
return None

def parse_static_options(self) -> List[Tuple[str, str, bool]]:
"""
Expand Down
8 changes: 5 additions & 3 deletions test/unit/app/tools/test_dynamic_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@


def get_from_url_option():
tool_param = Bunch()
tool_param.tool = Bunch()
tool_param.tool.app = Bunch()
tool_param = Bunch(
tool=Bunch(
app=Bunch(),
),
)

return DynamicOptions(
XML(
Expand Down
13 changes: 13 additions & 0 deletions test/unit/tool_util/test_parameter_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ def test_fill_defaults():
assert with_defaults["cond"]["cond"] == "single"
assert with_defaults["cond"]["inner_cond"]["inner_cond"] == "single"

# dynamic parameters should just stay empty - null would cause runtime to skip over population
with_defaults = fill_state_for({}, "parameters/gx_select_dynamic", partial=True)
assert "parameter" not in with_defaults

# dynamic parameters should just stay empty - null would cause runtime to skip over population
with_defaults = fill_state_for(
{"conditional_parameter": {"test_parameter": False}},
"parameters/gx_conditional_boolean_discriminate_on_string_value",
)
assert "conditional_parameter" in with_defaults
assert "boolean_parameter" in with_defaults["conditional_parameter"]
assert with_defaults["conditional_parameter"]["boolean_parameter"] is False


def _fake_dereference(input: DataRequestUri) -> DataRequestInternalHda:
return DataRequestInternalHda(id=EXAMPLE_ID_1)
Expand Down

0 comments on commit f37c889

Please sign in to comment.