Skip to content

Commit

Permalink
post merge cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed Sep 13, 2022
1 parent e2e66b4 commit 2d2f1f1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/linters/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 28 additions & 16 deletions lib/galaxy/tool_util/linters/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -163,15 +159,15 @@ 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)
# #set x = $str(r[ 'param_name' ])
# #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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/parser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
52 changes: 39 additions & 13 deletions test/unit/tool_util/test_tool_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@
</section>
<conditional name="cond">
<param name="dup_in_cond" type="select">
<option value="a">a</option>
<option value="b">b</option>
</param>
<when value="a">
<param name="dup_in_cond" type="text"/>
</when>
<when value="b">
Expand Down Expand Up @@ -613,6 +617,7 @@
<param name="param_that_is_not_in_inputs_configfile" type="text"/>
</inputs>
</tool>
"""

# test tool xml for outputs linter
OUTPUTS_MISSING = """
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 2d2f1f1

Please sign in to comment.