Skip to content

Commit

Permalink
Merge pull request #735 from tclose/fix-cache-dir
Browse files Browse the repository at this point in the history
use exist_ok instead of explicit check for path exists when creating hash cache so it is multiprocess safe
  • Loading branch information
djarecka committed Mar 18, 2024
2 parents 811dc45 + db42246 commit ee5a238
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions pydra/utils/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ def location_converter(path: ty.Union[Path, str, None]) -> Path:
if path is None:
path = PersistentCache.location_default()
path = Path(path)
if not path.exists():
path.mkdir(parents=True)
try:
path.mkdir(parents=True, exist_ok=True)
except FileExistsError:
raise ValueError(
f"provided path to persistent cache {path} is a file not a directory"
) from None
return path


Expand Down Expand Up @@ -106,13 +110,6 @@ def location_default(cls):
def _location_default(self):
return self.location_default()

@location.validator
def location_validator(self, _, location):
if not os.path.isdir(location):
raise ValueError(
f"Persistent cache location '{location}' is not a directory"
)

@cleanup_period.default
def cleanup_period_default(self):
return int(os.environ.get(self.CLEANUP_ENV_VAR, 30))
Expand Down
2 changes: 1 addition & 1 deletion pydra/utils/tests/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,5 @@ def test_persistent_hash_cache_not_dir(text_file):
"""
Test that an error is raised if the provided cache path is not a directory
"""
with pytest.raises(ValueError, match="is not a directory"):
with pytest.raises(ValueError, match="not a directory"):
PersistentCache(text_file.fspath)

0 comments on commit ee5a238

Please sign in to comment.