diff --git a/pydra/utils/hash.py b/pydra/utils/hash.py index 90e132d1ea..4d3c6a74b4 100644 --- a/pydra/utils/hash.py +++ b/pydra/utils/hash.py @@ -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 @@ -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)) diff --git a/pydra/utils/tests/test_hash.py b/pydra/utils/tests/test_hash.py index 56a7d9e680..e63e1c68b6 100644 --- a/pydra/utils/tests/test_hash.py +++ b/pydra/utils/tests/test_hash.py @@ -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)