From 3c1461ccc12e0fd3970f472d9d15f5c06e42cc2d Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 24 Sep 2024 18:56:11 -0400 Subject: [PATCH 1/3] Remove some unused dynamic drill down options. --- lib/galaxy/tool_util/parser/interface.py | 7 ---- lib/galaxy/tool_util/parser/xml.py | 50 ++---------------------- lib/galaxy/tools/parameters/basic.py | 22 ----------- 3 files changed, 4 insertions(+), 75 deletions(-) diff --git a/lib/galaxy/tool_util/parser/interface.py b/lib/galaxy/tool_util/parser/interface.py index c137955dbeb1..35d66eaa6589 100644 --- a/lib/galaxy/tool_util/parser/interface.py +++ b/lib/galaxy/tool_util/parser/interface.py @@ -443,19 +443,12 @@ def get_index_file_name(self) -> Optional[str]: """If dynamic options are loaded from an index file, return the name.""" -DrillDownDynamicFilters = Dict[str, Dict[str, dict]] # {input key: {metadata_key: metadata values}} - - class DrillDownDynamicOptions(metaclass=ABCMeta): @abstractmethod def from_code_block(self) -> Optional[str]: """Get a code block to do an eval on.""" - @abstractmethod - def from_filters(self) -> Optional[DrillDownDynamicFilters]: - """Get filters to apply to target datasets.""" - class InputSource(metaclass=ABCMeta): default_optional = False diff --git a/lib/galaxy/tool_util/parser/xml.py b/lib/galaxy/tool_util/parser/xml.py index a89754553f84..301be5b3051a 100644 --- a/lib/galaxy/tool_util/parser/xml.py +++ b/lib/galaxy/tool_util/parser/xml.py @@ -37,7 +37,6 @@ from .interface import ( AssertionList, Citation, - DrillDownDynamicFilters, DrillDownDynamicOptions, DrillDownOptionsDict, DynamicOptions, @@ -1371,50 +1370,13 @@ def parse_static_options(self) -> List[Tuple[str, str, bool]]: def parse_drill_down_dynamic_options( self, tool_data_path: Optional[str] = None ) -> Optional[DrillDownDynamicOptions]: - from_file = self.input_elem.get("from_file", None) - if from_file: - if not os.path.isabs(from_file): - assert tool_data_path, "This tool cannot be parsed outside of a Galaxy context" - from_file = os.path.join(tool_data_path, from_file) - elem = XML(f"{open(from_file).read()}") - else: - elem = self.input_elem - + elem = self.input_elem dynamic_options_raw = elem.get("dynamic_options", None) dynamic_options: Optional[str] = str(dynamic_options_raw) if dynamic_options_raw else None - filters: Optional[DrillDownDynamicFilters] = None - if elem.find("filter"): - _filters: DrillDownDynamicFilters = {} - for filter in elem.findall("filter"): - # currently only filtering by metadata key matching input file is allowed - filter_type = filter.get("type") - if filter_type == "data_meta": - data_ref = filter.get("data_ref") - assert data_ref - if data_ref not in _filters: - _filters[data_ref] = {} - meta_key = filter.get("meta_key") - assert meta_key - if meta_key not in _filters[data_ref]: - _filters[data_ref][meta_key] = {} - meta_value = filter.get("value") - if meta_value not in _filters[data_ref][meta_key]: - _filters[data_ref][meta_key][meta_value] = [] - assert meta_value - options_elem = filter.find("options") - assert options_elem - _recurse_drill_down_elems( - _filters[data_ref][meta_key][meta_value], - options_elem.findall("option"), - ) - filters = _filters - if filters is None and dynamic_options is None: + if dynamic_options is None: return None else: - return XmlDrillDownDynamicOptions( - code_block=dynamic_options, - filters=filters, - ) + return XmlDrillDownDynamicOptions(code_block=dynamic_options) def parse_drill_down_static_options( self, tool_data_path: Optional[str] = None @@ -1572,17 +1534,13 @@ def parse_citation_elem(citation_elem: Element) -> Optional[Citation]: class XmlDrillDownDynamicOptions(DrillDownDynamicOptions): - def __init__(self, code_block: Optional[str], filters: Optional[DrillDownDynamicFilters]): + def __init__(self, code_block: Optional[str]): self._code_block = code_block - self._filters = filters def from_code_block(self) -> Optional[str]: """Get a code block to do an eval on.""" return self._code_block - def from_filters(self) -> Optional[DrillDownDynamicFilters]: - return self._filters - def _element_to_dict(elem: Element) -> Dict[str, Any]: # every call to this function needs to be replaced with something more type safe and with diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 1a099bfe7061..8043949d7922 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1648,12 +1648,10 @@ def __init__(self, tool, input_source, context=None): if drill_down_dynamic_options is not None: self.is_dynamic = True self.dynamic_options = drill_down_dynamic_options.code_block - self.filtered = drill_down_dynamic_options.filters self.options = [] else: self.is_dynamic = False self.dynamic_options = None - self.filtered = {} self.options = input_source.parse_drill_down_static_options(tool_data_path) def _get_options_from_code(self, trans=None, other_values=None): @@ -1674,20 +1672,6 @@ def get_options(self, trans=None, other_values=None): options = self._get_options_from_code(trans=trans, other_values=other_values) else: options = [] - for filter_key, filter_value in self.filtered.items(): - dataset = other_values.get(filter_key) - if dataset.__class__.__name__.endswith( - "DatasetFilenameWrapper" - ): # this is a bad way to check for this, but problems importing class (due to circular imports?) - dataset = dataset.dataset - if dataset: - for meta_key, meta_dict in filter_value.items(): - if hasattr(dataset, "metadata") and hasattr(dataset.metadata, "spec"): - check_meta_val = dataset.metadata.spec[meta_key].param.to_string( - dataset.metadata.get(meta_key) - ) - if check_meta_val in meta_dict: - options.extend(meta_dict[check_meta_val]) return options return self.options @@ -1830,12 +1814,6 @@ def get_option_display(value, options): return "\n".join(map(str, rval)) return "Nothing selected." - def get_dependencies(self): - """ - Get the *names* of the other params this param depends on. - """ - return list(self.filtered.keys()) - def to_dict(self, trans, other_values=None): other_values = other_values or {} # skip SelectToolParameter (the immediate parent) bc we need to get options in a different way here From 7253cea658f3c2f95d5f4bc6a3d43e2103b4b914 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 26 Sep 2024 10:38:43 -0400 Subject: [PATCH 2/3] Update lib/galaxy/tools/parameters/basic.py Co-authored-by: Nicola Soranzo --- lib/galaxy/tools/parameters/basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 8043949d7922..2dc6e01dcfdb 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1647,7 +1647,7 @@ def __init__(self, tool, input_source, context=None): drill_down_dynamic_options = input_source.parse_drill_down_dynamic_options(tool_data_path) if drill_down_dynamic_options is not None: self.is_dynamic = True - self.dynamic_options = drill_down_dynamic_options.code_block + self.dynamic_options = drill_down_dynamic_options.from_code_block() self.options = [] else: self.is_dynamic = False From cee6a76763e1d39cc317ad66e09e1630d2e81bc2 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 27 Sep 2024 17:20:04 -0400 Subject: [PATCH 3/3] This needs to be there. --- lib/galaxy/tools/parameters/basic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 2dc6e01dcfdb..0bd4509372f2 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1814,6 +1814,9 @@ def get_option_display(value, options): return "\n".join(map(str, rval)) return "Nothing selected." + def get_dependencies(self): + return [] + def to_dict(self, trans, other_values=None): other_values = other_values or {} # skip SelectToolParameter (the immediate parent) bc we need to get options in a different way here