Skip to content

Commit 73256b4

Browse files
committed
galaxy-tool-util: use a better location for the container_image_cache_path
1 parent a36a9e9 commit 73256b4

File tree

3 files changed

+77
-11
lines changed

3 files changed

+77
-11
lines changed

cwltool/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ def main(
12891289
find_default_container,
12901290
default_container=runtimeContext.default_container,
12911291
use_biocontainers=args.beta_use_biocontainers,
1292+
container_image_cache_path=args.beta_dependencies_directory,
12921293
)
12931294

12941295
(out, status) = real_executor(
@@ -1410,10 +1411,13 @@ def find_default_container(
14101411
builder: HasReqsHints,
14111412
default_container: Optional[str] = None,
14121413
use_biocontainers: Optional[bool] = None,
1414+
container_image_cache_path: Optional[str] = None,
14131415
) -> Optional[str]:
14141416
"""Find a container."""
14151417
if not default_container and use_biocontainers:
1416-
default_container = get_container_from_software_requirements(use_biocontainers, builder)
1418+
default_container = get_container_from_software_requirements(
1419+
use_biocontainers, builder, container_image_cache_path
1420+
)
14171421
return default_container
14181422

14191423

cwltool/software_requirements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_dependencies(builder: HasReqsHints) -> ToolRequirements:
136136

137137

138138
def get_container_from_software_requirements(
139-
use_biocontainers: bool, builder: HasReqsHints
139+
use_biocontainers: bool, builder: HasReqsHints, container_image_cache_path: Optional[str] = "."
140140
) -> Optional[str]:
141141
if use_biocontainers:
142142
ensure_galaxy_lib_available()
@@ -147,7 +147,7 @@ def get_container_from_software_requirements(
147147
app_info: AppInfo = AppInfo(
148148
involucro_auto_init=True,
149149
enable_mulled_containers=True,
150-
container_image_cache_path=".",
150+
container_image_cache_path=container_image_cache_path,
151151
)
152152
container_registry: ContainerRegistry = ContainerRegistry(app_info)
153153
requirements = get_dependencies(builder)

tests/test_dependencies.py

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Tests of satisfying SoftwareRequirement via dependencies."""
22
import os
3+
import tempfile
34
from pathlib import Path
45
from shutil import which
56
from types import ModuleType
6-
from typing import Optional
7-
7+
from typing import Optional, Tuple, Callable
8+
from getpass import getuser
89
import pytest
910

1011
from cwltool.context import LoadingContext
@@ -26,7 +27,15 @@ def test_biocontainers(tmp_path: Path) -> None:
2627
wflow = get_data("tests/seqtk_seq.cwl")
2728
job = get_data("tests/seqtk_seq_job.json")
2829
error_code, _, _ = get_main_output(
29-
["--outdir", str(tmp_path), "--beta-use-biocontainers", wflow, job]
30+
[
31+
"--outdir",
32+
str(tmp_path / "out"),
33+
"--beta-use-biocontainers",
34+
"--beta-dependencies-directory",
35+
str(tmp_path / "deps"),
36+
wflow,
37+
job,
38+
]
3039
)
3140

3241
assert error_code == 0
@@ -38,31 +47,84 @@ def test_biocontainers_resolution(tmp_path: Path) -> None:
3847
"""Confirm expected container name for --beta-use-biocontainers."""
3948
tool = load_tool(get_data("tests/seqtk_seq.cwl"), LoadingContext())
4049
assert (
41-
get_container_from_software_requirements(True, tool) == "quay.io/biocontainers/seqtk:r93--0"
50+
get_container_from_software_requirements(
51+
True, tool, container_image_cache_path=str(tmp_path)
52+
)
53+
== "quay.io/biocontainers/seqtk:r93--0"
4254
)
4355

4456

45-
@pytest.mark.skipif(not deps, reason="galaxy-tool-util is not installed")
46-
def test_bioconda(tmp_path: Path) -> None:
57+
@pytest.fixture(scope="session")
58+
def bioconda_setup(request: pytest.FixtureRequest) -> Tuple[Optional[int], str]:
59+
"""
60+
Caches the conda environment created for seqtk_seq.cwl.
61+
62+
Respects ``--basetemp`` via code copied from
63+
:py:method:`pytest.TempPathFactory.getbasetemp`.
64+
"""
65+
66+
deps_dir = request.config.cache.get("bioconda_deps", None)
67+
if deps_dir is not None and not Path(deps_dir).exists():
68+
# cache value set, but cache is gone :( ... recreate
69+
deps_dir = None
70+
71+
if deps_dir is None:
72+
given_basetemp = request.config.option.basetemp
73+
if given_basetemp is not None:
74+
basetemp = Path(os.path.abspath(str(given_basetemp))).resolve()
75+
deps_dir = basetemp / "bioconda"
76+
else:
77+
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")
78+
temproot = Path(from_env or tempfile.gettempdir()).resolve()
79+
rootdir = temproot.joinpath(f"pytest-of-{getuser() or 'unknown'}")
80+
try:
81+
rootdir.mkdir(mode=0o700, exist_ok=True)
82+
except OSError:
83+
rootdir = temproot.joinpath("pytest-of-unknown")
84+
rootdir.mkdir(mode=0o700, exist_ok=True)
85+
deps_dir = rootdir / "bioconda"
86+
request.config.cache.set("bioconda_deps", str(deps_dir))
87+
88+
deps_dirpath = Path(deps_dir)
89+
deps_dirpath.mkdir(exist_ok=True)
90+
4791
wflow = get_data("tests/seqtk_seq.cwl")
4892
job = get_data("tests/seqtk_seq_job.json")
4993
error_code, _, stderr = get_main_output(
50-
["--outdir", str(tmp_path), "--beta-conda-dependencies", "--debug", wflow, job]
94+
[
95+
"--outdir",
96+
str(deps_dirpath / "out"),
97+
"--beta-conda-dependencies",
98+
"--beta-dependencies-directory",
99+
str(deps_dirpath / "deps"),
100+
"--debug",
101+
wflow,
102+
job,
103+
]
51104
)
105+
return error_code, stderr
52106

107+
108+
@pytest.mark.skipif(not deps, reason="galaxy-tool-util is not installed")
109+
def test_bioconda(bioconda_setup: Callable[[], Tuple[Optional[int], str]]) -> None:
110+
error_code, stderr = bioconda_setup
53111
assert error_code == 0, stderr
54112

55113

56114
@pytest.mark.skipif(not deps, reason="galaxy-tool-util is not installed")
57115
@pytest.mark.skipif(not which("modulecmd"), reason="modulecmd not installed")
58-
def test_modules(monkeypatch: pytest.MonkeyPatch) -> None:
116+
def test_modules(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
59117
"""Do a basic smoke test using environment modules to satisfy a SoftwareRequirement."""
60118
wflow = get_data("tests/random_lines.cwl")
61119
job = get_data("tests/random_lines_job.json")
62120
monkeypatch.setenv("MODULEPATH", os.path.join(os.getcwd(), "tests/test_deps_env/modulefiles"))
63121
error_code, _, stderr = get_main_output(
64122
[
123+
"--outdir",
124+
str(tmp_path / "out"),
65125
"--beta-dependency-resolvers-configuration",
126+
"--beta-dependencies-directory",
127+
str(tmp_path / "deps"),
66128
"tests/test_deps_env_modules_resolvers_conf.yml",
67129
"--debug",
68130
wflow,

0 commit comments

Comments
 (0)