Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions planemo/commands/cmd_container_register.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
"""Module describing the planemo ``container_register`` command."""
import os
import string

import click

from galaxy.tools.deps.mulled.util import quay_repository, v2_image_name
from galaxy.tools.deps.mulled.util import conda_build_target_str, quay_repository, v2_image_name

from planemo import options
from planemo.cli import command_function
from planemo.conda import best_practice_search, collect_conda_target_lists
from planemo.conda import best_practice_search, collect_conda_target_lists_and_tool_paths
from planemo.git import add, branch, commit, push
from planemo.github_util import clone_fork_branch, get_repository_object, pull_request
from planemo.mulled import conda_to_mulled_targets

REGISTERY_TARGET_NAME = "multi-package-containers"
REGISTERY_TARGET_PATH = "combinations"
REGISTERY_REPOSITORY = "jmchilton/multi-package-containers"
DEFAULT_MESSAGE = "Add %s (generated with Planemo)."
DEFAULT_MESSAGE = "Add container $hash.\n**Hash**: $hash\n\n**Packages**:\n$packages\n\n**For** :\n$tools\n\nGenerated with Planemo."


@click.command('container_register')
Expand Down Expand Up @@ -63,9 +64,11 @@ def cli(ctx, paths, **kwds):
registry_target = RegistryTarget(ctx, **kwds)

combinations_added = 0
for conda_targets in collect_conda_target_lists(ctx, paths, recursive=kwds["recursive"]):
conda_targets_list, tool_paths_list = collect_conda_target_lists_and_tool_paths(ctx, paths, recursive=kwds["recursive"])
for conda_targets, tool_paths in zip(conda_targets_list, tool_paths_list):
ctx.vlog("Handling conda_targets [%s]" % conda_targets)
mulled_targets = conda_to_mulled_targets(conda_targets)
mulled_targets_str = "- " + "\n- ".join(map(conda_build_target_str, mulled_targets))
if len(mulled_targets) < 2:
ctx.vlog("Skipping registeration, fewer than 2 targets discovered.")
# Skip these for now, we will want to revisit this for conda-forge dependencies and such.
Expand Down Expand Up @@ -101,7 +104,8 @@ def cli(ctx, paths, **kwds):
continue

registry_target.write_targets(ctx, target_filename, mulled_targets)
registry_target.handle_pull_request(ctx, name, target_filename, **kwds)
tools_str = "\n".join(map(lambda p: "- " + os.path.basename(p), tool_paths))
registry_target.handle_pull_request(ctx, name, target_filename, mulled_targets_str, tools_str, **kwds)
combinations_added += 1


Expand Down Expand Up @@ -137,9 +141,14 @@ def has_pull_request_for(self, name):

return has_pr

def handle_pull_request(self, ctx, name, target_filename, **kwds):
def handle_pull_request(self, ctx, name, target_filename, packages_str, tools_str, **kwds):
if self.do_pull_request:
message = kwds["message"] % name
message = kwds["message"]
message = string.Template(message).safe_substitute({
"hash": name,
"packages": packages_str,
"tools": tools_str,
})
branch_name = name.replace(":", "-")
branch(ctx, self.target_repository, branch_name, from_branch="master")
add(ctx, self.target_repository, target_filename)
Expand Down
25 changes: 23 additions & 2 deletions planemo/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,35 @@ def parse_target(target_str):
def collect_conda_target_lists(ctx, paths, recursive=False, found_tool_callback=None):
"""Load CondaTarget lists from supplied artifact sources.

If a tool contains more than one requirement, the requirements will all
appear together as one list element of the output list.
"""
conda_target_lists, _ = collect_conda_target_lists_and_tool_paths(ctx, paths, recursive=recursive, found_tool_callback=found_tool_callback)
return conda_target_lists


def collect_conda_target_lists_and_tool_paths(ctx, paths, recursive=False, found_tool_callback=None):
"""Load CondaTarget lists from supplied artifact sources.

If a tool contains more than one requirement, the requirements will all
appear together as one list element of the output list.
"""
conda_target_lists = set([])
tool_paths = {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth to use defaultdict(list) here?

for (tool_path, tool_source) in yield_tool_sources_on_paths(ctx, paths, recursive=recursive, yield_load_errors=False):
if found_tool_callback:
found_tool_callback(tool_path)
conda_target_lists.add(frozenset(tool_source_conda_targets(tool_source)))
return conda_target_lists
targets = frozenset(tool_source_conda_targets(tool_source))
conda_target_lists.add(targets)
if targets not in tool_paths:
tool_paths[targets] = []
tool_paths[targets].append(tool_path)

# Turn them into lists so the order matches before returning...
conda_target_lists = list(conda_target_lists)
conda_target_tool_paths = [tool_paths[c] for c in conda_target_lists]

return conda_target_lists, conda_target_tool_paths


def tool_source_conda_targets(tool_source):
Expand Down Expand Up @@ -140,5 +160,6 @@ def best_practice_search(conda_target):
"build_conda_context",
"collect_conda_targets",
"collect_conda_target_lists",
"collect_conda_target_lists_and_tool_paths",
"tool_source_conda_targets",
)