diff --git a/lib/galaxy/tool_util/linters/citations.py b/lib/galaxy/tool_util/linters/citations.py index 60f3527a223..ecd18b21103 100644 --- a/lib/galaxy/tool_util/linters/citations.py +++ b/lib/galaxy/tool_util/linters/citations.py @@ -8,13 +8,17 @@ of the tool publish results. def lint_citations(tool_xml, lint_ctx): """Ensure tool contains at least one valid citation.""" root = tool_xml.getroot() + if root is not None: + root_line = root.sourceline + else: + root_line = 1 citations = root.findall("citations") if len(citations) > 1: lint_ctx.error("More than one citation section found, behavior undefined.", line=citations[1].sourceline) return if len(citations) == 0: - lint_ctx.warn("No citations found, consider adding citations to your tool.", line=root.sourceline) + lint_ctx.warn("No citations found, consider adding citations to your tool.", line=root_line) return valid_citations = 0 @@ -32,4 +36,4 @@ def lint_citations(tool_xml, lint_ctx): valid_citations += 1 if valid_citations > 0: - lint_ctx.valid(f"Found {valid_citations} likely valid citations.", line=root.sourceline) + lint_ctx.valid(f"Found {valid_citations} likely valid citations.", line=root_line) diff --git a/lib/galaxy/tool_util/linters/command.py b/lib/galaxy/tool_util/linters/command.py index cd0afe744ee..e7e13749678 100644 --- a/lib/galaxy/tool_util/linters/command.py +++ b/lib/galaxy/tool_util/linters/command.py @@ -8,13 +8,17 @@ from supplied inputs. def lint_command(tool_xml, lint_ctx): """Ensure tool contains exactly one command and check attributes.""" root = tool_xml.getroot() + if root is not None: + root_line = root.sourceline + else: + root_line = 1 commands = root.findall("command") if len(commands) > 1: lint_ctx.error("More than one command tag found, behavior undefined.", line=commands[1].sourceline) return if len(commands) == 0: - lint_ctx.error("No command tag found, must specify a command template to execute.", line=root.sourceline) + lint_ctx.error("No command tag found, must specify a command template to execute.", line=root_line) return command = get_command(tool_xml) diff --git a/lib/galaxy/tool_util/linters/general.py b/lib/galaxy/tool_util/linters/general.py index 59d0bf4b14b..2911f2baed2 100644 --- a/lib/galaxy/tool_util/linters/general.py +++ b/lib/galaxy/tool_util/linters/general.py @@ -31,7 +31,7 @@ def lint_general(tool_source, lint_ctx): tool_xml = getattr(tool_source, "xml_tree", None) try: tool_line = tool_xml.find("./tool").sourceline - except: + except AttributeError: tool_line = 0 version = tool_source.parse_version() or '' parsed_version = packaging.version.parse(version) diff --git a/lib/galaxy/tool_util/linters/help.py b/lib/galaxy/tool_util/linters/help.py index be9f8ecce46..c557d6049e3 100644 --- a/lib/galaxy/tool_util/linters/help.py +++ b/lib/galaxy/tool_util/linters/help.py @@ -7,15 +7,20 @@ from galaxy.util import ( def lint_help(tool_xml, lint_ctx): """Ensure tool contains exactly one valid RST help block.""" - # determine line to report for general problems with outputs + # determine line to report for general problems with help root = tool_xml.getroot() + if root is not None: + root_line = root.sourceline + else + root_line = 1 + helps = root.findall("help") if len(helps) > 1: lint_ctx.error("More than one help section found, behavior undefined.", line=helps[1].sourceline) return if len(helps) == 0: - lint_ctx.warn("No help section found, consider adding a help section to your tool.", line=root.sourceline) + lint_ctx.warn("No help section found, consider adding a help section to your tool.", line=root_line) return help = helps[0].text or '' @@ -23,7 +28,7 @@ def lint_help(tool_xml, lint_ctx): lint_ctx.warn("Help section appears to be empty.", line=helps[0].sourceline) return - lint_ctx.valid("Tool contains help section.", line=root.sourceline) + lint_ctx.valid("Tool contains help section.", line=root_line) invalid_rst = rst_invalid(help) if "TODO" in help: diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index b7cd16ad398..6a8915ec556 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -49,7 +49,7 @@ def lint_inputs(tool_xml, lint_ctx): # determine line to report for general problems with outputs try: tool_line = tool_xml.find("./tool").sourceline - except: + except AttributeError: tool_line = 0 datasource = is_datasource(tool_xml) inputs = tool_xml.findall("./inputs//param") diff --git a/lib/galaxy/tool_util/linters/outputs.py b/lib/galaxy/tool_util/linters/outputs.py index 6f33fcb4291..9c6faa5fa43 100644 --- a/lib/galaxy/tool_util/linters/outputs.py +++ b/lib/galaxy/tool_util/linters/outputs.py @@ -9,7 +9,7 @@ def lint_output(tool_xml, lint_ctx): # determine line to report for general problems with outputs try: tool_line = tool_xml.find("./tool").sourceline - except: + except AttributeError: tool_line = 0 outputs = tool_xml.findall("./outputs") if len(outputs) == 0: diff --git a/lib/galaxy/tool_util/linters/stdio.py b/lib/galaxy/tool_util/linters/stdio.py index 801ce233f0e..d79dfa528ff 100644 --- a/lib/galaxy/tool_util/linters/stdio.py +++ b/lib/galaxy/tool_util/linters/stdio.py @@ -7,7 +7,7 @@ def lint_stdio(tool_source, lint_ctx): # determine line to report for general problems with stdio try: tool_line = tool_xml.find("./tool").sourceline - except: + except AttributeError: tool_line = 0 stdios = tool_xml.findall("./stdio") if tool_xml else [] diff --git a/lib/galaxy/tool_util/linters/tests.py b/lib/galaxy/tool_util/linters/tests.py index c62bda15ac5..74d69d22d1e 100644 --- a/lib/galaxy/tool_util/linters/tests.py +++ b/lib/galaxy/tool_util/linters/tests.py @@ -5,15 +5,14 @@ from ._util import is_datasource # Misspelled so as not be picked up by nosetests. def lint_tsts(tool_xml, lint_ctx): # determine line to report for general problems with tests - try: - tests_line = tool_xml.find("./tool").sourceline - except: - tests_line = 0 try: tests_line = tool_xml.find("./tests").sourceline - except: + except AttributeError: + tests_line = 1 + try: + tests_line = tool_xml.find("./tool").sourceline + except AttributeError: pass - tests = tool_xml.findall("./tests/test") datasource = is_datasource(tool_xml) if not tests and not datasource: