Mercurial > repos > guerler > springsuite
diff planemo/lib/python3.7/site-packages/galaxy/tool_util/linters/help.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/planemo/lib/python3.7/site-packages/galaxy/tool_util/linters/help.py Fri Jul 31 00:32:28 2020 -0400 @@ -0,0 +1,48 @@ +"""This module contains a linting function for a tool's help.""" +from galaxy.util import ( + rst_to_html, + unicodify, +) + + +def lint_help(tool_xml, lint_ctx): + """Ensure tool contains exactly one valid RST help block.""" + root = tool_xml.getroot() + helps = root.findall("help") + if len(helps) > 1: + lint_ctx.error("More than one help section found, behavior undefined.") + return + + if len(helps) == 0: + lint_ctx.warn("No help section found, consider adding a help section to your tool.") + return + + help = helps[0].text or '' + if not help.strip(): + lint_ctx.warn("Help section appears to be empty.") + return + + lint_ctx.valid("Tool contains help section.") + invalid_rst = rst_invalid(help) + + if "TODO" in help: + lint_ctx.warn("Help contains TODO text.") + + if invalid_rst: + lint_ctx.warn("Invalid reStructuredText found in help - [%s]." % invalid_rst) + else: + lint_ctx.valid("Help contains valid reStructuredText.") + + +def rst_invalid(text): + """Predicate to determine if text is invalid reStructuredText. + + Return False if the supplied text is valid reStructuredText or + a string indicating the problem. + """ + invalid_rst = False + try: + rst_to_html(text, error=True) + except Exception as e: + invalid_rst = unicodify(e) + return invalid_rst