Skip to content

Commit e4a9749

Browse files
authored
Merge pull request #980 from mvdbeek/figure_out_extended_base
Make container_register build files with headers and include base_image
2 parents 2b659c9 + 1097677 commit e4a9749

4 files changed

Lines changed: 40 additions & 19 deletions

File tree

planemo/commands/cmd_container_register.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import string
44

55
import click
6+
from galaxy.tool_util.deps.mulled.mulled_build import (
7+
base_image_for_targets,
8+
DEFAULT_BASE_IMAGE,
9+
)
610
from galaxy.tool_util.deps.mulled.util import (
711
conda_build_target_str,
812
quay_repository,
@@ -23,7 +27,10 @@
2327
REGISTERY_TARGET_NAME = "multi-package-containers"
2428
REGISTERY_TARGET_PATH = "combinations"
2529
REGISTERY_REPOSITORY = "BioContainers/multi-package-containers"
26-
DEFAULT_MESSAGE = "Add container $hash.\n**Hash**: $hash\n\n**Packages**:\n$packages\n\n**For** :\n$tools\n\nGenerated with Planemo."
30+
DEFAULT_MESSAGE = "Add container $hash.\n**Hash**: $hash\n\n**Packages**:\n$packages\nBase Image:$base_image\n\n"
31+
DEFAULT_MESSAGE += "**For** :\n$tools\n\nGenerated with Planemo."
32+
CONTENTS = "#targets\tbase_image\timage_build\n$targets\t$base_image\t$image_build\n"
33+
BIOCONTAINERS_PLATFORM = 'linux-64'
2734

2835

2936
@click.command('container_register')
@@ -80,7 +87,7 @@ def cli(ctx, paths, **kwds):
8087
mulled_targets_str = "- " + "\n- ".join(map(conda_build_target_str, mulled_targets))
8188
best_practice_requirements = True
8289
for conda_target in conda_targets:
83-
best_hit, exact = best_practice_search(conda_target, conda_context=conda_context)
90+
best_hit, exact = best_practice_search(conda_target, conda_context=conda_context, platform=BIOCONTAINERS_PLATFORM)
8491
if not best_hit:
8592
ctx.log("Target [%s] is not available in best practice channels - skipping" % conda_target)
8693
best_practice_requirements = False
@@ -92,6 +99,13 @@ def cli(ctx, paths, **kwds):
9299
if not best_practice_requirements:
93100
continue
94101

102+
base_image = DEFAULT_BASE_IMAGE
103+
for conda_target in conda_targets:
104+
base_image = base_image_for_targets([conda_target], conda_context=conda_context)
105+
if base_image != DEFAULT_BASE_IMAGE:
106+
ctx.log("%s requires '%s' as base image" % (conda_target, base_image))
107+
break
108+
95109
if len(mulled_targets) < 1:
96110
ctx.log("Skipping registration, no targets discovered.")
97111
continue
@@ -114,14 +128,14 @@ def cli(ctx, paths, **kwds):
114128
ctx.vlog("Found matching open pull request for [%s], skipping" % name)
115129
continue
116130

117-
registry_target.write_targets(ctx, target_filename, mulled_targets)
131+
registry_target.write_targets(ctx, target_filename, mulled_targets, tag, base_image)
118132
tools_str = "\n".join(map(lambda p: "- " + os.path.basename(p), tool_paths))
119-
registry_target.handle_pull_request(ctx, name, target_filename, mulled_targets_str, tools_str, **kwds)
133+
registry_target.handle_pull_request(ctx, name, target_filename, mulled_targets_str, tools_str, base_image, **kwds)
120134
combinations_added += 1
121135

122136

123137
class RegistryTarget(object):
124-
"""Abstraction around mulled container registery (both directory and Github repo)."""
138+
"""Abstraction around mulled container registry (both directory and Github repo)."""
125139

126140
def __init__(self, ctx, **kwds):
127141
output_directory = kwds["output_directory"]
@@ -152,13 +166,14 @@ def has_pull_request_for(self, name):
152166

153167
return has_pr
154168

155-
def handle_pull_request(self, ctx, name, target_filename, packages_str, tools_str, **kwds):
169+
def handle_pull_request(self, ctx, name, target_filename, packages_str, tools_str, base_image, **kwds):
156170
if self.do_pull_request:
157171
message = kwds["message"]
158172
message = string.Template(message).safe_substitute({
159173
"hash": name,
160174
"packages": packages_str,
161175
"tools": tools_str,
176+
"base_image": base_image,
162177
})
163178
branch_name = name.replace(":", "-")
164179
branch(ctx, self.target_repository, branch_name, from_branch="master")
@@ -168,11 +183,16 @@ def handle_pull_request(self, ctx, name, target_filename, packages_str, tools_st
168183
push(ctx, self.target_repository, os.environ.get("GITHUB_USER"), branch_name, force=force_push)
169184
pull_request(ctx, self.target_repository, message=message)
170185

171-
def write_targets(self, ctx, target_filename, mulled_targets):
186+
def write_targets(self, ctx, target_filename, mulled_targets, tag, base_image):
172187
with open(target_filename, "w") as f:
173-
contents = to_target_str(mulled_targets)
174-
f.write("%s\n" % contents)
175-
ctx.log("Wrote requirements [%s] to file [%s]" % (contents, target_filename))
188+
targets = to_target_str(mulled_targets)
189+
f.write(string.Template(CONTENTS).safe_substitute(
190+
targets=targets,
191+
base_image=base_image,
192+
image_build=tag
193+
)
194+
)
195+
ctx.log("Wrote requirements [%s] to file [%s]" % (targets, target_filename))
176196

177197

178198
def to_target_str(targets):

planemo/conda.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def tool_source_conda_targets(tool_source):
140140
best_practice_search_first = threading.local()
141141

142142

143-
def best_practice_search(conda_target, conda_context=None):
143+
def best_practice_search(conda_target, conda_context=None, platform=None):
144144
# Call it in offline mode after the first time.
145145
try:
146146
best_practice_search_first.previously_called
@@ -152,7 +152,13 @@ def best_practice_search(conda_target, conda_context=None):
152152

153153
if not conda_context:
154154
conda_context = conda_util.CondaContext()
155-
return conda_util.best_search_result(conda_target, conda_context=conda_context, channels_override=BEST_PRACTICE_CHANNELS, offline=offline)
155+
return conda_util.best_search_result(
156+
conda_target,
157+
conda_context=conda_context,
158+
channels_override=BEST_PRACTICE_CHANNELS,
159+
offline=offline,
160+
platform=platform,
161+
)
156162

157163

158164
__all__ = (

planemo/mulled.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from galaxy.tool_util.deps.mulled.util import build_target
1515

1616
from planemo.conda import collect_conda_target_lists
17-
from planemo.io import IS_OS_X, shell
17+
from planemo.io import shell
1818

1919

2020
def conda_to_mulled_targets(conda_targets):
@@ -56,11 +56,6 @@ def build_mull_target_kwds(ctx, **kwds):
5656
conda_version = kwds.get("mulled_conda_version", None)
5757
if conda_version is not None:
5858
target_kwds["conda_version"] = conda_version
59-
else:
60-
# Hack to workaround a bug with osxfs + Conda 4.2 - remove
61-
# when container gets upgraded to 4.3
62-
if IS_OS_X:
63-
target_kwds["conda_version"] = "4.3"
6459
return target_kwds
6560

6661

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cwltool==1.0.20191225192155
77
docutils
88
ephemeris>=0.10.3
99
galaxy-containers
10-
galaxy-tool-util>=20.1.0.dev0
10+
galaxy-tool-util>=20.1.0.dev2
1111
glob2
1212
gxformat2>=0.8.0
1313
jinja2

0 commit comments

Comments
 (0)