Skip to content

Commit

Permalink
Implement directory_uri workflow parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 31, 2024
1 parent 0dfc0c4 commit fd34879
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
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 @@ -1272,17 +1273,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 @@ -1309,10 +1300,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 @@ -1430,6 +1434,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 @@ -1502,7 +1508,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 @@ -1613,7 +1619,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

0 comments on commit fd34879

Please sign in to comment.