snakemake-software-deployment-plugin-container 0.7.5__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.
Files changed (11) hide show
  1. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/CHANGELOG.md +8 -0
  2. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/PKG-INFO +2 -2
  3. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/pyproject.toml +2 -2
  4. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/src/snakemake_software_deployment_plugin_container/__init__.py +88 -25
  5. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/tests/test_plugin.py +52 -0
  6. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/.github/workflows/ci.yml +0 -0
  7. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/.github/workflows/conventional-prs.yml +0 -0
  8. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/.github/workflows/release-please.yml +0 -0
  9. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/.gitignore +0 -0
  10. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/LICENSE +0 -0
  11. {snakemake_software_deployment_plugin_container-0.7.5 → snakemake_software_deployment_plugin_container-0.7.6}/README.md +0 -0
@@ -1,5 +1,13 @@
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
+
3
11
  ## [0.7.5](https://github.com/snakemake/snakemake-software-deployment-plugin-container/compare/v0.7.4...v0.7.5) (2026-09-10)
4
12
 
5
13
 
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: snakemake-software-deployment-plugin-container
3
- Version: 0.7.5
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.23.0
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.5"
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.23.0,<2.0.0)",
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 DeployableEnvBase
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
@@ -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.deployment_path.mkdir(parents=True, exist_ok=True)
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.is_deployable()
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
- self.settings.runtime is Runtime.UDOCKER
208
- or self.settings.runtime is Runtime.APPTAINER
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,17 @@ 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
+
233
262
  def pre_cmd(self) -> str:
234
263
  return ""
235
264
 
@@ -251,6 +280,9 @@ class RuntimeManager:
251
280
  return image_uri[9:]
252
281
  return image_uri
253
282
 
283
+ def run_image(self) -> str:
284
+ return self.image_uri()
285
+
254
286
  def subcommand(self) -> str:
255
287
  return "run"
256
288
 
@@ -283,12 +315,20 @@ class RuntimeManager:
283
315
  f" {self.options()}"
284
316
  f" {self.workdir_option()} {getcwd()!r}" # Working directory inside container
285
317
  f" {mountpoints}"
286
- f" {self.image_uri()}" # Container image
318
+ f" {self.run_image()}" # Container image
287
319
  f" {self.env.shell_executable.name}" # Shell executable
288
320
  f" -c {shlex.quote(cmd)}" # The command to execute
289
321
  )
290
322
 
291
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
+
292
332
  class RuntimeManagerApptainer(RuntimeManager):
293
333
  def subcommand(self) -> str:
294
334
  return "exec"
@@ -307,18 +347,38 @@ class RuntimeManagerApptainer(RuntimeManager):
307
347
  return "--bind"
308
348
 
309
349
  def image_uri(self) -> str:
310
- if re.match(r"[a-z\.]+://", super().image_uri()):
311
- return super().image_uri()
312
- return f"docker://{super().image_uri()}"
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}"
313
358
 
314
- def deployed_image_path(self) -> Path | None:
315
- return (self.env.deployment_path / self.deployed_image_name()).with_suffix(
316
- ".sif"
317
- )
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"
318
369
 
319
370
  def deploy_cmd(self) -> str | None:
320
371
  return f"apptainer pull {self.deployed_image_path()} {self.image_uri()}"
321
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
+
322
382
 
323
383
  class RuntimeManagerDocker(RuntimeManager):
324
384
  def options(self) -> str:
@@ -358,6 +418,9 @@ class RuntimeManagerUdocker(RuntimeManager):
358
418
  options += f" --env {env_var}={os.environ[env_var]}"
359
419
  return options
360
420
 
421
+ def is_deployable(self) -> bool:
422
+ return True
423
+
361
424
  def deployed_image_path(self) -> Path | None:
362
425
  return None
363
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
+ )