From 2d2f1f1a40e62f326b7e57285224c23867f4fd49 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 13 Sep 2022 16:31:09 +0200 Subject: [PATCH] post merge cleanup --- lib/galaxy/tool_util/linters/_util.py | 2 +- lib/galaxy/tool_util/linters/inputs.py | 44 ++++++++++++-------- lib/galaxy/tool_util/parser/util.py | 2 +- test/unit/tool_util/test_tool_linters.py | 52 ++++++++++++++++++------ 4 files changed, 69 insertions(+), 31 deletions(-) diff --git a/lib/galaxy/tool_util/linters/_util.py b/lib/galaxy/tool_util/linters/_util.py index 42f00a08c5cb..3b899c43c427 100644 --- a/lib/galaxy/tool_util/linters/_util.py +++ b/lib/galaxy/tool_util/linters/_util.py @@ -40,7 +40,7 @@ def get_code(tool_xml): labelcode += cn.attrib["label"] + "\n" actioncode = "" - for cn in tool_xml.findall('./outputs//conditional[@name]'): + for cn in tool_xml.findall("./outputs//conditional[@name]"): actioncode += cn.attrib["name"] + "\n" for cn in tool_xml.findall('./outputs//action/option[@type="from_param"]'): actioncode += cn.attrib.get("name", "") + "\n" diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index 40e86e79c1e8..872fe94a3d82 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -2,11 +2,7 @@ import re from galaxy.util import string_as_bool -from ._util import ( - get_code, - is_datasource, - is_valid_cheetah_placeholder -) +from ._util import get_code, is_datasource, is_valid_cheetah_placeholder from ..parser.util import _parse_name, _prepare_argument FILTER_TYPES = [ @@ -163,7 +159,7 @@ def _param_in_compiled_cheetah(param, param_name, code): # gets # set $rg_id = str($rg_param('read_group_id_conditional').ID) # rg_id = str(VFN(VFFSL(SL,"rg_param",False)('read_group_id_conditional'),"ID",True)) - if re.search(r'(VFN|VFFSL)\(.*[\"\']([\w.]+\.)?' + param_name + r'(\.[\w.]+)?[\"\']', code): + if re.search(r"(VFN|VFFSL)\(.*[\"\']([\w.]+\.)?" + param_name + r"(\.[\w.]+)?[\"\']", code): return True # #for i, r in enumerate($repeat_name) @@ -171,7 +167,7 @@ def _param_in_compiled_cheetah(param, param_name, code): # #end for # the loop content gets # x = VFFSL(SL,"str",False)(r[ 'var_in_repeat' ]) - if re.search(r'(VFFSL|VFN)\(.*\[\s*[\"\']' + param_name + r'[\"\']\s*\]', code): + if re.search(r"(VFFSL|VFN)\(.*\[\s*[\"\']" + param_name + r"[\"\']\s*\]", code): # print(f" G") return True @@ -571,7 +567,10 @@ def lint_inputs_used(tool_xml, lint_ctx): continue if param_name in filter_code: continue - if tool_xml.find("./inputs//param/options[@from_dataset]") is not None or tool_xml.find("./inputs//param/options/filter[@ref]") is not None: + if ( + tool_xml.find("./inputs//param/options[@from_dataset]") is not None + or tool_xml.find("./inputs//param/options/filter[@ref]") is not None + ): continue if param.getparent().tag == "conditional": continue @@ -581,11 +580,17 @@ def lint_inputs_used(tool_xml, lint_ctx): param_type = param.attrib.get("type") if param_type in ["data", "collection"]: if not conf_inputs.attrib.get("data_style"): - lint_ctx.error(f"Param input [{param_name}] not found in command or configfiles. Does the present inputs config miss the 'data_style' attribute?", line=param.sourceline, xpath=tool_xml.getpath(param)) - inputs_conf_name = conf_inputs.attrib.get('name', conf_inputs.attrib.get('filename', None)) + lint_ctx.error( + f"Param input [{param_name}] not found in command or configfiles. Does the present inputs config miss the 'data_style' attribute?", + node=param, + ) + inputs_conf_name = conf_inputs.attrib.get("name", conf_inputs.attrib.get("filename", None)) if inputs_conf_name: if not re.search(r"(^|[^\w])" + inputs_conf_name + r"([^\w]|$)", code): - lint_ctx.error(f"Param input [{param_name}] only used inputs configfile {inputs_conf_name}, but this is not used in the command", line=param.sourceline, xpath=tool_xml.getpath(param)) + lint_ctx.error( + f"Param input [{param_name}] only used inputs configfile {inputs_conf_name}, but this is not used in the command", + node=param, + ) continue change_format = tool_xml.find(f"./outputs//change_format/when[@input='{param_name}']") is not None @@ -599,17 +604,24 @@ def lint_inputs_used(tool_xml, lint_ctx): only = "" # TODO check that template is used?? if template: - lint_ctx.warn(f"Param input [{param_name}] {only}used in a template macro, use a macro token instead.", line=param.sourceline, xpath=tool_xml.getpath(param)) + lint_ctx.warn( + f"Param input [{param_name}] {only}used in a template macro, use a macro token instead.", node=param + ) if action: - lint_ctx.warn(f"Param input [{param_name}] {only}found in output actions, better use extended metadata.", line=param.sourceline, xpath=tool_xml.getpath(param)) + lint_ctx.warn( + f"Param input [{param_name}] {only}found in output actions, better use extended metadata.", + node=param, + ) if label: - lint_ctx.warn(f"Param input [{param_name}] {only}found in a label attribute, this is discouraged.", line=param.sourceline, xpath=tool_xml.getpath(param)) + lint_ctx.warn( + f"Param input [{param_name}] {only}found in a label attribute, this is discouraged.", node=param + ) continue if change_format: - lint_ctx.error(f"Param input [{param_name}] is only used in a change_format tag", line=param.sourceline, xpath=tool_xml.getpath(param)) + lint_ctx.error(f"Param input [{param_name}] is only used in a change_format tag", node=param) else: - lint_ctx.error(f"Param input [{param_name}] not found in command or configfiles.", line=param.sourceline, xpath=tool_xml.getpath(param)) + lint_ctx.error(f"Param input [{param_name}] not found in command or configfiles.", node=param) def lint_repeats(tool_xml, lint_ctx): diff --git a/lib/galaxy/tool_util/parser/util.py b/lib/galaxy/tool_util/parser/util.py index 61ff94fe8e3c..159eed4e5c74 100644 --- a/lib/galaxy/tool_util/parser/util.py +++ b/lib/galaxy/tool_util/parser/util.py @@ -11,7 +11,7 @@ def is_dict(item): def _prepare_argument(argument): if argument is None: return "" - return argument.lstrip('-').replace("-", "_") + return argument.lstrip("-").replace("-", "_") def _parse_name(name, argument): diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index 80b3495c646b..6fd8e832141e 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -428,6 +428,10 @@ + + + + @@ -613,6 +617,7 @@ +""" # test tool xml for outputs linter OUTPUTS_MISSING = """ @@ -1267,7 +1272,7 @@ def test_inputs_duplicated_options(lint_ctx): def test_inputs_duplicated_options_with_different_select(lint_ctx): - tool_source = get_xml_tool_source(SELECT_DUPLICATED_OPTIONS_WITH_DIFF_SELECTED) + tool_source = get_xml_tool_source(INPUTS_SELECT_DUPLICATED_OPTIONS_WITH_DIFF_SELECTED) run_lint(lint_ctx, inputs.lint_inputs, tool_source) assert not lint_ctx.warn_messages assert not lint_ctx.error_messages @@ -1421,46 +1426,67 @@ def test_inputs_duplicate_names(lint_ctx): def test_inputs_used_parameter_in_command(lint_ctx): tool_source = get_xml_tool_source(INPUTS_USED_PARAMETER_IN_COMMAND) - run_lint(lint_ctx, inputs.lint_inputs, tool_source) + run_lint(lint_ctx, inputs.lint_inputs_used, tool_source) assert not lint_ctx.info_messages assert not lint_ctx.valid_messages assert not lint_ctx.warn_messages assert "Param input [hey_a_missing_parameter] not found in command or configfiles." in lint_ctx.error_messages assert "Param input [change_format_parameter] is only used in a change_format tag" in lint_ctx.error_messages assert len(lint_ctx.error_messages) == 2 - + def test_inputs_used_other(lint_ctx): tool_source = get_xml_tool_source(INPUTS_USED_OTHER) - run_lint(lint_ctx, inputs.lint_inputs, tool_source) + run_lint(lint_ctx, inputs.lint_inputs_used, tool_source) assert not lint_ctx.info_messages assert not lint_ctx.valid_messages - assert "Param input [variable_in_template_token] only used in a template macro, use a macro token instead." in lint_ctx.warn_messages - assert "Param input [action_option_reference] only found in output actions." in lint_ctx.warn_messages - assert "Param input [action_filter_reference] only found in output actions." in lint_ctx.warn_messages - assert "Param input [action_conditional_reference] only found in output actions." in lint_ctx.warn_messages - assert "Param input [param_that_is_used_only_in_output_label] only found in a label attribute." in lint_ctx.warn_messages + assert ( + "Param input [variable_in_template_token] only used in a template macro, use a macro token instead." + in lint_ctx.warn_messages + ) + assert ( + "Param input [action_option_reference] only found in output actions, better use extended metadata." + in lint_ctx.warn_messages + ) + assert ( + "Param input [action_filter_reference] only found in output actions, better use extended metadata." + in lint_ctx.warn_messages + ) + assert ( + "Param input [action_conditional_reference] only found in output actions, better use extended metadata." + in lint_ctx.warn_messages + ) + assert ( + "Param input [param_that_is_used_only_in_output_label] only found in a label attribute, this is discouraged." + in lint_ctx.warn_messages + ) assert len(lint_ctx.warn_messages) == 5 assert len(lint_ctx.error_messages) == 0 def test_inputs_used_parameter_in_command_with_inputs(lint_ctx): tool_source = get_xml_tool_source(INPUTS_USED_PARAMETER_IN_COMMAND_WITH_INPUTS) - run_lint(lint_ctx, inputs.lint_inputs, tool_source) + run_lint(lint_ctx, inputs.lint_inputs_used, tool_source) assert not lint_ctx.info_messages assert not lint_ctx.valid_messages assert not lint_ctx.warn_messages - assert "Param input [param_that_is_not_in_inputs_configfile] not found in command or configfiles. Does the present inputs config miss the 'data_style' attribute?" in lint_ctx.error_messages + assert ( + "Param input [param_that_is_not_in_inputs_configfile] not found in command or configfiles. Does the present inputs config miss the 'data_style' attribute?" + in lint_ctx.error_messages + ) assert len(lint_ctx.error_messages) == 1 def test_inputs_used_parameter_in_command_with_inputs2(lint_ctx): tool_source = get_xml_tool_source(INPUTS_USED_PARAMETER_IN_COMMAND_WITH_INPUTS2) - run_lint(lint_ctx, inputs.lint_inputs, tool_source) + run_lint(lint_ctx, inputs.lint_inputs_used, tool_source) assert not lint_ctx.info_messages assert not lint_ctx.valid_messages assert not lint_ctx.warn_messages - assert "Param input [param_that_is_not_in_inputs_configfile] only used inputs configfile inputs, but this is not used in the command" in lint_ctx.error_messages + assert ( + "Param input [param_that_is_not_in_inputs_configfile] only used inputs configfile inputs, but this is not used in the command" + in lint_ctx.error_messages + ) assert len(lint_ctx.error_messages) == 1