From 302b281bd83a11f24d2d20f80ee13c2833f1a818 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 24 Sep 2024 18:56:11 -0400 Subject: [PATCH] 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 50ec9ed30d17..b0262157194c 100644 --- a/lib/galaxy/tool_util/parser/interface.py +++ b/lib/galaxy/tool_util/parser/interface.py @@ -433,19 +433,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 c61b178e64c7..fcdcfa536608 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, @@ -1370,50 +1369,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 @@ -1571,17 +1533,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 9669b62771e9..846c7a0a37cc 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1647,12 +1647,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): @@ -1673,20 +1671,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 @@ -1829,12 +1813,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