Skip to content

Commit ee5a238

Browse files
authored
Merge pull request #735 from tclose/fix-cache-dir
use exist_ok instead of explicit check for path exists when creating hash cache so it is multiprocess safe
2 parents 811dc45 + db42246 commit ee5a238

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

pydra/utils/hash.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ def location_converter(path: ty.Union[Path, str, None]) -> Path:
6060
if path is None:
6161
path = PersistentCache.location_default()
6262
path = Path(path)
63-
if not path.exists():
64-
path.mkdir(parents=True)
63+
try:
64+
path.mkdir(parents=True, exist_ok=True)
65+
except FileExistsError:
66+
raise ValueError(
67+
f"provided path to persistent cache {path} is a file not a directory"
68+
) from None
6569
return path
6670

6771

@@ -106,13 +110,6 @@ def location_default(cls):
106110
def _location_default(self):
107111
return self.location_default()
108112

109-
@location.validator
110-
def location_validator(self, _, location):
111-
if not os.path.isdir(location):
112-
raise ValueError(
113-
f"Persistent cache location '{location}' is not a directory"
114-
)
115-
116113
@cleanup_period.default
117114
def cleanup_period_default(self):
118115
return int(os.environ.get(self.CLEANUP_ENV_VAR, 30))

pydra/utils/tests/test_hash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,5 @@ def test_persistent_hash_cache_not_dir(text_file):
384384
"""
385385
Test that an error is raised if the provided cache path is not a directory
386386
"""
387-
with pytest.raises(ValueError, match="is not a directory"):
387+
with pytest.raises(ValueError, match="not a directory"):
388388
PersistentCache(text_file.fspath)

0 commit comments

Comments
 (0)