diff -Nru python-filelock-3.4.2/debian/changelog python-filelock-3.6.0/debian/changelog --- python-filelock-3.4.2/debian/changelog 2022-02-07 11:07:31.000000000 +0000 +++ python-filelock-3.6.0/debian/changelog 2022-02-19 19:03:12.000000000 +0000 @@ -1,3 +1,9 @@ +python-filelock (3.6.0-1) unstable; urgency=medium + + * New upstream release. + + -- Sascha Steinbiss Sat, 19 Feb 2022 20:03:12 +0100 + python-filelock (3.4.2-2) unstable; urgency=medium * Ensure version is set correctly in setup.cfg. diff -Nru python-filelock-3.4.2/docs/changelog.rst python-filelock-3.6.0/docs/changelog.rst --- python-filelock-3.4.2/docs/changelog.rst 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/docs/changelog.rst 2022-02-17 18:26:03.000000000 +0000 @@ -1,6 +1,21 @@ Changelog ========= +v3.6.0 (2022-02-17) +------------------- +- Fix pylint warning "Abstract class :class:`WindowsFileLock ` with abstract methods instantiated" + :pr:`135` - by :user:`vonschultz` +- Fix pylint warning "Abstract class :class:`UnixFileLock ` with abstract methods instantiated" + :pr:`135` - by :user:`vonschultz` + +v3.5.1 (2022-02-16) +------------------- +- Use ``time.monotonic`` instead of ``time.time`` for calculating timeouts. + +v3.5.0 (2022-02-15) +------------------- +- Enable use as context decorator + v3.4.2 (2021-12-16) ------------------- - Drop support for python ``3.6`` diff -Nru python-filelock-3.4.2/docs/index.rst python-filelock-3.6.0/docs/index.rst --- python-filelock-3.4.2/docs/index.rst 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/docs/index.rst 2022-02-17 18:26:03.000000000 +0000 @@ -10,7 +10,8 @@ lock = FileLock("high_ground.txt.lock") with lock: - open("high_ground.txt", "a").write("You were the chosen one.") + with open("high_ground.txt", "a") as f: + f.write("You were the chosen one.") **Don't use** a :class:`FileLock ` to lock the file you want to write to, instead create a separate ``.lock`` file as shown above. @@ -59,14 +60,24 @@ .. code-block:: python with lock: - open(file_path, "a").write("Hello there!") + with open(file_path, "a") as f: + f.write("Hello there!") lock.acquire() try: - open(file_path, "a").write("General Kenobi!") + with open(file_path, "a") as f: + f.write("General Kenobi!") finally: lock.release() + + @lock + def decorated(): + print("You're a decorated Jedi!") + + + decorated() + The :meth:`acquire ` method accepts also a ``timeout`` parameter. If the lock cannot be acquired within ``timeout`` seconds, a :class:`Timeout ` exception is raised: @@ -74,7 +85,8 @@ try: with lock.acquire(timeout=10): - open(file_path, "a").write("I have a bad feeling about this.") + with open(file_path, "a") as f: + f.write("I have a bad feeling about this.") except Timeout: print("Another instance of this application currently holds the lock.") @@ -84,12 +96,14 @@ def cite1(): with lock: - open(file_path, "a").write("I hate it when he does that.") + with open(file_path, "a") as f: + f.write("I hate it when he does that.") def cite2(): with lock: - open(file_path, "a").write("You don't want to sell me death sticks.") + with open(file_path, "a") as f: + f.write("You don't want to sell me death sticks.") # The lock is acquired here. diff -Nru python-filelock-3.4.2/PKG-INFO python-filelock-3.6.0/PKG-INFO --- python-filelock-3.4.2/PKG-INFO 2021-12-26 17:13:18.620433800 +0000 +++ python-filelock-3.6.0/PKG-INFO 2022-02-17 18:26:11.019809000 +0000 @@ -1,12 +1,12 @@ Metadata-Version: 2.1 Name: filelock -Version: 3.4.2 +Version: 3.6.0 Summary: A platform independent file lock. Home-page: https://github.com/tox-dev/py-filelock +Download-URL: https://github.com/tox-dev/py-filelock/archive/main.zip Author: Benedikt Schmitt Author-email: benedikt@benediktschmitt.de License: Unlicense -Download-URL: https://github.com/tox-dev/py-filelock/archive/main.zip Project-URL: Source, https://github.com/tox-dev/py-filelock Project-URL: Tracker, https://github.com/tox-dev/py-filelock/issues Platform: UNKNOWN diff -Nru python-filelock-3.4.2/.pre-commit-config.yaml python-filelock-3.6.0/.pre-commit-config.yaml --- python-filelock-3.4.2/.pre-commit-config.yaml 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/.pre-commit-config.yaml 2022-02-17 18:26:03.000000000 +0000 @@ -12,7 +12,7 @@ - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/asottile/pyupgrade - rev: v2.29.1 + rev: v2.31.0 hooks: - id: pyupgrade args: [ "--py36-plus" ] @@ -21,12 +21,12 @@ hooks: - id: isort - repo: https://github.com/psf/black - rev: 21.12b0 + rev: 22.1.0 hooks: - id: black args: [ --safe ] - repo: https://github.com/asottile/blacken-docs - rev: v1.12.0 + rev: v1.12.1 hooks: - id: blacken-docs additional_dependencies: [ black==21.12b0 ] @@ -35,7 +35,7 @@ hooks: - id: rst-backticks - repo: https://github.com/tox-dev/tox-ini-fmt - rev: "0.5.1" + rev: "0.5.2" hooks: - id: tox-ini-fmt args: [ "-p", "fix_lint" ] diff -Nru python-filelock-3.4.2/src/filelock/_api.py python-filelock-3.6.0/src/filelock/_api.py --- python-filelock-3.4.2/src/filelock/_api.py 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/src/filelock/_api.py 2022-02-17 18:26:03.000000000 +0000 @@ -1,5 +1,6 @@ from __future__ import annotations +import contextlib import logging import os import time @@ -35,7 +36,7 @@ self.lock.release() -class BaseFileLock(ABC): +class BaseFileLock(ABC, contextlib.ContextDecorator): """Abstract base class for a file lock object.""" def __init__(self, lock_file: str | os.PathLike[Any], timeout: float = -1) -> None: @@ -160,7 +161,7 @@ lock_id = id(self) lock_filename = self._lock_file - start_time = time.time() + start_time = time.monotonic() try: while True: with self._thread_lock: @@ -171,7 +172,7 @@ if self.is_locked: _LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename) break - elif 0 <= timeout < time.time() - start_time: + elif 0 <= timeout < time.monotonic() - start_time: _LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename) raise Timeout(self._lock_file) else: diff -Nru python-filelock-3.4.2/src/filelock/_unix.py python-filelock-3.6.0/src/filelock/_unix.py --- python-filelock-3.4.2/src/filelock/_unix.py 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/src/filelock/_unix.py 2022-02-17 18:26:03.000000000 +0000 @@ -2,7 +2,6 @@ import os import sys -from abc import ABC from typing import cast from ._api import BaseFileLock @@ -11,9 +10,15 @@ has_fcntl = False if sys.platform == "win32": # pragma: win32 cover - class UnixFileLock(BaseFileLock, ABC): + class UnixFileLock(BaseFileLock): """Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.""" + def _acquire(self) -> None: + raise NotImplementedError + + def _release(self) -> None: + raise NotImplementedError + else: # pragma: win32 no cover try: import fcntl diff -Nru python-filelock-3.4.2/src/filelock/version.py python-filelock-3.6.0/src/filelock/version.py --- python-filelock-3.4.2/src/filelock/version.py 2021-12-26 17:13:18.000000000 +0000 +++ python-filelock-3.6.0/src/filelock/version.py 2022-02-17 18:26:10.000000000 +0000 @@ -1,5 +1,5 @@ # coding: utf-8 # file generated by setuptools_scm # don't change, don't track in version control -version = '3.4.2' -version_tuple = (3, 4, 2) +version = '3.6.0' +version_tuple = (3, 6, 0) diff -Nru python-filelock-3.4.2/src/filelock/_windows.py python-filelock-3.6.0/src/filelock/_windows.py --- python-filelock-3.4.2/src/filelock/_windows.py 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/src/filelock/_windows.py 2022-02-17 18:26:03.000000000 +0000 @@ -2,7 +2,6 @@ import os import sys -from abc import ABC from errno import ENOENT from typing import cast @@ -49,9 +48,15 @@ else: # pragma: win32 no cover - class WindowsFileLock(BaseFileLock, ABC): + class WindowsFileLock(BaseFileLock): """Uses the :func:`msvcrt.locking` function to hard lock the lock file on windows systems.""" + def _acquire(self) -> None: + raise NotImplementedError + + def _release(self) -> None: + raise NotImplementedError + __all__ = [ "WindowsFileLock", diff -Nru python-filelock-3.4.2/src/filelock.egg-info/PKG-INFO python-filelock-3.6.0/src/filelock.egg-info/PKG-INFO --- python-filelock-3.4.2/src/filelock.egg-info/PKG-INFO 2021-12-26 17:13:18.000000000 +0000 +++ python-filelock-3.6.0/src/filelock.egg-info/PKG-INFO 2022-02-17 18:26:10.000000000 +0000 @@ -1,12 +1,12 @@ Metadata-Version: 2.1 Name: filelock -Version: 3.4.2 +Version: 3.6.0 Summary: A platform independent file lock. Home-page: https://github.com/tox-dev/py-filelock +Download-URL: https://github.com/tox-dev/py-filelock/archive/main.zip Author: Benedikt Schmitt Author-email: benedikt@benediktschmitt.de License: Unlicense -Download-URL: https://github.com/tox-dev/py-filelock/archive/main.zip Project-URL: Source, https://github.com/tox-dev/py-filelock Project-URL: Tracker, https://github.com/tox-dev/py-filelock/issues Platform: UNKNOWN diff -Nru python-filelock-3.4.2/tests/test_filelock.py python-filelock-3.6.0/tests/test_filelock.py --- python-filelock-3.4.2/tests/test_filelock.py 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/tests/test_filelock.py 2022-02-17 18:26:03.000000000 +0000 @@ -1,5 +1,6 @@ from __future__ import annotations +import inspect import logging import sys import threading @@ -13,7 +14,7 @@ import pytest from _pytest.logging import LogCaptureFixture -from filelock import BaseFileLock, FileLock, SoftFileLock, Timeout +from filelock import BaseFileLock, FileLock, SoftFileLock, Timeout, UnixFileLock, WindowsFileLock @pytest.mark.parametrize( @@ -368,3 +369,31 @@ break else: # pragma: no cover pytest.fail("No warnings of stacklevel=2 matching.") + + +@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) +def test_context_decorator(lock_type: type[BaseFileLock], tmp_path: Path) -> None: + lock_path = tmp_path / "a" + lock = lock_type(str(lock_path)) + + @lock + def decorated_method() -> None: + assert lock.is_locked + + assert not lock.is_locked + decorated_method() + assert not lock.is_locked + + +def test_wrong_platform(tmp_path: Path) -> None: + assert not inspect.isabstract(UnixFileLock) + assert not inspect.isabstract(WindowsFileLock) + assert inspect.isabstract(BaseFileLock) + + lock_type = UnixFileLock if sys.platform == "win32" else WindowsFileLock + lock = lock_type(str(tmp_path / "lockfile")) + + with pytest.raises(NotImplementedError): + lock.acquire() + with pytest.raises(NotImplementedError): + lock._release() diff -Nru python-filelock-3.4.2/whitelist.txt python-filelock-3.6.0/whitelist.txt --- python-filelock-3.4.2/whitelist.txt 2021-12-26 17:13:11.000000000 +0000 +++ python-filelock-3.6.0/whitelist.txt 2022-02-17 18:26:03.000000000 +0000 @@ -15,6 +15,7 @@ fspath intersphinx intervall +isabstract iwgrp iwoth iwusr