Skip to content
Snippets Groups Projects
Commit c06a559d authored by John Chilton's avatar John Chilton
Browse files

Updates to galaxy submodules for recent planemo changes.

parent 44a51565
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,14 @@ galaxy.tools.linters.citations module
:undoc-members:
:show-inheritance:
galaxy.tools.linters.command module
-----------------------------------
.. automodule:: galaxy.tools.linters.command
:members:
:undoc-members:
:show-inheritance:
galaxy.tools.linters.help module
--------------------------------
......
......@@ -31,6 +31,7 @@ class LintContext(object):
self.found_warns = False
def lint(self, module, name, lint_func, tool_xml):
name = name.replace("tsts", "tests")
self.printed_linter_info = False
self.valid_messages = []
self.info_messages = []
......@@ -51,7 +52,7 @@ class LintContext(object):
return
self.printed_linter_info = True
print("Applying linter %s... %s" % (name, status))
for message in self.error_messages:
self.found_errors = True
print_linter_info()
......
......@@ -12,7 +12,7 @@ def lint_citations(tool_xml, lint_ctx):
return
valid_citations = 0
for citation in citations.children():
for citation in citations[0]:
if citation.tag != "citation":
lint_ctx.warn("Unknown tag discovered in citations block [%s], will be ignored." % citation.tag)
if "type" in citation.attrib:
......
def lint_command(tool_xml, lint_ctx):
root = tool_xml.getroot()
commands = root.findall("command")
if len(commands) > 1:
lint_ctx.error("More than one command tag found, behavior undefined.")
return
if len(commands) == 0:
lint_ctx.error("No command tag found, must specify a command template to execute.")
return
command = commands[0]
if "TODO" in command:
lint_ctx.warn("Command template contains TODO text.")
lint_ctx.info("Tool contains a command.")
from galaxy.util import rst_to_html
def lint_help(tool_xml, lint_ctx):
......@@ -11,5 +12,22 @@ def lint_help(tool_xml, lint_ctx):
lint_ctx.warn("No help section found, consider adding a help section to your tool.")
return
# TODO: validate help section RST.
help = helps[0].text
if not help.strip():
lint_ctx.warn("Help section appears to be empty.")
return
lint_ctx.valid("Tool contains help section.")
invalid_rst = False
try:
rst_to_html(help)
except Exception as e:
invalid_rst = str(e)
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.")
......@@ -3,7 +3,7 @@
def lint_output(tool_xml, lint_ctx):
outputs = tool_xml.findall("./outputs/data")
if not outputs:
lint_ctx.warn("Tool contains no outputs, most tools should produce outputs..")
lint_ctx.warn("Tool contains no outputs, most tools should produce outputs.")
return
num_outputs = 0
......@@ -15,7 +15,7 @@ def lint_output(tool_xml, lint_ctx):
format_set = True
format = output_attrib["format"]
if format == "input":
lint_ctx.warn("Using format='input' on output data, format_source attribute is less ambigious and should be used instead.")
lint_ctx.warn("Using format='input' on output data, format_source attribute is less ambiguous and should be used instead.")
elif "format_source" in output_attrib:
format_set = True
......
......@@ -120,6 +120,7 @@ def _expand_macro(element, expand_el, macros):
# HACK for elementtree, newer implementations (etree/lxml) won't
# require this parent_map data structure but elementtree does not
# track parents or recongnize .find('..').
# TODO fix this now that we're not using elementtree
parent_map = dict((c, p) for p in element.getiterator() for c in p)
_xml_replace(expand_el, macro_def, parent_map)
......
......@@ -2,21 +2,44 @@ import glob
import os
from ..tools import loader
import sys
import logging
log = logging.getLogger(__name__)
PATH_DOES_NOT_EXIST_ERROR = "Could not load tools from path [%s] - this path does not exist."
LOAD_FAILURE_ERROR = "Failed to load tool with path %s."
def load_exception_handler(path, exc_info):
log.warn(LOAD_FAILURE_ERROR % path, exc_info=exc_info)
def load_tool_elements_from_path(path):
def load_tool_elements_from_path(path, load_exception_handler=load_exception_handler):
tool_elements = []
for file in __find_tool_files(path):
if __looks_like_a_tool(file):
tool_elements.append((file, loader.load_tool(file)))
try:
looks_like_a_tool = __looks_like_a_tool(file)
except IOError:
# Some problem reading the tool file, skip.
continue
if looks_like_a_tool:
try:
tool_elements.append((file, loader.load_tool(file)))
except Exception:
exc_info = sys.exc_info()
load_exception_handler(file, exc_info)
return tool_elements
def __looks_like_a_tool(path):
with open(path) as f:
for i in range(10):
line = f.next()
try:
line = f.next()
except StopIteration:
break
if "<tool" in line:
return True
return False
......
......@@ -10,13 +10,19 @@ try:
import grp
except ImportError:
grp = None
try:
import docutils.core
import docutils.writers.html4css1
except ImportError:
pass
import errno
import urlparse
from tempfile import NamedTemporaryFile
from logging import getLogger
log = getLogger(__name__)
import logging
log = logging.getLogger(__name__)
BUFFER_SIZE = 4096
DEFAULT_ENCODING = os.environ.get('GALAXY_DEFAULT_ENCODING', 'utf-8')
def enum(**enums):
......@@ -130,6 +136,8 @@ def xml_text(root, name=None):
# asbool implementation pulled from PasteDeploy
truthy = frozenset(['true', 'yes', 'on', 'y', 't', '1'])
falsy = frozenset(['false', 'no', 'off', 'n', 'f', '0'])
def asbool(obj):
if isinstance(obj, basestring):
obj = obj.strip().lower()
......@@ -196,3 +204,29 @@ def mask_password_from_url( url ):
split = split._replace(netloc=split.netloc.replace("%s:%s" % (split.username, split.password), '%s:********' % split.username))
url = urlparse.urlunsplit(split)
return url
def unicodify( value, encoding=DEFAULT_ENCODING, error='replace', default=None ):
"""
Returns a unicode string or None
"""
if isinstance( value, unicode ):
return value
try:
return unicode( str( value ), encoding, error )
except:
return default
def rst_to_html( s ):
"""Convert a blob of reStructuredText to HTML"""
log = logging.getLogger( "docutils" )
class FakeStream( object ):
def write( self, str ):
if len( str ) > 0 and not str.isspace():
log.warn( str )
return unicodify( docutils.core.publish_string( s,
writer=docutils.writers.html4css1.Writer(),
settings_overrides={ "embed_stylesheet": False, "template": os.path.join(os.path.dirname(__file__), "docutils_template.txt"), "warning_stream": FakeStream() } ) )
%(body)s
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment