Skip to content

Commit

Permalink
Discriminate data managers and allow managed testing
Browse files Browse the repository at this point in the history
I am not a big fan of the heuristic in which we fall back
to loading the data manager tool relative to the data_manager_conf.xml
file, but I don't really see a better way here.
  • Loading branch information
mvdbeek committed Feb 7, 2019
1 parent c4fbe94 commit d710bb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/galaxy/tools/data_manager/manager.py
Expand Up @@ -57,11 +57,19 @@ def load_from_xml(self, xml_filename, store_tool_path=True):
tool_path = '.'
self.tool_path = tool_path
for data_manager_elem in root.findall('data_manager'):
self.load_manager_from_elem(data_manager_elem, tool_path=self.tool_path)
if not self.load_manager_from_elem(data_manager_elem, tool_path=self.tool_path):
# Wasn't able to load manager, could happen when galaxy is managed by planemo.
# Fall back to loading relative to the data_manager_conf.xml file
tool_path = os.path.dirname(xml_filename)
self.load_manager_from_elem(data_manager_elem, tool_path=tool_path)

def load_manager_from_elem(self, data_manager_elem, tool_path=None, add_manager=True):
try:
data_manager = DataManager(self, data_manager_elem, tool_path=tool_path)
except IOError as e:
if e.errno == errno.ENOENT:
# File does not exist
return None
except Exception as e:
log.error("Error loading data_manager '%s':\n%s" % (e, util.xml_to_string(data_manager_elem)))
return None
Expand Down
16 changes: 13 additions & 3 deletions lib/galaxy/tools/loader_directory.py
Expand Up @@ -19,6 +19,7 @@
LOAD_FAILURE_ERROR = "Failed to load tool with path %s."
TOOL_LOAD_ERROR = object()
TOOL_REGEX = re.compile(r"<tool\s")
DATA_MANAGER_REGEX = re.compile(r"\stool_type=\"manage_data\"")

YAML_EXTENSIONS = [".yaml", ".yml", ".json"]
CWL_EXTENSIONS = YAML_EXTENSIONS + [".cwl"]
Expand Down Expand Up @@ -153,8 +154,7 @@ def looks_like_a_tool(path_or_uri_like, invalid_names=[], enable_beta_formats=Fa
return looks


def looks_like_a_tool_xml(path):
"""Quick check to see if a file looks like it may be a Galaxy XML tool file."""
def looks_like_xml(path, regex=TOOL_REGEX):
full_path = os.path.abspath(path)

if not full_path.endswith(".xml"):
Expand All @@ -172,12 +172,22 @@ def looks_like_a_tool_xml(path):

with open(path, "r") as f:
start_contents = f.read(5 * 1024)
if TOOL_REGEX.search(start_contents):
if regex.search(start_contents):
return True

return False


def looks_like_a_tool_xml(path):
"""Quick check to see if a file looks like it may be a Galaxy XML tool file."""
return looks_like_xml(path=path, regex=TOOL_REGEX)


def looks_like_a_data_manager_xml(path):
"""Quick check to see if a file looks like it may be a Galaxy data manager XML file."""
return looks_like_xml(path=path, regex=DATA_MANAGER_REGEX)


def is_a_yaml_with_class(path, classes):
"""Determine if a file is a valid YAML with a supplied ``class`` entry."""
if not _has_extension(path, YAML_EXTENSIONS):
Expand Down

0 comments on commit d710bb8

Please sign in to comment.