commit/galaxy-central: jmchilton: Eliminate Galaxy dependencies from lib/galaxy/tools/loader.py.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/ae1a6cb7f4aa/ Changeset: ae1a6cb7f4aa User: jmchilton Date: 2014-10-06 13:24:53+00:00 Summary: Eliminate Galaxy dependencies from lib/galaxy/tools/loader.py. Should allow for reuse in command-line tools that operate on Galaxy tools. Updates for targetting Python 2.6+. Affected #: 1 file diff -r 8f746975db66785dcec2ef16f943052d767b01d4 -r ae1a6cb7f4aae2ee7746fdee01d83d96cff5a0a2 lib/galaxy/tools/loader.py --- a/lib/galaxy/tools/loader.py +++ b/lib/galaxy/tools/loader.py @@ -1,10 +1,8 @@ -from __future__ import with_statement +from xml.etree import ElementTree, ElementInclude from copy import deepcopy import os -from galaxy.util import parse_xml - def load_tool(path): """ @@ -16,7 +14,7 @@ _import_macros(root, path) # Expand xml macros - macro_dict = _macros_of_type(root, 'xml', lambda el: list(el.getchildren())) + macro_dict = _macros_of_type(root, 'xml', lambda el: list(el)) _expand_macros([root], macro_dict) # Expand tokens @@ -42,7 +40,7 @@ """ Load raw (no macro expansion) tree representation of tool represented at the specified path. """ - tree = parse_xml(path) + tree = _parse_xml(path) return tree @@ -54,7 +52,7 @@ def _import_macros(root, path): tool_dir = os.path.dirname(path) macros_el = _macros_el(root) - if macros_el: + if macros_el is not None: macro_els = _load_macros(macros_el, tool_dir) _xml_set_children(macros_el, macro_els) @@ -66,7 +64,7 @@ def _macros_of_type(root, type, el_func): macros_el = root.find('macros') macro_dict = {} - if macros_el: + if macros_el is not None: macro_els = macros_el.findall('macro') macro_dict = dict([(macro_el.get("name"), el_func(macro_el)) \ for macro_el in macro_els \ @@ -88,7 +86,7 @@ new_value = _expand_tokens_str(value, tokens) if not (new_value is value): element.attrib[key] = new_value - _expand_tokens(list(element.getchildren()), tokens) + _expand_tokens(list(element), tokens) def _expand_tokens_str(str, tokens): @@ -129,7 +127,7 @@ def _expand_yield_statements(macro_def, expand_el): yield_els = [yield_el for macro_def_el in macro_def for yield_el in macro_def_el.findall('.//yield')] - expand_el_children = expand_el.getchildren() + expand_el_children = list(expand_el) macro_def_parent_map = \ dict((c, p) for macro_def_el in macro_def for p in macro_def_el.getiterator() for c in p) @@ -151,7 +149,7 @@ macro_els = [] # attribute typed macro - if macros_el: + if macros_el is not None: macro_els = macros_el.findall("macro") for macro in macro_els: if 'type' not in macro.attrib: @@ -163,7 +161,7 @@ typed_tag = ['template', 'xml', 'token'] for tag in typed_tag: macro_els = [] - if macros_el: + if macros_el is not None: macro_els = macros_el.findall(tag) for macro_el in macro_els: macro_el.attrib['type'] = tag @@ -188,7 +186,7 @@ def _imported_macro_paths_from_el(macros_el): imported_macro_paths = [] macro_import_els = [] - if macros_el: + if macros_el is not None: macro_import_els = macros_el.findall("import") for macro_import_el in macro_import_els: raw_import_path = macro_import_el.text @@ -199,13 +197,13 @@ def _load_macro_file(path, tool_dir): - tree = parse_xml(path) + tree = _parse_xml(path) root = tree.getroot() return _load_macros(root, tool_dir) def _xml_set_children(element, new_children): - for old_child in element.getchildren(): + for old_child in element: element.remove(old_child) for i, new_child in enumerate(new_children): element.insert(i, new_child) @@ -216,7 +214,7 @@ parent_el = parent_map[query] matching_index = -1 #for index, el in enumerate(parent_el.iter('.')): ## Something like this for newer implementation - for index, el in enumerate(parent_el.getchildren()): + for index, el in enumerate(list(parent_el)): if el == query: matching_index = index break @@ -226,3 +224,10 @@ current_index += 1 parent_el.insert(current_index, deepcopy(target)) parent_el.remove(query) + + +def _parse_xml(fname): + tree = ElementTree.parse(fname) + root = tree.getroot() + ElementInclude.include(root) + return tree Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org