Mercurial > repos > guerler > springsuite
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 0:d30785e31577 | 1:56ad4e20f292 |
|---|---|
| 1 """This module contains a linting function for a tool's help.""" | |
| 2 from galaxy.util import ( | |
| 3 rst_to_html, | |
| 4 unicodify, | |
| 5 ) | |
| 6 | |
| 7 | |
| 8 def lint_help(tool_xml, lint_ctx): | |
| 9 """Ensure tool contains exactly one valid RST help block.""" | |
| 10 root = tool_xml.getroot() | |
| 11 helps = root.findall("help") | |
| 12 if len(helps) > 1: | |
| 13 lint_ctx.error("More than one help section found, behavior undefined.") | |
| 14 return | |
| 15 | |
| 16 if len(helps) == 0: | |
| 17 lint_ctx.warn("No help section found, consider adding a help section to your tool.") | |
| 18 return | |
| 19 | |
| 20 help = helps[0].text or '' | |
| 21 if not help.strip(): | |
| 22 lint_ctx.warn("Help section appears to be empty.") | |
| 23 return | |
| 24 | |
| 25 lint_ctx.valid("Tool contains help section.") | |
| 26 invalid_rst = rst_invalid(help) | |
| 27 | |
| 28 if "TODO" in help: | |
| 29 lint_ctx.warn("Help contains TODO text.") | |
| 30 | |
| 31 if invalid_rst: | |
| 32 lint_ctx.warn("Invalid reStructuredText found in help - [%s]." % invalid_rst) | |
| 33 else: | |
| 34 lint_ctx.valid("Help contains valid reStructuredText.") | |
| 35 | |
| 36 | |
| 37 def rst_invalid(text): | |
| 38 """Predicate to determine if text is invalid reStructuredText. | |
| 39 | |
| 40 Return False if the supplied text is valid reStructuredText or | |
| 41 a string indicating the problem. | |
| 42 """ | |
| 43 invalid_rst = False | |
| 44 try: | |
| 45 rst_to_html(text, error=True) | |
| 46 except Exception as e: | |
| 47 invalid_rst = unicodify(e) | |
| 48 return invalid_rst |
