Skip to content

Commit bb41504

Browse files
authored
cache relative paths (#1685)
* cachedir: always calculate checksums
1 parent fb5774b commit bb41504

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

cwltool/argparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def __init__(
831831
nargs: Any = None,
832832
**kwargs: Any,
833833
) -> None:
834-
"""Intialize."""
834+
"""Initialize."""
835835
super().__init__(option_strings, dest, **kwargs)
836836
self._called = False
837837

cwltool/command_line_tool.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,18 @@ def job(
850850
_check_adjust = partial(
851851
check_adjust, self.path_check_mode.value, cachebuilder
852852
)
853+
_checksum = partial(
854+
compute_checksums,
855+
runtimeContext.make_fs_access(runtimeContext.basedir),
856+
)
853857
visit_class(
854858
[cachebuilder.files, cachebuilder.bindings],
855859
("File", "Directory"),
856860
_check_adjust,
857861
)
862+
visit_class(
863+
[cachebuilder.files, cachebuilder.bindings], ("File"), _checksum
864+
)
858865

859866
cmdline = flatten(
860867
list(map(cachebuilder.generate_arg, cachebuilder.bindings))
@@ -895,14 +902,19 @@ def calc_checksum(location: str) -> Optional[str]:
895902
return cast(Optional[str], e["checksum"])
896903
return None
897904

905+
def remove_prefix(s: str, prefix: str) -> str:
906+
# replace with str.removeprefix when Python 3.9+
907+
return s[len(prefix) :] if s.startswith(prefix) else s
908+
898909
for location, fobj in cachebuilder.pathmapper.items():
899910
if fobj.type == "File":
900911
checksum = calc_checksum(location)
901912
fobj_stat = os.stat(fobj.resolved)
913+
path = remove_prefix(fobj.resolved, runtimeContext.basedir + "/")
902914
if checksum is not None:
903-
keydict[fobj.resolved] = [fobj_stat.st_size, checksum]
915+
keydict[path] = [fobj_stat.st_size, checksum]
904916
else:
905-
keydict[fobj.resolved] = [
917+
keydict[path] = [
906918
fobj_stat.st_size,
907919
int(fobj_stat.st_mtime * 1000),
908920
]

docs/pythonversions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and downstream users before making the decision to drop support for a
2222
Python version before the date outlined in this policy. The reasoning
2323
for dropping support for a Python version should be outlined here.
2424

25-
As of Feburary 2022, here are approximate cwltool support periods for
25+
As of February 2022, here are approximate cwltool support periods for
2626
across Python versions:
2727

2828
====== ======================
@@ -38,7 +38,7 @@ Python cwltool end of support
3838
====== ======================
3939

4040
Default Python version of supported Linux distributions, for reference
41-
(as of Feburary 2022)
41+
(as of February 2022)
4242

4343
====== =============================================
4444
Python Linux distros where it is the default version

tests/test_examples.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,46 @@ def test_issue_740_fixed(tmp_path: Path, factor: str) -> None:
13051305
assert error_code == 0, stderr
13061306

13071307

1308+
@needs_docker
1309+
@pytest.mark.parametrize("factor", test_factors)
1310+
def test_cache_relative_paths(tmp_path: Path, factor: str) -> None:
1311+
"""Confirm that re-running a particular workflow with caching succeeds."""
1312+
test_file = "secondary-files.cwl"
1313+
test_job_file = "secondary-files-job.yml"
1314+
cache_dir = str(tmp_path / "cwltool_cache")
1315+
commands = factor.split()
1316+
commands.extend(
1317+
[
1318+
"--cachedir",
1319+
cache_dir,
1320+
get_data(f"tests/{test_file}"),
1321+
get_data(f"tests/{test_job_file}"),
1322+
]
1323+
)
1324+
error_code, _, stderr = get_main_output(commands)
1325+
1326+
stderr = re.sub(r"\s\s+", " ", stderr)
1327+
assert "completed success" in stderr
1328+
assert error_code == 0
1329+
1330+
commands = factor.split()
1331+
commands.extend(
1332+
[
1333+
"--cachedir",
1334+
cache_dir,
1335+
get_data(f"tests/{test_file}"),
1336+
get_data(f"tests/{test_job_file}"),
1337+
]
1338+
)
1339+
error_code, _, stderr = get_main_output(commands)
1340+
1341+
stderr = re.sub(r"\s\s+", " ", stderr)
1342+
assert "Output of job will be cached in" not in stderr
1343+
assert error_code == 0, stderr
1344+
1345+
assert (tmp_path / "cwltool_cache" / "27903451fc1ee10c148a0bdeb845b2cf").exists()
1346+
1347+
13081348
@needs_docker
13091349
def test_compute_checksum() -> None:
13101350
runtime_context = RuntimeContext()

0 commit comments

Comments
 (0)