Skip to content

Commit

Permalink
Merge remote-tracking branch 'talagayev/fasteners_to_filelock' into s…
Browse files Browse the repository at this point in the history
…sh_worker
  • Loading branch information
yuxuanzhuang committed Dec 6, 2024
2 parents ef401c2 + aa9f83f commit 1e3daa1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/actions/setup-deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ inputs:
default: 'codecov'
cython:
default: 'cython'
fasteners:
default: 'fasteners'
filelock:
default: 'filelock'
griddataformats:
default: 'griddataformats'
hypothesis:
Expand Down Expand Up @@ -106,7 +106,7 @@ runs:
CONDA_MIN_DEPS: |
${{ inputs.codecov }}
${{ inputs.cython }}
${{ inputs.fasteners }}
${{ inputs.filelock }}
${{ inputs.griddataformats }}
${{ inputs.hypothesis }}
${{ inputs.matplotlib }}
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
scikit-learn
tqdm
threadpoolctl
fasteners
filelock
displayName: 'Install dependencies'
# for wheel install testing, we pin to an
# older NumPy, the oldest version we support and that
Expand Down
2 changes: 1 addition & 1 deletion maintainer/conda/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- codecov
- cython
- docutils
- fasteners
- filelock
- griddataformats
- gsd
- h5py>=2.10
Expand Down
10 changes: 6 additions & 4 deletions package/MDAnalysis/coordinates/XDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import numpy as np
from os.path import getctime, getsize, isfile, split, join
import warnings
import fasteners
from filelock import FileLock

from . import base
from ..lib.mdamath import triclinic_box
Expand Down Expand Up @@ -121,6 +121,8 @@ class XDRBaseReader(base.ReaderBase):
Add a InterProcessLock when generating offsets
.. versionchanged:: 2.4.0
Use a direct read into ts attributes
.. versionchanged:: 2.9.0
Changed fasteners.InterProcessLock() to filelock.FileLock
"""
@store_init_arguments
def __init__(self, filename, convert_units=True, sub=None,
Expand Down Expand Up @@ -195,18 +197,18 @@ def _load_offsets(self):

# check if the location of the lock is writable.
try:
with fasteners.InterProcessLock(lock_name) as filelock:
with FileLock(lock_name) as filelock:
pass
except OSError as e:
if isinstance(e, PermissionError) or e.errno == errno.EROFS:
warnings.warn(f"Cannot write lock/offset file in same location as "
f"{self.filename}. Using slow offset calculation.")
self._read_offsets(store=True)
self._read_offsets(store=False)
return
else:
raise

with fasteners.InterProcessLock(lock_name) as filelock:
with FileLock(lock_name) as filelock:
if not isfile(fname):
self._read_offsets(store=True)
return
Expand Down
2 changes: 1 addition & 1 deletion package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
'tqdm>=4.43.0',
'threadpoolctl',
'packaging',
'fasteners',
'filelock',
'mda-xdrlib',
'waterdynamics',
'pathsimanalysis',
Expand Down
2 changes: 1 addition & 1 deletion package/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
biopython>=1.80
codecov
cython
fasteners
filelock
griddataformats
gsd
hypothesis
Expand Down
8 changes: 2 additions & 6 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,10 @@ def test_persistent_offsets_readonly(self, tmpdir):

filename = str(tmpdir.join(os.path.basename(self.filename)))
# try to write a offsets file
with (pytest.warns(UserWarning, match="Couldn't save offsets") and
with (pytest.warns(UserWarning, match="Couldn't save offsets") or
pytest.warns(UserWarning, match="Cannot write")):
self._reader(filename)
assert_equal(os.path.exists(XDR.offsets_filename(filename)), False)
# check the lock file is not created as well.
assert_equal(os.path.exists(XDR.offsets_filename(filename,
ending='.lock')), False)

# pre-teardown permission fix - leaving permission blocked dir
# is problematic on py3.9 + Windows it seems. See issue
Expand All @@ -923,8 +920,7 @@ def test_persistent_offsets_readonly(self, tmpdir):
shutil.rmtree(tmpdir)

def test_offset_lock_created(self):
assert os.path.exists(XDR.offsets_filename(self.filename,
ending='lock'))
assert os.path.exists(XDR.offsets_filename(self.filename))


class TestXTCReader_offsets(_GromacsReader_offsets):
Expand Down

0 comments on commit 1e3daa1

Please sign in to comment.