Skip to content

Commit

Permalink
Refactor text wrapper default handling to expose fewer internals.
Browse files Browse the repository at this point in the history
I don't want to have to set optionality inferred for all tool parameters and I want to try to encapsulate this logic more in the parameter definition.
  • Loading branch information
jmchilton committed Oct 7, 2024
1 parent 101d53c commit cdb6b1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
13 changes: 12 additions & 1 deletion lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def __init__(self, tool, input_source, context=None):
self.hidden = input_source.get_bool("hidden", False)
self.refresh_on_change = input_source.get_bool("refresh_on_change", False)
self.optional = input_source.parse_optional()
self.optionality_inferred = False
self.is_dynamic = False
self.label = input_source.parse_label()
self.help = input_source.parse_help()
Expand Down Expand Up @@ -351,6 +350,7 @@ def parse_name(input_source):
class SimpleTextToolParameter(ToolParameter):
def __init__(self, tool, input_source):
input_source = ensure_input_source(input_source)
self.optionality_inferred = False
super().__init__(tool, input_source)
optional = input_source.get("optional", None)
if optional is not None:
Expand Down Expand Up @@ -404,6 +404,7 @@ class TextToolParameter(SimpleTextToolParameter):
def __init__(self, tool, input_source):
input_source = ensure_input_source(input_source)
super().__init__(tool, input_source)
self.profile = tool.profile
self.datalist = []
for title, value, _ in input_source.parse_static_options():
self.datalist.append({"label": title, "value": value})
Expand All @@ -419,6 +420,16 @@ def validate(self, value, trans=None):
):
return super().validate(value, trans)

@property
def wrapper_default() -> Optional[str]:
"""Handle change in default handling pre and post 23.0 profiles."""
profile = self.profile
legacy_behavior = (profile is None or Version(str(profile)) < Version("23.0"))
default_value = None
if self.optional and self.optionality_inferred and legacy_behavior:
default_value = ""
return default_value

def to_dict(self, trans, other_values=None):
d = super().to_dict(trans)
other_values = other_values or {}
Expand Down
16 changes: 6 additions & 10 deletions lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Union,
)

from packaging.version import Version
from typing_extensions import TypeAlias

from galaxy.model import (
Expand All @@ -33,7 +32,10 @@
from galaxy.model.metadata import FileParameter
from galaxy.model.none_like import NoneDataset
from galaxy.security.object_wrapper import wrap_with_safe_string
from galaxy.tools.parameters.basic import BooleanToolParameter
from galaxy.tools.parameters.basic import (
BooleanToolParameter,
TextToolParameter,
)
from galaxy.tools.parameters.wrapped_json import (
data_collection_input_to_staging_path_and_source_path,
data_input_to_staging_path_and_source_path,
Expand Down Expand Up @@ -126,15 +128,9 @@ def __init__(
profile: Optional[float] = None,
) -> None:
self.input = input
if (
value is None
and input.type == "text"
and input.optional
and input.optionality_inferred
and (profile is None or Version(str(profile)) < Version("23.0"))
):
if value is None and input.type == "text":
# Tools with old profile versions may treat an optional text parameter as `""`
value = ""
value = cast(TextToolParameter, input).wrapper_default()
self.value = value
self._other_values: Dict[str, str] = other_values or {}

Expand Down

0 comments on commit cdb6b1d

Please sign in to comment.