Skip to content

Commit

Permalink
Improve tool loading problem messages.
Browse files Browse the repository at this point in the history
Include tool paths, IDs, etc... where appropriate.
  • Loading branch information
jmchilton committed Feb 22, 2016
1 parent e5758ea commit 3b70182
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def parse( self, tool_source, guid=None ):
else:
self.id = guid
if not self.id:
raise Exception( "Missing tool 'id'" )
raise Exception( "Missing tool 'id' for tool at '%s'" % tool_source )

if not self.legacy_defaults and VERSION_MAJOR < tool_profile:
template = "The tool %s targets version %s of Galaxy, you should upgrade Galaxy to ensure proper functioning of this tool."
Expand All @@ -479,15 +479,15 @@ def parse( self, tool_source, guid=None ):
# Get the (user visible) name of the tool
self.name = tool_source.parse_name()
if not self.name:
raise Exception( "Missing tool 'name'" )
raise Exception( "Missing tool 'name' for tool with id '%s' at '%s'" % (self.id, tool_source) )

self.version = tool_source.parse_version()
if not self.version:
if self.legacy_defaults:
# For backward compatibility, some tools may not have versions yet.
self.version = "1.0.0"
else:
raise Exception( "Missing tool version.")
raise Exception( "Missing tool 'version' for tool with id '%s' at '%s'" % (self.id, tool_source) )

# Support multi-byte tools
self.is_multi_byte = tool_source.parse_is_multi_byte()
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/tools/parser/cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, tool_file):
self._cwl_tool_file = tool_file
self._id, _ = os.path.splitext(os.path.basename(tool_file))
self._tool_proxy = tool_proxy(tool_file)
self._source_path = tool_file

@property
def tool_proxy(self):
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/tools/parser/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ def get_tool_source(config_file, enable_beta_formats=True):
if not enable_beta_formats:
tree = load_tool_xml(config_file)
root = tree.getroot()
return XmlToolSource(root)
return XmlToolSource(root, source_path=config_file)

if config_file.endswith(".yml"):
log.info("Loading tool from YAML - this is experimental - tool will not function in future.")
with open(config_file, "r") as f:
as_dict = ordered_load(f)
return YamlToolSource(as_dict)
return YamlToolSource(as_dict, source_path=config_file)
elif config_file.endswith(".json") or config_file.endswith(".cwl"):
log.info("Loading CWL tool - this is experimental - tool likely will not function in future at least in same way.")
return CwlToolSource(config_file)
else:
tree = load_tool_xml(config_file)
root = tree.getroot()
return XmlToolSource(root)
return XmlToolSource(root, source_path=config_file)


def ordered_load(stream):
Expand Down
11 changes: 11 additions & 0 deletions lib/galaxy/tools/parser/interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from abc import ABCMeta
from abc import abstractmethod

import six

NOT_IMPLEMENTED_MESSAGE = "Galaxy tool format does not yet support this tool feature."


@six.python_2_unicode_compatible
class ToolSource(object):
""" This interface represents an abstract source to parse tool
information from.
Expand Down Expand Up @@ -182,6 +185,14 @@ def parse_profile(self):
def parse_tests_to_dict(self):
return {'tests': []}

def __str__(self):
source_path = getattr(self, "_soure_path", None)
if source_path:
as_str = u'%s[%s]' % (self.__class__.__name__, source_path)
else:
as_str = u'%s[In-memory]' % (self.__class__.__name__)
return as_str


class PagesSource(object):
""" Contains a list of Pages - each a list of InputSources -
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tools/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class XmlToolSource(ToolSource):
""" Responsible for parsing a tool from classic Galaxy representation.
"""

def __init__(self, root):
def __init__(self, root, source_path=None):
self.root = root
self._source_path = source_path

def parse_version(self):
return self.root.get("version", None)
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tools/parser/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

class YamlToolSource(ToolSource):

def __init__(self, root_dict):
def __init__(self, root_dict, source_path=None):
self.root_dict = root_dict
self._source_path = source_path

def parse_id(self):
return self.root_dict.get("id")
Expand Down

0 comments on commit 3b70182

Please sign in to comment.