Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use exist_ok instead of explicit check for path exists when creating hash cache so it is multiprocess safe #735

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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(

Check warning on line 66 in pydra/utils/hash.py

View check run for this annotation

Codecov / codecov/patch

pydra/utils/hash.py#L65-L66

Added lines #L65 - L66 were not covered by tests
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(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)
Loading