snakemake-software-deployment-plugin-container 0.7.4__tar.gz → 0.7.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/CHANGELOG.md +15 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/PKG-INFO +2 -2
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/pyproject.toml +2 -2
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/src/snakemake_software_deployment_plugin_container/__init__.py +99 -27
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/tests/test_plugin.py +52 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/.github/workflows/ci.yml +0 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/.github/workflows/conventional-prs.yml +0 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/.github/workflows/release-please.yml +0 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/.gitignore +0 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/LICENSE +0 -0
- {snakemake_software_deployment_plugin_container-0.7.4 → snakemake_software_deployment_plugin_container-0.7.6}/README.md +0 -0
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.7.6](https://github.com/snakemake/snakemake-software-deployment-plugin-container/compare/v0.7.5...v0.7.6) (2026-11-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* require snakemake-interface-common 1.24.1 for list settings ([#32](https://github.com/snakemake/snakemake-software-deployment-plugin-container/issues/32)) ([f4dffda](https://github.com/snakemake/snakemake-software-deployment-plugin-container/commit/f4dffda66051569b5fcb44a54a0e84ea2526b053))
|
|
9
|
+
* run apptainer jobs from the pulled SIF and keep local images as is ([#31](https://github.com/snakemake/snakemake-software-deployment-plugin-container/issues/31)) ([7a561bd](https://github.com/snakemake/snakemake-software-deployment-plugin-container/commit/7a561bd859d44a4d23115889c499387d6223c5a7))
|
|
10
|
+
|
|
11
|
+
## [0.7.5](https://github.com/snakemake/snakemake-software-deployment-plugin-container/compare/v0.7.4...v0.7.5) (2026-09-10)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* specify UDOCKER_DIR with udocker run ([59a66f4](https://github.com/snakemake/snakemake-software-deployment-plugin-container/commit/59a66f4924059ad3b3c84853d8cd7a4173b4bfb6))
|
|
17
|
+
|
|
3
18
|
## [0.7.4](https://github.com/snakemake/snakemake-software-deployment-plugin-container/compare/v0.7.3...v0.7.4) (2026-09-10)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: snakemake-software-deployment-plugin-container
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.6
|
|
4
4
|
Project-URL: repository, https://github.com/snakemake/snakemake-software-deployment-plugin-container
|
|
5
5
|
Project-URL: documentation, https://snakemake.github.io/snakemake-plugin-catalog/plugins/software-deployment/container.html
|
|
6
6
|
Author-email: Ben Carrillo <ben.uzh@pm.me>, Johannes Köster <johannes.koester@uni-due.de>
|
|
7
7
|
License-File: LICENSE
|
|
8
8
|
Requires-Python: <4.0,>=3.11
|
|
9
|
-
Requires-Dist: snakemake-interface-common<2.0.0,>=1.
|
|
9
|
+
Requires-Dist: snakemake-interface-common<2.0.0,>=1.24.1
|
|
10
10
|
Requires-Dist: snakemake-interface-software-deployment-plugins<1.0,>=0.19.2
|
|
11
11
|
Requires-Dist: udocker<2.0.0,>=1.3.17
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "snakemake-software-deployment-plugin-container"
|
|
3
|
-
version = "0.7.
|
|
3
|
+
version = "0.7.6"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name = "Ben Carrillo", email = "ben.uzh@pm.me" },
|
|
6
6
|
{ name = "Johannes Köster", email = "johannes.koester@uni-due.de" }
|
|
@@ -9,7 +9,7 @@ description = ""
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11,<4.0"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"snakemake-interface-common (>=1.
|
|
12
|
+
"snakemake-interface-common (>=1.24.1,<2.0.0)",
|
|
13
13
|
"snakemake-interface-software-deployment-plugins (>=0.19.2,<1.0)",
|
|
14
14
|
"udocker (>=1.3.17,<2.0.0)",
|
|
15
15
|
]
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
from typing import ClassVar
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from abc import abstractmethod
|
|
4
|
-
from snakemake_interface_software_deployment_plugins import
|
|
4
|
+
from snakemake_interface_software_deployment_plugins import (
|
|
5
|
+
CacheableEnvBase,
|
|
6
|
+
DeployableEnvBase,
|
|
7
|
+
)
|
|
5
8
|
import re
|
|
6
9
|
|
|
7
10
|
__author__ = "ben carrillo"
|
|
@@ -13,7 +16,7 @@ import os
|
|
|
13
16
|
import shlex
|
|
14
17
|
from dataclasses import dataclass, field
|
|
15
18
|
from os import getcwd
|
|
16
|
-
from shutil import which
|
|
19
|
+
from shutil import rmtree, which
|
|
17
20
|
from typing import Iterable, List
|
|
18
21
|
|
|
19
22
|
from snakemake_interface_software_deployment_plugins.settings import (
|
|
@@ -95,7 +98,7 @@ class EnvSpec(EnvSpecBase):
|
|
|
95
98
|
|
|
96
99
|
|
|
97
100
|
# All errors should be wrapped with snakemake-interface-common.errors.WorkflowError
|
|
98
|
-
class Env(DeployableEnvBase, EnvBase):
|
|
101
|
+
class Env(CacheableEnvBase, DeployableEnvBase, EnvBase):
|
|
99
102
|
# image_repo is the de-referenced repository from where the image was obtained
|
|
100
103
|
image_repo: str
|
|
101
104
|
settings: Settings
|
|
@@ -120,7 +123,7 @@ class Env(DeployableEnvBase, EnvBase):
|
|
|
120
123
|
if not self.runtime_manager.is_setup:
|
|
121
124
|
if self.runtime_manager.setup_cmd() is not None:
|
|
122
125
|
self.run_cmd(self.runtime_manager.setup_cmd(), check=True)
|
|
123
|
-
self.runtime_manager.is_setup = True
|
|
126
|
+
self.runtime_manager.__class__.is_setup = True
|
|
124
127
|
|
|
125
128
|
# The decorator ensures that the decorated method is only called once
|
|
126
129
|
# in case multiple environments of the same kind are created.
|
|
@@ -186,27 +189,42 @@ class Env(DeployableEnvBase, EnvBase):
|
|
|
186
189
|
self.run_cmd(cmd: str) in order to ensure that it runs within eventual
|
|
187
190
|
parent environments (e.g. a container or an env module).
|
|
188
191
|
"""
|
|
192
|
+
self.deployment_path.mkdir(parents=True, exist_ok=True)
|
|
193
|
+
cached = self.cached_image_path()
|
|
194
|
+
if cached is not None and cached.exists():
|
|
195
|
+
deployed = self.runtime_manager.deployed_image_path()
|
|
196
|
+
assert deployed is not None
|
|
197
|
+
deployed.symlink_to(cached)
|
|
198
|
+
return
|
|
189
199
|
deploy_cmd = self.runtime_manager.deploy_cmd()
|
|
190
200
|
assert deploy_cmd is not None
|
|
191
|
-
self.
|
|
192
|
-
self.run_cmd(
|
|
193
|
-
deploy_cmd,
|
|
194
|
-
check=True,
|
|
195
|
-
)
|
|
201
|
+
self.run_cmd(deploy_cmd, check=True)
|
|
196
202
|
|
|
197
203
|
def remove(self) -> None:
|
|
198
204
|
"""Remove the deployed environment."""
|
|
199
|
-
if (
|
|
200
|
-
self.
|
|
201
|
-
and self.runtime_manager.deployed_image_path() is not None
|
|
202
|
-
):
|
|
203
|
-
self.runtime_manager.deployed_image_path.unlink(missing_ok=True)
|
|
205
|
+
if self.is_deployable():
|
|
206
|
+
rmtree(self.deployment_path)
|
|
204
207
|
|
|
205
208
|
def is_deployable(self) -> bool:
|
|
206
|
-
return (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
)
|
|
209
|
+
return self.runtime_manager.is_deployable()
|
|
210
|
+
|
|
211
|
+
def is_cacheable(self) -> bool:
|
|
212
|
+
return self.runtime_manager.cache_asset_name() is not None
|
|
213
|
+
|
|
214
|
+
def cached_image_path(self) -> Path | None:
|
|
215
|
+
asset = self.runtime_manager.cache_asset_name()
|
|
216
|
+
if asset is None:
|
|
217
|
+
return None
|
|
218
|
+
return self.cache_path / asset
|
|
219
|
+
|
|
220
|
+
async def get_cache_assets(self) -> Iterable[str]:
|
|
221
|
+
asset = self.runtime_manager.cache_asset_name()
|
|
222
|
+
return [] if asset is None else [asset]
|
|
223
|
+
|
|
224
|
+
async def cache_asset(self, asset: str, to_path: Path) -> None:
|
|
225
|
+
cache_cmd = self.runtime_manager.cache_cmd(to_path)
|
|
226
|
+
assert cache_cmd is not None
|
|
227
|
+
self.run_cmd(cache_cmd, check=True)
|
|
210
228
|
|
|
211
229
|
|
|
212
230
|
@dataclass
|
|
@@ -230,6 +248,20 @@ class RuntimeManager:
|
|
|
230
248
|
@abstractmethod
|
|
231
249
|
def deploy_cmd(self) -> str | None: ...
|
|
232
250
|
|
|
251
|
+
def is_deployable(self) -> bool:
|
|
252
|
+
return False
|
|
253
|
+
|
|
254
|
+
def cache_asset_name(self) -> str | None:
|
|
255
|
+
"""Name of the single file under the shared cache that holds the image,
|
|
256
|
+
or None if the runtime cannot store the image as one file."""
|
|
257
|
+
return None
|
|
258
|
+
|
|
259
|
+
def cache_cmd(self, to_path: Path) -> str | None:
|
|
260
|
+
return None
|
|
261
|
+
|
|
262
|
+
def pre_cmd(self) -> str:
|
|
263
|
+
return ""
|
|
264
|
+
|
|
233
265
|
def pre_subcommand_options(self) -> str:
|
|
234
266
|
return ""
|
|
235
267
|
|
|
@@ -248,6 +280,9 @@ class RuntimeManager:
|
|
|
248
280
|
return image_uri[9:]
|
|
249
281
|
return image_uri
|
|
250
282
|
|
|
283
|
+
def run_image(self) -> str:
|
|
284
|
+
return self.image_uri()
|
|
285
|
+
|
|
251
286
|
def subcommand(self) -> str:
|
|
252
287
|
return "run"
|
|
253
288
|
|
|
@@ -270,19 +305,30 @@ class RuntimeManager:
|
|
|
270
305
|
|
|
271
306
|
def decorate_shellcmd(self, cmd: str) -> str:
|
|
272
307
|
mountpoints = self.get_mountpoint_args()
|
|
308
|
+
pre_cmd = self.pre_cmd()
|
|
309
|
+
if pre_cmd:
|
|
310
|
+
pre_cmd += " "
|
|
273
311
|
return (
|
|
274
|
-
f"{self.env.settings.runtime}"
|
|
312
|
+
f"{pre_cmd}{self.env.settings.runtime}"
|
|
275
313
|
f" {self.pre_subcommand_options()}"
|
|
276
314
|
f" {self.subcommand()}"
|
|
277
315
|
f" {self.options()}"
|
|
278
316
|
f" {self.workdir_option()} {getcwd()!r}" # Working directory inside container
|
|
279
317
|
f" {mountpoints}"
|
|
280
|
-
f" {self.
|
|
318
|
+
f" {self.run_image()}" # Container image
|
|
281
319
|
f" {self.env.shell_executable.name}" # Shell executable
|
|
282
320
|
f" -c {shlex.quote(cmd)}" # The command to execute
|
|
283
321
|
)
|
|
284
322
|
|
|
285
323
|
|
|
324
|
+
APPTAINER_TRANSPORT = re.compile(
|
|
325
|
+
r"[a-z\.]+://|(docker-archive|docker-daemon|oci-archive|oci):"
|
|
326
|
+
)
|
|
327
|
+
# Transports that `apptainer pull` can turn into a SIF. The others (archives,
|
|
328
|
+
# the docker daemon, local files) are run as given.
|
|
329
|
+
APPTAINER_PULLABLE = re.compile(r"(library|docker|shub|oras|ipfs|https?)://")
|
|
330
|
+
|
|
331
|
+
|
|
286
332
|
class RuntimeManagerApptainer(RuntimeManager):
|
|
287
333
|
def subcommand(self) -> str:
|
|
288
334
|
return "exec"
|
|
@@ -301,18 +347,38 @@ class RuntimeManagerApptainer(RuntimeManager):
|
|
|
301
347
|
return "--bind"
|
|
302
348
|
|
|
303
349
|
def image_uri(self) -> str:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
350
|
+
image_uri = self.env.spec.image_uri
|
|
351
|
+
if (
|
|
352
|
+
APPTAINER_TRANSPORT.match(image_uri)
|
|
353
|
+
or image_uri.endswith(".sif")
|
|
354
|
+
or Path(image_uri).is_file()
|
|
355
|
+
):
|
|
356
|
+
return image_uri
|
|
357
|
+
return f"docker://{image_uri}"
|
|
307
358
|
|
|
308
|
-
def
|
|
309
|
-
return (self.
|
|
310
|
-
|
|
311
|
-
|
|
359
|
+
def is_deployable(self) -> bool:
|
|
360
|
+
return APPTAINER_PULLABLE.match(self.image_uri()) is not None
|
|
361
|
+
|
|
362
|
+
def run_image(self) -> str:
|
|
363
|
+
if self.is_deployable():
|
|
364
|
+
return str(self.deployed_image_path())
|
|
365
|
+
return self.image_uri()
|
|
366
|
+
|
|
367
|
+
def deployed_image_path(self) -> Path:
|
|
368
|
+
return self.env.deployment_path / f"{self.deployed_image_name()}.sif"
|
|
312
369
|
|
|
313
370
|
def deploy_cmd(self) -> str | None:
|
|
314
371
|
return f"apptainer pull {self.deployed_image_path()} {self.image_uri()}"
|
|
315
372
|
|
|
373
|
+
def cache_asset_name(self) -> str | None:
|
|
374
|
+
if self.is_deployable():
|
|
375
|
+
return f"{self.deployed_image_name()}.sif"
|
|
376
|
+
return None
|
|
377
|
+
|
|
378
|
+
def cache_cmd(self, to_path: Path) -> str | None:
|
|
379
|
+
# --force because the cache mechanism pre-creates to_path as empty file.
|
|
380
|
+
return f"apptainer pull --force {to_path} {self.image_uri()}"
|
|
381
|
+
|
|
316
382
|
|
|
317
383
|
class RuntimeManagerDocker(RuntimeManager):
|
|
318
384
|
def options(self) -> str:
|
|
@@ -339,6 +405,9 @@ class RuntimeManagerUdocker(RuntimeManager):
|
|
|
339
405
|
def setup_cmd(self) -> str | None:
|
|
340
406
|
return "udocker install"
|
|
341
407
|
|
|
408
|
+
def pre_cmd(self) -> str:
|
|
409
|
+
return f"UDOCKER_DIR={self.env.deployment_path}"
|
|
410
|
+
|
|
342
411
|
def pre_subcommand_options(self) -> str:
|
|
343
412
|
return "--quiet"
|
|
344
413
|
|
|
@@ -349,6 +418,9 @@ class RuntimeManagerUdocker(RuntimeManager):
|
|
|
349
418
|
options += f" --env {env_var}={os.environ[env_var]}"
|
|
350
419
|
return options
|
|
351
420
|
|
|
421
|
+
def is_deployable(self) -> bool:
|
|
422
|
+
return True
|
|
423
|
+
|
|
352
424
|
def deployed_image_path(self) -> Path | None:
|
|
353
425
|
return None
|
|
354
426
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
from collections.abc import Set
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from types import SimpleNamespace
|
|
2
4
|
from typing import Optional, Type
|
|
3
5
|
import shutil
|
|
4
6
|
import os
|
|
@@ -21,6 +23,7 @@ from snakemake_software_deployment_plugin_container import (
|
|
|
21
23
|
EnvSpec,
|
|
22
24
|
Env,
|
|
23
25
|
Runtime,
|
|
26
|
+
RuntimeManagerApptainer,
|
|
24
27
|
)
|
|
25
28
|
|
|
26
29
|
|
|
@@ -105,3 +108,52 @@ class TestDockerContainer(TestBase):
|
|
|
105
108
|
self,
|
|
106
109
|
) -> Optional[SoftwareDeploymentSettingsBase]:
|
|
107
110
|
return Settings(runtime=Runtime.DOCKER)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def apptainer_manager(image_uri: str, deployment_path: Path) -> RuntimeManagerApptainer:
|
|
114
|
+
env = SimpleNamespace(
|
|
115
|
+
spec=SimpleNamespace(image_uri=image_uri),
|
|
116
|
+
deployment_path=deployment_path,
|
|
117
|
+
settings=SimpleNamespace(runtime=Runtime.APPTAINER, mountpoints=[]),
|
|
118
|
+
tempdir=Path("/tmp/x"),
|
|
119
|
+
mountpoints=[],
|
|
120
|
+
envvars=[],
|
|
121
|
+
shell_executable=Path("/bin/bash"),
|
|
122
|
+
)
|
|
123
|
+
return RuntimeManagerApptainer(env)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_apptainer_exec_uses_deployed_sif(tmp_path):
|
|
127
|
+
manager = apptainer_manager("python:3.12-slim", tmp_path)
|
|
128
|
+
sif = manager.deployed_image_path()
|
|
129
|
+
# the SIF name keeps the full tag
|
|
130
|
+
assert sif == tmp_path / "python_3.12-slim.sif"
|
|
131
|
+
assert manager.is_deployable()
|
|
132
|
+
assert manager.deploy_cmd() == f"apptainer pull {sif} docker://python:3.12-slim"
|
|
133
|
+
assert manager.cache_asset_name() == "python_3.12-slim.sif"
|
|
134
|
+
assert (
|
|
135
|
+
manager.cache_cmd(Path("/cache/x.part"))
|
|
136
|
+
== "apptainer pull --force /cache/x.part docker://python:3.12-slim"
|
|
137
|
+
)
|
|
138
|
+
assert f" {sif} bash -c " in manager.decorate_shellcmd("echo hi")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_apptainer_local_sif_is_used_as_is(tmp_path):
|
|
142
|
+
manager = apptainer_manager("/data/img.sif", tmp_path)
|
|
143
|
+
assert not manager.is_deployable()
|
|
144
|
+
assert manager.cache_asset_name() is None
|
|
145
|
+
assert " /data/img.sif bash -c " in manager.decorate_shellcmd("echo hi")
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_apptainer_transports(tmp_path):
|
|
149
|
+
manager = apptainer_manager("oras://registry/img:1.0", tmp_path)
|
|
150
|
+
assert manager.is_deployable()
|
|
151
|
+
sif = manager.deployed_image_path()
|
|
152
|
+
assert manager.deploy_cmd() == f"apptainer pull {sif} oras://registry/img:1.0"
|
|
153
|
+
|
|
154
|
+
# apptainer pull cannot fetch these, so they are run as given
|
|
155
|
+
manager = apptainer_manager("docker-archive:/data/img.tar", tmp_path)
|
|
156
|
+
assert not manager.is_deployable()
|
|
157
|
+
assert " docker-archive:/data/img.tar bash -c " in manager.decorate_shellcmd(
|
|
158
|
+
"echo hi"
|
|
159
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|