From e98abeb61d98bf2a3535d176b472a4753f7a1582 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:25:12 +0200 Subject: [PATCH] Create links only for inputs of type data --- server/galaxyls/services/links.py | 22 ++++++++++++++++------ server/galaxyls/services/tools/document.py | 11 +++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/server/galaxyls/services/links.py b/server/galaxyls/services/links.py index 44b90f7..98afdec 100644 --- a/server/galaxyls/services/links.py +++ b/server/galaxyls/services/links.py @@ -4,6 +4,7 @@ from galaxyls.services.tools.document import GalaxyToolXmlDocument from galaxyls.services.xml.document import XmlDocument +from galaxyls.services.xml.nodes import XmlElement from galaxyls.services.xml.utils import convert_document_offsets_to_range @@ -20,18 +21,17 @@ def _get_test_data_file_links(self, tool: GalaxyToolXmlDocument) -> List[Documen for test in tool.get_tests(): params = filter(lambda e: e.name == "param", test.elements) for param in params: - value_attr = param.attributes.get("value") - if value_attr is None or value_attr.value is None: + value_attribute = param.attributes.get("value") + filename = param.get_attribute_value("value") + if not value_attribute or not value_attribute.value or not filename: # Must have a value continue - filename = value_attr.get_value() - if filename is None or "." not in filename: - # Must be a filename with extension + if not self._is_data_input_param(param, tool): continue test_data_file_path = tool.get_test_data_path() / filename - start_offset, end_offset = value_attr.value.get_unquoted_content_offsets() + start_offset, end_offset = value_attribute.value.get_unquoted_content_offsets() link_range = convert_document_offsets_to_range(tool.xml_document.document, start_offset, end_offset) result.append( DocumentLink( @@ -40,3 +40,13 @@ def _get_test_data_file_links(self, tool: GalaxyToolXmlDocument) -> List[Documen ) ) return result + + def _is_data_input_param(self, param: XmlElement, tool: GalaxyToolXmlDocument) -> bool: + param_name = param.get_attribute_value("name") + inputs = tool.get_inputs() + for input in inputs: + input_name = input.get_attribute_value("name") + if input_name == param_name: + input_type = input.get_attribute_value("type") + return input_type == "data" + return False diff --git a/server/galaxyls/services/tools/document.py b/server/galaxyls/services/tools/document.py index 96050cf..198416c 100644 --- a/server/galaxyls/services/tools/document.py +++ b/server/galaxyls/services/tools/document.py @@ -147,6 +147,17 @@ def analyze_inputs(self) -> GalaxyToolInputTree: inputs = self.find_element(INPUTS) return GalaxyToolInputTree(inputs) + def get_inputs(self) -> List[XmlElement]: + """Gets the inputs of this document as a list of elements. + + Returns: + List[XmlElement]: The outputs defined in the document. + """ + outputs = self.find_element(INPUTS) + if outputs: + return outputs.elements + return [] + def get_outputs(self) -> List[XmlElement]: """Gets the outputs of this document as a list of elements.