diff --git a/.github/actions/setup-deps/action.yaml b/.github/actions/setup-deps/action.yaml index bffcca1640f..c1681d9ae48 100644 --- a/.github/actions/setup-deps/action.yaml +++ b/.github/actions/setup-deps/action.yaml @@ -21,8 +21,8 @@ inputs: default: 'codecov' cython: default: 'cython' - fasteners: - default: 'fasteners' + filelock: + default: 'filelock' griddataformats: default: 'griddataformats' hypothesis: @@ -106,7 +106,7 @@ runs: CONDA_MIN_DEPS: | ${{ inputs.codecov }} ${{ inputs.cython }} - ${{ inputs.fasteners }} + ${{ inputs.filelock }} ${{ inputs.griddataformats }} ${{ inputs.hypothesis }} ${{ inputs.matplotlib }} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 27b1c0db3f9..20a32d103ef 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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 diff --git a/maintainer/conda/environment.yml b/maintainer/conda/environment.yml index cd324d25cda..3ceeeadb2d2 100644 --- a/maintainer/conda/environment.yml +++ b/maintainer/conda/environment.yml @@ -7,7 +7,7 @@ dependencies: - codecov - cython - docutils - - fasteners + - filelock - griddataformats - gsd - h5py>=2.10 diff --git a/package/MDAnalysis/coordinates/XDR.py b/package/MDAnalysis/coordinates/XDR.py index 6fe75982cc4..bf036e34e51 100644 --- a/package/MDAnalysis/coordinates/XDR.py +++ b/package/MDAnalysis/coordinates/XDR.py @@ -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 @@ -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, @@ -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 diff --git a/package/pyproject.toml b/package/pyproject.toml index 72a372ccef2..b3283eb22c4 100644 --- a/package/pyproject.toml +++ b/package/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ 'tqdm>=4.43.0', 'threadpoolctl', 'packaging', - 'fasteners', + 'filelock', 'mda-xdrlib', 'waterdynamics', 'pathsimanalysis', diff --git a/package/requirements.txt b/package/requirements.txt index accac1b49fd..a196a9fe0f7 100644 --- a/package/requirements.txt +++ b/package/requirements.txt @@ -1,7 +1,7 @@ biopython>=1.80 codecov cython -fasteners +filelock griddataformats gsd hypothesis diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index efb15d78250..6f768cd6e11 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -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 @@ -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):