Skip to content

Commit

Permalink
add xpath
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed Nov 24, 2021
1 parent 00cd587 commit fa55cf8
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 108 deletions.
5 changes: 4 additions & 1 deletion lib/galaxy/tool_util/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def __str__(self):
rval = f".. {self.level.upper()}: {self.message}"
if self.line is not None:
rval += f" (line {self.line})"
if self.xpath is not None:
rval += f" [{self.xpath}]"

return rval


Expand All @@ -95,7 +98,7 @@ def lint(self, name, lint_func, lint_target):
return
self.printed_linter_info = False
self.message_list = []

# call linter
lint_func(lint_target, self)
# TODO: colorful emoji if in click CLI.
Expand Down
14 changes: 8 additions & 6 deletions lib/galaxy/tool_util/linters/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@ def lint_citations(tool_xml, lint_ctx):
root = tool_xml.getroot()
if root is not None:
root_line = root.sourceline
root_xpath = tool_xml.getpath(root)
else:
root_line = 1
root_xpath = None
citations = root.findall("citations")
if len(citations) > 1:
lint_ctx.error("More than one citation section found, behavior undefined.", line=citations[1].sourceline)
lint_ctx.error("More than one citation section found, behavior undefined.", line=citations[1].sourceline, xpath=tool_xml.getpath(citations[1]))
return

if len(citations) == 0:
lint_ctx.warn("No citations found, consider adding citations to your tool.", line=root_line)
lint_ctx.warn("No citations found, consider adding citations to your tool.", line=root_line, xpath=root_xpath)
return

valid_citations = 0
for citation in citations[0]:
if citation.tag != "citation":
lint_ctx.warn(f"Unknown tag discovered in citations block [{citation.tag}], will be ignored.", line=citation.sourceline)
lint_ctx.warn(f"Unknown tag discovered in citations block [{citation.tag}], will be ignored.", line=citation.sourceline, xpath=tool_xml.getpath(citation))
continue
citation_type = citation.attrib.get("type")
if citation_type not in ('bibtex', 'doi'):
lint_ctx.warn(f"Unknown citation type discovered [{citation_type}], will be ignored.", line=citation.sourceline)
lint_ctx.warn(f"Unknown citation type discovered [{citation_type}], will be ignored.", line=citation.sourceline, xpath=tool_xml.getpath(citation))
continue
if citation.text is None or not citation.text.strip():
lint_ctx.error(f'Empty {citation_type} citation.', line=citation.sourceline)
lint_ctx.error(f'Empty {citation_type} citation.', line=citation.sourceline, xpath=tool_xml.getpath(citation))
continue
valid_citations += 1

if valid_citations > 0:
lint_ctx.valid(f"Found {valid_citations} likely valid citations.", line=root_line)
lint_ctx.valid(f"Found {valid_citations} likely valid citations.", line=root_line, xpath=root_xpath)
14 changes: 8 additions & 6 deletions lib/galaxy/tool_util/linters/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ def lint_command(tool_xml, lint_ctx):
root = tool_xml.getroot()
if root is not None:
root_line = root.sourceline
root_path = tool_xml.getpath(root)
else:
root_line = 1
root_path = None
commands = root.findall("command")
if len(commands) > 1:
lint_ctx.error("More than one command tag found, behavior undefined.", line=commands[1].sourceline)
lint_ctx.error("More than one command tag found, behavior undefined.", line=commands[1].sourceline, xpath=tool_xml.getpath(commands[1]))
return

if len(commands) == 0:
lint_ctx.error("No command tag found, must specify a command template to execute.", line=root_line)
lint_ctx.error("No command tag found, must specify a command template to execute.", line=root_line, xpath=root_path)
return

command = get_command(tool_xml)
if "TODO" in command:
lint_ctx.warn("Command template contains TODO text.", line=command.sourceline)
lint_ctx.warn("Command template contains TODO text.", line=command.sourceline, xpath=tool_xml.getpath(command))

command_attrib = command.attrib
interpreter_type = None
Expand All @@ -33,14 +35,14 @@ def lint_command(tool_xml, lint_ctx):
elif key == "detect_errors":
detect_errors = value
if detect_errors not in ["default", "exit_code", "aggressive"]:
lint_ctx.warn(f"Unknown detect_errors attribute [{detect_errors}]", line=command.sourceline)
lint_ctx.warn(f"Unknown detect_errors attribute [{detect_errors}]", line=command.sourceline, xpath=tool_xml.getpath(command))

interpreter_info = ""
if interpreter_type:
interpreter_info = f" with interpreter of type [{interpreter_type}]"
if interpreter_type:
lint_ctx.info("Command uses deprecated 'interpreter' attribute.", line=command.sourceline)
lint_ctx.info(f"Tool contains a command{interpreter_info}.", line=command.sourceline)
lint_ctx.info("Command uses deprecated 'interpreter' attribute.", line=command.sourceline, xpath=tool_xml.getpath(command))
lint_ctx.info(f"Tool contains a command{interpreter_info}.", line=command.sourceline, xpath=tool_xml.getpath(command))


def get_command(tool_xml):
Expand Down
19 changes: 10 additions & 9 deletions lib/galaxy/tool_util/linters/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,34 @@ def lint_help(tool_xml, lint_ctx):
root = tool_xml.getroot()
if root is not None:
root_line = root.sourceline
else
root_path = tool_xml.getpath(root)
else:
root_line = 1

root_path = None
helps = root.findall("help")
if len(helps) > 1:
lint_ctx.error("More than one help section found, behavior undefined.", line=helps[1].sourceline)
lint_ctx.error("More than one help section found, behavior undefined.", line=helps[1].sourceline, xpath=tool_xml.getpath(helps[1]))
return

if len(helps) == 0:
lint_ctx.warn("No help section found, consider adding a help section to your tool.", line=root_line)
lint_ctx.warn("No help section found, consider adding a help section to your tool.", line=root_line, xpath=root_path)
return

help = helps[0].text or ''
if not help.strip():
lint_ctx.warn("Help section appears to be empty.", line=helps[0].sourceline)
lint_ctx.warn("Help section appears to be empty.", line=helps[0].sourceline, xpath=tool_xml.getpath(helps[0]))
return

lint_ctx.valid("Tool contains help section.", line=root_line)
lint_ctx.valid("Tool contains help section.", line=helps[0].sourceline, xpath=tool_xml.getpath(helps[0]))
invalid_rst = rst_invalid(help)

if "TODO" in help:
lint_ctx.warn("Help contains TODO text.", line=helps[0].sourceline)
lint_ctx.warn("Help contains TODO text.", line=helps[0].sourceline, xpath=tool_xml.getpath(helps[0]))

if invalid_rst:
lint_ctx.warn(f"Invalid reStructuredText found in help - [{invalid_rst}].", line=helps[0].sourceline)
lint_ctx.warn(f"Invalid reStructuredText found in help - [{invalid_rst}].", line=helps[0].sourceline, xpath=tool_xml.getpath(helps[0]))
else:
lint_ctx.valid("Help contains valid reStructuredText.", line=helps[0].sourceline)
lint_ctx.valid("Help contains valid reStructuredText.", line=helps[0].sourceline, xpath=tool_xml.getpath(helps[0]))


def rst_invalid(text):
Expand Down
Loading

0 comments on commit fa55cf8

Please sign in to comment.