Skip to content

Commit

Permalink
Clean up dataset passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Feb 8, 2024
1 parent 0f2b038 commit 28d3da4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
8 changes: 7 additions & 1 deletion lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import os.path
import re
import typing
import urllib.parse
from collections.abc import MutableMapping
from typing import (
Expand Down Expand Up @@ -1101,6 +1102,9 @@ def to_json(self, value, app, use_security):
return history_item_to_json(value, app, use_security=use_security)
return value

def to_python(self, value, app):
return history_item_dict_to_python(value, app, self.name) or super().to_python(value, app)

def get_initial_value(self, trans, other_values):
try:
options = list(self.get_options(trans, other_values))
Expand Down Expand Up @@ -2011,7 +2015,9 @@ def do_validate(v):
raise ValueError("At most %d datasets are required for %s" % (self.max, self.name))


def src_id_to_item(sa_session: "Session", value: MutableMapping[str, Any], security: "IdEncodingHelper") -> Union[
def src_id_to_item(
sa_session: "Session", value: typing.MutableMapping[str, Any], security: "IdEncodingHelper"
) -> Union[
DatasetCollectionElement,
HistoryDatasetAssociation,
HistoryDatasetCollectionAssociation,
Expand Down
23 changes: 5 additions & 18 deletions lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import shlex
import tempfile
from collections.abc import MutableMapping
from functools import total_ordering
from typing import (
Any,
Expand Down Expand Up @@ -31,10 +30,7 @@
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,
history_item_dict_to_python,
)
from galaxy.tools.parameters.basic import BooleanToolParameter
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 @@ -218,26 +214,17 @@ def __init__(
self._input = input
self._value = value
self._other_values = other_values
self._fields: Dict[str, str] = {}
self._fields: Dict[str, List[str]] = {}
self._compute_environment = compute_environment

def __getattr__(self, name: str) -> Any:
if name not in self._fields:
if isinstance(self._value, MutableMapping):
dataset = history_item_dict_to_python(
self._value, app=self._compute_environment.job_io.user_context.trans.app, name=self._input.name
)
self._fields[name] = [self._input.options.get_option_from_dataset(dataset)[name]]
if isinstance(self._value, DatasetInstance):
self._fields[name] = [self._input.options.get_option_from_dataset(self._value)[name]]
else:
self._fields[name] = self._input.options.get_field_by_name_for_value(
# TODO: Replace trans here ...
name,
self._value,
self._compute_environment.job_io.user_context.trans,
self._other_values,
name, self._value, None, self._other_values
)
# if name == "path":
# dataset = self._input.options.get_field_by_name_for_value("dataset" ... ) ?
values = map(str, self._fields[name])
if name in PATH_ATTRIBUTES and self._compute_environment:
# If we infer this is a path, rewrite it if needed.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/app/tools/test_select_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ def __init__(self):
)
self.missing_index_file = None

def get_fields(self, user, history):
def get_fields(self):
return [["testname1", "testpath1"], ["testname2", "testpath2"]]

0 comments on commit 28d3da4

Please sign in to comment.