Skip to content

Commit 04238d3

Browse files
committed
Eliminate deprecated XML-based abstraction from planemo.tools.
Using ToolSource to parse out tool name and ID in shed operations nows.
1 parent 4c0f100 commit 04238d3

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

planemo/shed/__init__.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
temp_directory,
3434
)
3535
from planemo.shed2tap.base import BasePackage
36-
from planemo.tools import load_tool_elements_from_path
36+
from planemo.tools import yield_tool_sources
3737

3838
from .diff import diff_and_remove
3939
from .interface import (
@@ -418,7 +418,7 @@ def _diff_in(ctx, working, realized_repository, **kwds):
418418
return exit
419419

420420

421-
def shed_repo_config(path, name=None):
421+
def shed_repo_config(ctx, path, name=None):
422422
shed_yaml_path = os.path.join(path, SHED_CONFIG_NAME)
423423
config = {}
424424
if os.path.exists(shed_yaml_path):
@@ -427,7 +427,7 @@ def shed_repo_config(path, name=None):
427427

428428
if config is None: # yaml may yield None
429429
config = {}
430-
_expand_raw_config(config, path, name=name)
430+
_expand_raw_config(ctx, config, path, name=name)
431431
return config
432432

433433

@@ -504,7 +504,7 @@ def find_repository_id(ctx, shed_context, path, **kwds):
504504
repo_config = kwds.get("config", None)
505505
if repo_config is None:
506506
name = kwds.get("name", None)
507-
repo_config = shed_repo_config(path, name=name)
507+
repo_config = shed_repo_config(ctx, path, name=name)
508508
name = repo_config["name"]
509509
find_kwds = kwds.copy()
510510
if "name" in find_kwds:
@@ -537,7 +537,7 @@ def _owner(ctx, repo_config, shed_context=None, **kwds):
537537
return owner
538538

539539

540-
def _expand_raw_config(config, path, name=None):
540+
def _expand_raw_config(ctx, config, path, name=None):
541541
name_input = name
542542
if "name" not in config:
543543
config["name"] = name
@@ -554,7 +554,7 @@ def _expand_raw_config(config, path, name=None):
554554
if auto_tool_repos and name_input:
555555
raise Exception(AUTO_NAME_CONFLICT_MESSAGE)
556556
if auto_tool_repos:
557-
repos = _build_auto_tool_repos(path, config, auto_tool_repos)
557+
repos = _build_auto_tool_repos(ctx, path, config, auto_tool_repos)
558558
if suite_config:
559559
if repos is None:
560560
repos = odict.odict()
@@ -571,15 +571,15 @@ def _expand_raw_config(config, path, name=None):
571571
config["repositories"] = repos
572572

573573

574-
def _build_auto_tool_repos(path, config, auto_tool_repos):
574+
def _build_auto_tool_repos(ctx, path, config, auto_tool_repos):
575575
default_include = config.get("include", ["**"])
576-
tool_els = list(load_tool_elements_from_path(path, recursive=True))
577-
paths = list(map(lambda pair: pair[0], tool_els))
576+
tool_source_pairs = list(yield_tool_sources(ctx, path, recursive=True))
577+
paths = list(map(lambda pair: pair[0], tool_source_pairs))
578578
excludes = _shed_config_excludes(config)
579579

580-
def _build_repository(tool_path, tool_el):
581-
tool_id = tool_el.getroot().get("id").lower()
582-
tool_name = tool_el.getroot().get("name")
580+
def _build_repository(tool_path, tool_source):
581+
tool_id = tool_source.parse_id().lower()
582+
tool_name = tool_source.parse_name()
583583
template_vars = dict(
584584
tool_id=tool_id,
585585
tool_name=tool_name,
@@ -600,8 +600,8 @@ def _build_repository(tool_path, tool_el):
600600
return repo_dict
601601

602602
repos = odict.odict()
603-
for tool_path, tool_el in tool_els:
604-
repository_config = _build_repository(tool_path, tool_el)
603+
for tool_path, tool_source in tool_source_pairs:
604+
repository_config = _build_repository(tool_path, tool_source)
605605
repository_name = repository_config["name"]
606606
repos[repository_name] = repository_config
607607
return repos
@@ -744,7 +744,7 @@ def find_raw_repositories(ctx, paths, **kwds):
744744
"""Return a list of "raw" repository objects for each repo on paths."""
745745
raw_repo_objects = []
746746
for path in paths:
747-
raw_repo_objects.extend(_find_raw_repositories(path, **kwds))
747+
raw_repo_objects.extend(_find_raw_repositories(ctx, path, **kwds))
748748
return raw_repo_objects
749749

750750

@@ -804,7 +804,7 @@ def _realize_effective_repositories(ctx, path, **kwds):
804804
code repository but are published to the tool shed as one repository per
805805
tool).
806806
"""
807-
raw_repo_objects = _find_raw_repositories(path, **kwds)
807+
raw_repo_objects = _find_raw_repositories(ctx, path, **kwds)
808808
failed = False
809809
with temp_directory() as base_dir:
810810
for raw_repo_object in raw_repo_objects:
@@ -904,7 +904,7 @@ def _path_on_disk(ctx, path):
904904
yield git_repo
905905

906906

907-
def _find_raw_repositories(path, **kwds):
907+
def _find_raw_repositories(ctx, path, **kwds):
908908
name = kwds.get("name", None)
909909
recursive = kwds.get("recursive", False)
910910

@@ -916,7 +916,7 @@ def _find_raw_repositories(path, **kwds):
916916
if len(shed_file_dirs) == 1:
917917
shed_file_dir = shed_file_dirs[0]
918918
try:
919-
config = shed_repo_config(shed_file_dir, name=name)
919+
config = shed_repo_config(ctx, shed_file_dir, name=name)
920920
except Exception as e:
921921
error_message = PARSING_PROBLEM % (shed_file_dir, e)
922922
exception = RuntimeError(error_message)
@@ -932,10 +932,10 @@ def _find_raw_repositories(path, **kwds):
932932
raw_dirs = shed_file_dirs or [path]
933933
kwds_copy = kwds.copy()
934934
kwds_copy["name"] = name
935-
return _build_raw_repo_objects(raw_dirs, **kwds_copy)
935+
return _build_raw_repo_objects(ctx, raw_dirs, **kwds_copy)
936936

937937

938-
def _build_raw_repo_objects(raw_dirs, **kwds):
938+
def _build_raw_repo_objects(ctx, raw_dirs, **kwds):
939939
"""
940940
From specific directories with .shed.yml files or specified directly from
941941
the command-line build abstract description of directories that should be
@@ -949,7 +949,7 @@ def _build_raw_repo_objects(raw_dirs, **kwds):
949949
raw_repo_objects = []
950950
for raw_dir in raw_dirs:
951951
try:
952-
config = shed_repo_config(raw_dir, name=name)
952+
config = shed_repo_config(ctx, raw_dir, name=name)
953953
except Exception as e:
954954
error_message = PARSING_PROBLEM % (raw_dir, e)
955955
exception = RuntimeError(error_message)

planemo/tools.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ def load_tool_sources_from_path(path, recursive, register_load_errors=False):
6060
)
6161

