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

Refactor for better reuse of workflow parameter type constants #19260

Merged
merged 1 commit into from
Dec 5, 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
10 changes: 5 additions & 5 deletions lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
get_args,
Iterable,
List,
Literal,
Optional,
Tuple,
Type,
Expand Down Expand Up @@ -109,13 +108,15 @@
from galaxy.util.rules_dsl import RuleSet
from galaxy.util.template import fill_template
from galaxy.util.tool_shed.common_util import get_tool_shed_url_from_tool_shed_registry
from galaxy.workflow.workflow_parameter_input_definitions import get_default_parameter
from galaxy.workflow.workflow_parameter_input_definitions import (
get_default_parameter,
INPUT_PARAMETER_TYPES,
)

if TYPE_CHECKING:
from galaxy.schema.invocation import InvocationMessageUnion
from galaxy.workflow.run import WorkflowProgress


log = logging.getLogger(__name__)

# Key into Tool state to describe invocation-specific runtime properties.
Expand All @@ -125,7 +126,6 @@
# ones.
RUNTIME_POST_JOB_ACTIONS_KEY = "__POST_JOB_ACTIONS__"

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 @@ -1505,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", "directory_uri"]:
if parameter_type not in POSSIBLE_PARAMETER_TYPES:
raise ValueError("Invalid parameter type for workflow parameters encountered.")

# Optional parameters for tool input source definition.
Expand Down
13 changes: 3 additions & 10 deletions lib/galaxy/workflow/workflow_parameter_input_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TextToolParameter,
)

param_types = Literal["text", "integer", "float", "color", "boolean", "directory_uri"]
INPUT_PARAMETER_TYPES = Literal["text", "integer", "float", "boolean", "color", "directory_uri"]
default_source_type = Dict[str, Union[int, float, bool, str]]
tool_param_type = Union[
TextToolParameter,
Expand All @@ -25,21 +25,14 @@
]


def get_default_parameter(param_type: param_types) -> tool_param_type:
def get_default_parameter(param_type: INPUT_PARAMETER_TYPES) -> tool_param_type:
"""
param_type is the type of parameter we want to build up, stored_parameter_type is the parameter_type
as stored in the tool state
"""
default_source: default_source_type = dict(name="default", label="Default Value", type=param_type, optional=False)
if param_type == "text":
input_default_value: Union[
TextToolParameter,
IntegerToolParameter,
FloatToolParameter,
BooleanToolParameter,
ColorToolParameter,
DirectoryUriToolParameter,
] = TextToolParameter(None, default_source)
input_default_value: tool_param_type = TextToolParameter(None, default_source)
elif param_type == "integer":
input_default_value = IntegerToolParameter(None, default_source)
elif param_type == "float":
Expand Down
Loading