Skip to content

Commit

Permalink
Rename is_runtime_value to reflect what it checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Mar 12, 2024
1 parent 2a61ad2 commit f18c43c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/tools/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
on_text_for_names,
ToolExecutionCache,
)
from galaxy.tools.parameters.basic import is_runtime_value
from galaxy.tools.parameters.basic import is_runtime_or_connected_value

if typing.TYPE_CHECKING:
from galaxy.tools import Tool
Expand Down Expand Up @@ -412,7 +412,7 @@ def precreate_output_collections(self, history, params):
# walk through and optional replace runtime values with None, assume they
# would have been replaced by now if they were going to be set.
def replace_optional_runtime_values(path, key, value):
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
return key, None
return key, value

Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/tools/parameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .basic import (
DataCollectionToolParameter,
DataToolParameter,
is_runtime_value,
is_runtime_or_connected_value,
ParameterValueError,
runtime_to_json,
SelectToolParameter,
Expand Down Expand Up @@ -163,7 +163,7 @@ def callback_helper(input, input_values, name_prefix, label_prefix, parent_prefi
replace = new_value != no_replacement_value
if replace:
input_values[input.name] = new_value
elif replace_optional_connections and is_runtime_value(value) and hasattr(input, "value"):
elif replace_optional_connections and is_runtime_or_connected_value(value) and hasattr(input, "value"):
input_values[input.name] = input.value

def get_current_case(input, input_values):
Expand Down Expand Up @@ -238,7 +238,7 @@ def check_param(trans, param, incoming_value, param_values, simple_errors=True):
error = None
try:
if trans.workflow_building_mode:
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
return [runtime_to_json(value), None]
value = param.from_json(value, trans, param_values)
param.validate(value, trans)
Expand Down
24 changes: 12 additions & 12 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def contains_workflow_parameter(value, search=False):
return False


def is_runtime_value(value):
def is_runtime_or_connected_value(value):
# TODO: rename to reflect RuntimeValue or ConnectedValue ?
return isinstance(value, RuntimeValue) or (
return isinstance(value, (ConnectedValue, RuntimeValue)) or (
isinstance(value, dict) and value.get("__class__") in ["RuntimeValue", "ConnectedValue"]
)

Expand All @@ -100,7 +100,7 @@ def is_runtime_context(trans, other_values):
if trans.workflow_building_mode:
return True
for context_value in other_values.values():
if is_runtime_value(context_value):
if is_runtime_or_connected_value(context_value):
return True
for v in util.listify(context_value):
if isinstance(v, HistoryDatasetAssociation) and (
Expand Down Expand Up @@ -235,13 +235,13 @@ def to_python(self, value, app):
return value

def value_to_basic(self, value, app, use_security=False):
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
return runtime_to_json(value)
return self.to_json(value, app, use_security)

def value_from_basic(self, value, app, ignore_errors=False):
# Handle Runtime and Unvalidated values
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
if isinstance(self, HiddenToolParameter):
raise ParameterValueError(message_suffix="Runtime Parameter not valid", parameter_name=self.name)
return runtime_to_object(value)
Expand All @@ -257,7 +257,7 @@ def value_from_basic(self, value, app, ignore_errors=False):
return self.to_python(value, app)

def value_to_display_text(self, value) -> str:
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
return "Not available."
return self.to_text(value)

Expand Down Expand Up @@ -1058,7 +1058,7 @@ def from_json(self, value, trans, other_values=None, require_legal_value=True):
raise ParameterValueError(
"no option was selected for non optional parameter", self.name, is_dynamic=self.is_dynamic
)
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
return None
if value in legal_values:
return value
Expand Down Expand Up @@ -1291,7 +1291,7 @@ def get_tag_list(self, other_values):
# Get the value of the associated data reference (a dataset)
history_items = other_values.get(self.data_ref, None)
# Check if a dataset is selected
if is_runtime_value(history_items):
if is_runtime_or_connected_value(history_items):
return []
if not history_items:
return []
Expand Down Expand Up @@ -1533,7 +1533,7 @@ def is_file_empty(self, trans, other_values):
dataset = dataset.hda
if isinstance(dataset, DatasetInstance):
return not dataset.has_data()
if is_runtime_value(dataset):
if is_runtime_or_connected_value(dataset):
return True
else:
msg = f"Dataset '{dataset}' for data_ref attribute '{self.data_ref}' of parameter '{self.name}' is not a DatasetInstance"
Expand Down Expand Up @@ -2120,7 +2120,7 @@ def from_json(self, value, trans, other_values=None):
session = trans.sa_session

other_values = other_values or {}
if trans.workflow_building_mode is workflow_building_modes.ENABLED or is_runtime_value(value):
if trans.workflow_building_mode is workflow_building_modes.ENABLED or is_runtime_or_connected_value(value):
return None
if not value and not self.optional and not self.default_object:
raise ParameterValueError("specify a dataset of the required format / build for parameter", self.name)
Expand Down Expand Up @@ -2605,7 +2605,7 @@ class BaseJsonToolParameter(ToolParameter):
"""

def value_to_basic(self, value, app, use_security=False):
if is_runtime_value(value):
if is_runtime_or_connected_value(value):
return runtime_to_json(value)
return value

Expand Down Expand Up @@ -2655,7 +2655,7 @@ def to_dict(self, trans, other_values=None):
target_name = self.data_ref
if target_name in other_values:
target = other_values[target_name]
if not is_runtime_value(target):
if not is_runtime_or_connected_value(target):
d["target"] = {
"src": "hdca" if hasattr(target, "collection") else "hda",
"id": trans.app.security.encode_id(target.id),
Expand Down
10 changes: 6 additions & 4 deletions lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
FloatToolParameter,
HiddenToolParameter,
IntegerToolParameter,
is_runtime_value,
is_runtime_or_connected_value,
parameter_types,
raw_to_galaxy,
runtime_to_json,
Expand Down Expand Up @@ -170,7 +170,7 @@ def to_cwl(value, hda_references, step):
return rval
elif isinstance(value, list):
return [to_cwl(v, hda_references=hda_references, step=step) for v in value]
elif is_runtime_value(value):
elif is_runtime_or_connected_value(value):
return None
elif isinstance(value, dict):
# Nested tool state, such as conditionals
Expand Down Expand Up @@ -845,7 +845,7 @@ def callback(input, prefixed_name, prefixed_label, value=None, **kwds):
if input.type in ["data", "data_collection"]:
return

if is_runtime_value(value) and runtime_to_json(value)["__class__"] != "ConnectedValue":
if is_runtime_or_connected_value(value) and runtime_to_json(value)["__class__"] != "ConnectedValue":
input_name = f"{step.order_index}|{prefixed_name}" # noqa: B023
inputs[input_name] = InputProxy(input, input_name)

Expand Down Expand Up @@ -1871,7 +1871,9 @@ def callback(input, prefixed_name, prefixed_label, value=None, **kwargs):
visible = not hasattr(input, "hidden") or not input.hidden
input_type = input.type
is_data = isinstance(input, DataToolParameter) or isinstance(input, DataCollectionToolParameter)
is_connectable = is_runtime_value(value) and runtime_to_json(value)["__class__"] == "ConnectedValue"
is_connectable = (
is_runtime_or_connected_value(value) and runtime_to_json(value)["__class__"] == "ConnectedValue"
)
if data_only:
skip = not visible or not is_data
elif connectable_only:
Expand Down

0 comments on commit f18c43c

Please sign in to comment.