Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow directory_uri workflow parameters. #19093

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
# ones.
RUNTIME_POST_JOB_ACTIONS_KEY = "__POST_JOB_ACTIONS__"

INPUT_PARAMETER_TYPES = Literal["text", "integer", "float", "boolean", "color"]
INPUT_PARAMETER_TYPES = Literal["text", "integer", "float", "boolean", "color", "directory_uri"]
POSSIBLE_PARAMETER_TYPES: Tuple[INPUT_PARAMETER_TYPES] = get_args(INPUT_PARAMETER_TYPES)


Expand Down Expand Up @@ -1210,6 +1210,7 @@ def get_inputs(self):
{"value": "float", "label": "Float"},
{"value": "boolean", "label": "Boolean (True or False)"},
{"value": "color", "label": "Color"},
{"value": "directory_uri", "label": "Directory URI"},
]
input_parameter_type = SelectToolParameter(None, select_source)
# encode following loop in description above instead
Expand Down Expand Up @@ -1269,17 +1270,7 @@ def get_inputs(self):
optional_cases = [when_true, when_false]
optional_cond.cases = optional_cases

if param_type == "text":

specify_multiple_source = dict(
name="multiple",
label="Allow multiple selection",
help="Only applies when connected to multi-select parameter(s)",
type="boolean",
)

specify_multiple = BooleanToolParameter(None, specify_multiple_source)

def regex_validator_definition():
add_validators_repeat = Repeat("validators")
add_validators_repeat.title = "Add validator to restrict valid input"
add_validators_repeat.min = 0
Expand All @@ -1306,10 +1297,23 @@ def get_inputs(self):
),
}

return add_validators_repeat

if param_type == "text":

specify_multiple_source = dict(
name="multiple",
label="Allow multiple selection",
help="Only applies when connected to multi-select parameter(s)",
type="boolean",
)

specify_multiple = BooleanToolParameter(None, specify_multiple_source)

# Insert multiple option as first option, which is determined by dictionary insert order
when_this_type.inputs = {
"multiple": specify_multiple,
"validators": add_validators_repeat,
"validators": regex_validator_definition(),
**when_this_type.inputs,
}

Expand Down Expand Up @@ -1427,6 +1431,8 @@ def get_inputs(self):
"label": "Set a maximum value for this input",
},
)
if param_type == "directory_uri":
when_this_type.inputs["validators"] = regex_validator_definition()

cases.append(when_this_type)

Expand Down Expand Up @@ -1499,7 +1505,7 @@ def get_runtime_inputs(self, step, connections: Optional[Iterable[WorkflowStepCo
parameter_type = parameter_def["parameter_type"]
optional = parameter_def["optional"]
default_value = parameter_def.get("default", self.default_default_value)
if parameter_type not in ["text", "boolean", "integer", "float", "color"]:
if parameter_type not in ["text", "boolean", "integer", "float", "color", "directory_uri"]:
raise ValueError("Invalid parameter type for workflow parameters encountered.")

# Optional parameters for tool input source definition.
Expand Down Expand Up @@ -1610,7 +1616,7 @@ def execute(
input_param = self.get_runtime_inputs(self)["input"]
# TODO: raise DelayedWorkflowEvaluation if replacement not ready ? Need test
try:
input_param.validate(input_value)
input_param.validate(input_value, trans)
except ValueError as e:
raise FailWorkflowEvaluation(
why=InvocationFailureWorkflowParameterInvalid(
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/workflow/run_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def build_workflow_run_configs(
module_injector.inject(step)
input_param = step.module.get_runtime_inputs(step.module)["input"]
try:
input_param.validate(input_dict)
input_param.validate(input_dict, trans=trans)
except ParameterValueError as e:
raise exceptions.RequestParameterInvalidException(
f"{step.label or step.order_index + 1}: {e.message_suffix}"
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/workflow/workflow_parameter_input_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
from galaxy.tools.parameters.basic import (
BooleanToolParameter,
ColorToolParameter,
DirectoryUriToolParameter,
FloatToolParameter,
IntegerToolParameter,
TextToolParameter,
)

param_types = Literal["text", "integer", "float", "color", "boolean"]
param_types = Literal["text", "integer", "float", "color", "boolean", "directory_uri"]
default_source_type = Dict[str, Union[int, float, bool, str]]
tool_param_type = Union[
TextToolParameter,
IntegerToolParameter,
FloatToolParameter,
BooleanToolParameter,
ColorToolParameter,
DirectoryUriToolParameter,
]


Expand All @@ -36,6 +38,7 @@ def get_default_parameter(param_type: param_types) -> tool_param_type:
FloatToolParameter,
BooleanToolParameter,
ColorToolParameter,
DirectoryUriToolParameter,
] = TextToolParameter(None, default_source)
elif param_type == "integer":
input_default_value = IntegerToolParameter(None, default_source)
Expand All @@ -45,4 +48,6 @@ def get_default_parameter(param_type: param_types) -> tool_param_type:
input_default_value = BooleanToolParameter(None, default_source)
elif param_type == "color":
input_default_value = ColorToolParameter(None, default_source)
elif param_type == "directory_uri":
input_default_value = DirectoryUriToolParameter(None, default_source)
return input_default_value
Loading