6262

63-
# TODO: replace usage of this with tool source so planemo
64-
# defers XML details to galaxy-lib.
65-
def load_tool_elements_from_path(path, recursive, register_load_errors=False):
66-
"""Generator for tool XML elements on a path."""
67-
return loader_directory.load_tool_elements_from_path(
68-
path,
69-
_load_exception_handler,
70-
recursive=recursive,
71-
register_load_errors=register_load_errors,
72-
)
73-
74-
7563
def _load_exception_handler(path, exc_info):
7664
error("Error loading tool with path %s" % path)
7765
traceback.print_exception(*exc_info, limit=1, file=sys.stderr)
@@ -90,7 +78,6 @@ def _is_tool_source(ctx, tool_path, tool_source):
9078

9179

9280
__all__ = (
93-
"load_tool_elements_from_path",
9481
"is_tool_load_error",
9582
"load_tool_sources_from_path",
9683
"yield_tool_sources",

tests/test_shed_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_find_category_ids():
6363
def test_create_simple():
6464
with mock_shed_context() as shed_context:
6565
path = os.path.join(TEST_REPOS_DIR, "single_tool")
66-
repo_config = shed.shed_repo_config(path)
66+
repo_config = shed.shed_repo_config(shed_context, path)
6767
create_response = shed.create_repository_for(
6868
None,
6969
shed_context.tsi,

0 commit comments

Comments
 (0)