Skip to content

Commit 411a8da

Browse files
committed
Improvements to linting help sections.
- Warn if help section is empty. - Warn if help section contains invalid RST.
1 parent 78f8274 commit 411a8da

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

planemo_ext/galaxy/tools/linters/help.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from galaxy.util import rst_to_html
12

23

34
def lint_help(tool_xml, lint_ctx):
@@ -11,5 +12,22 @@ def lint_help(tool_xml, lint_ctx):
1112
lint_ctx.warn("No help section found, consider adding a help section to your tool.")
1213
return
1314

14-
# TODO: validate help section RST.
15+
help = helps[0].text
16+
if not help.strip():
17+
lint_ctx.warn("Help section appears to be empty.")
18+
return
19+
1520
lint_ctx.valid("Tool contains help section.")
21+
invalid_rst = False
22+
try:
23+
rst_to_html(help)
24+
except Exception as e:
25+
invalid_rst = str(e)
26+
27+
if "TODO" in help:
28+
lint_ctx.warn("Help contains TODO text.")
29+
30+
if invalid_rst:
31+
lint_ctx.warn("Invalid reStructuredText found in help - [%s]." % invalid_rst)
32+
else:
33+
lint_ctx.valid("Help contains valid reStructuredText.")

planemo_ext/galaxy/util/__init__.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
import grp
1111
except ImportError:
1212
grp = None
13+
try:
14+
import docutils.core
15+
import docutils.writers.html4css1
16+
except ImportError:
17+
pass
1318
import errno
1419
import urlparse
1520
from tempfile import NamedTemporaryFile
16-
from logging import getLogger
17-
log = getLogger(__name__)
21+
import logging
22+
log = logging.getLogger(__name__)
1823

1924
BUFFER_SIZE = 4096
25+
DEFAULT_ENCODING = os.environ.get('GALAXY_DEFAULT_ENCODING', 'utf-8')
2026

2127

2228
def enum(**enums):
@@ -130,6 +136,8 @@ def xml_text(root, name=None):
130136
# asbool implementation pulled from PasteDeploy
131137
truthy = frozenset(['true', 'yes', 'on', 'y', 't', '1'])
132138
falsy = frozenset(['false', 'no', 'off', 'n', 'f', '0'])
139+
140+
133141
def asbool(obj):
134142
if isinstance(obj, basestring):
135143
obj = obj.strip().lower()
@@ -193,3 +201,29 @@ def mask_password_from_url( url ):
193201
split._replace(netloc=split.netloc.replace("%s:%s" % (split.username, split.password), '%s:********' % split.username))
194202
url = urlparse.urlunsplit(split)
195203
return url
204+
205+
206+
def unicodify( value, encoding=DEFAULT_ENCODING, error='replace', default=None ):
207+
"""
208+
Returns a unicode string or None
209+
"""
210+
211+
if isinstance( value, unicode ):
212+
return value
213+
try:
214+
return unicode( str( value ), encoding, error )
215+
except:
216+
return default
217+
218+
219+
def rst_to_html( s ):
220+
"""Convert a blob of reStructuredText to HTML"""
221+
log = logging.getLogger( "docutils" )
222+
223+
class FakeStream( object ):
224+
def write( self, str ):
225+
if len( str ) > 0 and not str.isspace():
226+
log.warn( str )
227+
return unicodify( docutils.core.publish_string( s,
228+
writer=docutils.writers.html4css1.Writer(),
229+
settings_overrides={ "embed_stylesheet": False, "template": os.path.join(os.path.dirname(__file__), "docutils_template.txt"), "warning_stream": FakeStream() } ) )
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%(body)s

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'six',
1919
'pyyaml',
2020
'jinja2',
21+
'docutils',
2122
]
2223

2324
test_requirements = [
@@ -53,7 +54,9 @@
5354
],
5455
data_files=[('tool_factory_2', ['tool_factory_2/rgToolFactory2.xml',
5556
'tool_factory_2/rgToolFactory2.py',
56-
'tool_factory_2/getlocalrpackages.py'])],
57+
'tool_factory_2/getlocalrpackages.py']),
58+
('planemo_ext/galaxy/util', ['planemo_ext/galaxy/util/docutils_template.txt']),
59+
],
5760
entry_points='''
5861
[console_scripts]
5962
planemo=planemo.cli:planemo

0 commit comments

Comments
 (0)