Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/linters/help.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
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 |