filelock 4.2.1__tar.gz → 4.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. {filelock-4.2.1 → filelock-4.2.2}/PKG-INFO +1 -1
  2. {filelock-4.2.1 → filelock-4.2.2}/docs/changelog.rst +8 -0
  3. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_api.py +1 -2
  4. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/version.py +2 -2
  5. {filelock-4.2.1 → filelock-4.2.2}/tests/soft_rw/test_soft_rw_protocol.py +18 -5
  6. {filelock-4.2.1 → filelock-4.2.2}/tests/test_filelock.py +42 -0
  7. {filelock-4.2.1 → filelock-4.2.2}/.gitignore +0 -0
  8. {filelock-4.2.1 → filelock-4.2.2}/LICENSE +0 -0
  9. {filelock-4.2.1 → filelock-4.2.2}/README.md +0 -0
  10. {filelock-4.2.1 → filelock-4.2.2}/docs/_static/custom.css +0 -0
  11. {filelock-4.2.1 → filelock-4.2.2}/docs/api.rst +0 -0
  12. {filelock-4.2.1 → filelock-4.2.2}/docs/changelog/template.jinja2 +0 -0
  13. {filelock-4.2.1 → filelock-4.2.2}/docs/concepts.rst +0 -0
  14. {filelock-4.2.1 → filelock-4.2.2}/docs/conf.py +0 -0
  15. {filelock-4.2.1 → filelock-4.2.2}/docs/example.gif +0 -0
  16. {filelock-4.2.1 → filelock-4.2.2}/docs/how-to.rst +0 -0
  17. {filelock-4.2.1 → filelock-4.2.2}/docs/index.rst +0 -0
  18. {filelock-4.2.1 → filelock-4.2.2}/docs/license.rst +0 -0
  19. {filelock-4.2.1 → filelock-4.2.2}/docs/logo.svg +0 -0
  20. {filelock-4.2.1 → filelock-4.2.2}/docs/tutorials.rst +0 -0
  21. {filelock-4.2.1 → filelock-4.2.2}/pyproject.toml +0 -0
  22. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/__init__.py +0 -0
  23. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_async.py +0 -0
  24. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_async_read_write.py +0 -0
  25. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_descriptor.py +0 -0
  26. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_error.py +0 -0
  27. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_identity.py +0 -0
  28. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_lease.py +0 -0
  29. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_marker.py +0 -0
  30. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_read_write.py +0 -0
  31. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft.py +0 -0
  32. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft_protocol.py +0 -0
  33. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft_rw/__init__.py +0 -0
  34. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft_rw/_async.py +0 -0
  35. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft_rw/_protocol.py +0 -0
  36. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft_rw/_storage.py +0 -0
  37. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_soft_rw/_sync.py +0 -0
  38. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_strict.py +0 -0
  39. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_unix.py +0 -0
  40. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_util.py +0 -0
  41. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/_windows.py +0 -0
  42. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/asyncio.py +0 -0
  43. {filelock-4.2.1 → filelock-4.2.2}/src/filelock/py.typed +0 -0
  44. {filelock-4.2.1 → filelock-4.2.2}/tasks/benchmark.py +0 -0
  45. {filelock-4.2.1 → filelock-4.2.2}/tasks/capabilities.py +0 -0
  46. {filelock-4.2.1 → filelock-4.2.2}/tasks/capability/assert_fallback.py +0 -0
  47. {filelock-4.2.1 → filelock-4.2.2}/tasks/capability/sitecustomize.py +0 -0
  48. {filelock-4.2.1 → filelock-4.2.2}/tasks/coverage_pragmas.py +0 -0
  49. {filelock-4.2.1 → filelock-4.2.2}/tasks/deny_symlink.py +0 -0
  50. {filelock-4.2.1 → filelock-4.2.2}/tasks/termux/Dockerfile +0 -0
  51. {filelock-4.2.1 → filelock-4.2.2}/tasks/verify_filesystem.py +0 -0
  52. {filelock-4.2.1 → filelock-4.2.2}/tests/async_filelock_cancellation_helpers.py +0 -0
  53. {filelock-4.2.1 → filelock-4.2.2}/tests/capability_marks.py +0 -0
  54. {filelock-4.2.1 → filelock-4.2.2}/tests/conftest.py +0 -0
  55. {filelock-4.2.1 → filelock-4.2.2}/tests/fork_helpers.py +0 -0
  56. {filelock-4.2.1 → filelock-4.2.2}/tests/pid_namespace_helpers.py +0 -0
  57. {filelock-4.2.1 → filelock-4.2.2}/tests/process_helpers.py +0 -0
  58. {filelock-4.2.1 → filelock-4.2.2}/tests/read_write_helpers.py +0 -0
  59. {filelock-4.2.1 → filelock-4.2.2}/tests/soft_rw/conftest.py +0 -0
  60. {filelock-4.2.1 → filelock-4.2.2}/tests/soft_rw/test_soft_rw_async.py +0 -0
  61. {filelock-4.2.1 → filelock-4.2.2}/tests/soft_rw/test_soft_rw_storage.py +0 -0
  62. {filelock-4.2.1 → filelock-4.2.2}/tests/soft_rw/test_soft_rw_sync.py +0 -0
  63. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_filelock.py +0 -0
  64. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_filelock_acquire_cancellation.py +0 -0
  65. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_filelock_release_cancellation.py +0 -0
  66. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_filelock_rollback_agnostic.py +0 -0
  67. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_filelock_runner_shutdown.py +0 -0
  68. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_filelock_transition_admission.py +0 -0
  69. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_read_write.py +0 -0
  70. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_read_write_cancel_wait.py +0 -0
  71. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_read_write_cancellation.py +0 -0
  72. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_read_write_worker_ownership.py +0 -0
  73. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_soft_contracts.py +0 -0
  74. {filelock-4.2.1 → filelock-4.2.2}/tests/test_async_transition_gate.py +0 -0
  75. {filelock-4.2.1 → filelock-4.2.2}/tests/test_default_mode.py +0 -0
  76. {filelock-4.2.1 → filelock-4.2.2}/tests/test_error.py +0 -0
  77. {filelock-4.2.1 → filelock-4.2.2}/tests/test_fork_backends.py +0 -0
  78. {filelock-4.2.1 → filelock-4.2.2}/tests/test_fork_coordination.py +0 -0
  79. {filelock-4.2.1 → filelock-4.2.2}/tests/test_fork_ownership.py +0 -0
  80. {filelock-4.2.1 → filelock-4.2.2}/tests/test_fork_registries.py +0 -0
  81. {filelock-4.2.1 → filelock-4.2.2}/tests/test_host_name_grammar.py +0 -0
  82. {filelock-4.2.1 → filelock-4.2.2}/tests/test_lazy_import.py +0 -0
  83. {filelock-4.2.1 → filelock-4.2.2}/tests/test_lifetime_validation.py +0 -0
  84. {filelock-4.2.1 → filelock-4.2.2}/tests/test_lock_expiry.py +0 -0
  85. {filelock-4.2.1 → filelock-4.2.2}/tests/test_marker_records.py +0 -0
  86. {filelock-4.2.1 → filelock-4.2.2}/tests/test_process_identity.py +0 -0
  87. {filelock-4.2.1 → filelock-4.2.2}/tests/test_read_write.py +0 -0
  88. {filelock-4.2.1 → filelock-4.2.2}/tests/test_read_write_fork.py +0 -0
  89. {filelock-4.2.1 → filelock-4.2.2}/tests/test_read_write_private_link.py +0 -0
  90. {filelock-4.2.1 → filelock-4.2.2}/tests/test_read_write_unit.py +0 -0
  91. {filelock-4.2.1 → filelock-4.2.2}/tests/test_soft_lease.py +0 -0
  92. {filelock-4.2.1 → filelock-4.2.2}/tests/test_soft_lifetime_warning.py +0 -0
  93. {filelock-4.2.1 → filelock-4.2.2}/tests/test_soft_stale.py +0 -0
  94. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft.py +0 -0
  95. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft_compat.py +0 -0
  96. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft_failures.py +0 -0
  97. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft_paths.py +0 -0
  98. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft_races.py +0 -0
  99. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft_recovery.py +0 -0
  100. {filelock-4.2.1 → filelock-4.2.2}/tests/test_strict_soft_stress.py +0 -0
  101. {filelock-4.2.1 → filelock-4.2.2}/tests/test_subclass_options.py +0 -0
  102. {filelock-4.2.1 → filelock-4.2.2}/tests/test_unix_fallback.py +0 -0
  103. {filelock-4.2.1 → filelock-4.2.2}/tests/test_util.py +0 -0
  104. {filelock-4.2.1 → filelock-4.2.2}/tests/test_virtualenv.py +0 -0
  105. {filelock-4.2.1 → filelock-4.2.2}/tox.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: filelock
3
- Version: 4.2.1
3
+ Version: 4.2.2
4
4
  Summary: A platform independent file lock.
5
5
  Project-URL: Documentation, https://py-filelock.readthedocs.io
6
6
  Project-URL: Homepage, https://github.com/tox-dev/py-filelock
@@ -6,6 +6,14 @@
6
6
 
7
7
  .. towncrier release notes start
8
8
 
9
+ *******************
10
+ 4.2.2 (2026-10-18)
11
+ *******************
12
+
13
+ - Fix a lock on a relative path that stayed held after a later ``with lock:`` ended, when an earlier ``acquire()`` had
14
+ failed because the working directory no longer exists. That call still raises :class:`FileNotFoundError`, and it now
15
+ leaves the lock's hold count unchanged. :pr:`856`
16
+
9
17
  *******************
10
18
  4.2.1 (2026-10-17)
11
19
  *******************
@@ -1217,10 +1217,9 @@ class BaseFileLock(contextlib.ContextDecorator, metaclass=FileLockMeta): # ruff
1217
1217
  if _on_this_stack(self._context.releasing):
1218
1218
  msg = f"lock '{self.lock_file}' is acquired again while this thread's release of it runs"
1219
1219
  raise RuntimeError(msg)
1220
- # Bump the counter up front; _undo_acquire rolls it back if acquisition fails.
1220
+ canonical = _canonical(self.lock_file)
1221
1221
  self._context.lock_counter += 1
1222
1222
 
1223
- canonical = _canonical(self.lock_file)
1224
1223
  self._raise_if_would_deadlock(canonical, timeout=timeout, blocking=blocking)
1225
1224
  if not self.is_locked:
1226
1225
  self._pin_lock_path(canonical)
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '4.2.1'
22
- __version_tuple__ = version_tuple = (4, 2, 1)
21
+ __version__ = version = '4.2.2'
22
+ __version_tuple__ = version_tuple = (4, 2, 2)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -30,6 +30,7 @@ from filelock._soft_rw._protocol import (
30
30
  Ledger,
31
31
  Participant,
32
32
  Snapshot,
33
+ TreeReplacedError,
33
34
  encode_holder,
34
35
  holder_lease,
35
36
  parse_snapshot,
@@ -884,13 +885,25 @@ def test_heartbeat_ignores_a_broken_successor_record(lock_file: str, files: OsFi
884
885
 
885
886
 
886
887
  @pytest.mark.requires_hard_links
887
- def test_heartbeat_reports_the_refresh_error(lock_file: str, files: OsFiles, mocker: MockerFixture) -> None:
888
- writer = _participant(files, lock_file, "write")
888
+ @pytest.mark.parametrize(
889
+ ("error", "expected"),
890
+ [
891
+ pytest.param(OSError(EIO, "Input/output error"), "transient", id="filesystem-error"),
892
+ pytest.param(TreeReplacedError("tree replaced"), "lost", id="replaced-tree"),
893
+ ],
894
+ )
895
+ def test_heartbeat_reports_the_refresh_error(
896
+ lock_file: str,
897
+ files: OsFiles,
898
+ mocker: MockerFixture,
899
+ error: OSError | TreeReplacedError,
900
+ expected: Literal["transient", "lost"],
901
+ ) -> None:
902
+ writer: Final[Participant] = _participant(files, lock_file, "write")
889
903
  writer.publish()
890
904
  assert writer.advance()
891
- error = OSError(EIO, "Input/output error")
892
- mocker.patch.object(OsFiles, "overwrite", side_effect=error)
893
- assert writer.heartbeat() == ("transient", error)
905
+ mocker.patch.object(OsFiles, "overwrite", autospec=True, side_effect=error)
906
+ assert writer.heartbeat() == (expected, error if isinstance(error, OSError) else None)
894
907
 
895
908
 
896
909
  def test_heartbeat_without_a_published_record_is_lost(lock_file: str, files: OsFiles) -> None:
@@ -3213,6 +3213,48 @@ def test_each_acquisition_resolves_the_working_directory(
3213
3213
  assert (lock.lock_file, (second / "resource.lock").exists()) == ("resource.lock", True)
3214
3214
 
3215
3215
 
3216
+ @pytest.mark.skipif(
3217
+ sys.platform == "win32", reason="a working directory in use cannot be removed"
3218
+ ) # pragma: win32 no cover
3219
+ @pytest.mark.parametrize("lock_type", _RELATIVE_LOCK_TYPES)
3220
+ def test_acquire_without_working_directory_leaves_no_hold(
3221
+ lock_type: type[BaseFileLock], working_directories: tuple[Path, Path]
3222
+ ) -> None:
3223
+ lock: Final[BaseFileLock] = lock_type("resource.lock")
3224
+ working_directories[0].rmdir()
3225
+
3226
+ with pytest.raises(FileNotFoundError):
3227
+ lock.acquire()
3228
+ second: Final[Path] = working_directories[1]
3229
+ os.chdir(second)
3230
+ with lock:
3231
+ assert (lock.lock_counter, lock.is_locked, (second / "resource.lock").exists()) == (1, True, True)
3232
+
3233
+ assert (lock.lock_counter, lock.is_locked) == (0, False)
3234
+
3235
+
3236
+ @pytest.mark.skipif(
3237
+ sys.platform == "win32", reason="a working directory in use cannot be removed"
3238
+ ) # pragma: win32 no cover
3239
+ @pytest.mark.parametrize("lock_type", _RELATIVE_LOCK_TYPES)
3240
+ def test_nested_acquire_without_working_directory_preserves_hold(
3241
+ lock_type: type[BaseFileLock], working_directories: tuple[Path, Path]
3242
+ ) -> None:
3243
+ lock: Final[BaseFileLock] = lock_type("resource.lock")
3244
+ lock.acquire()
3245
+ first: Final[Path] = working_directories[0]
3246
+ (first / "resource.lock").unlink()
3247
+ first.rmdir()
3248
+
3249
+ with pytest.raises(FileNotFoundError):
3250
+ lock.acquire()
3251
+ assert (lock.lock_counter, lock.is_locked) == (1, True)
3252
+
3253
+ os.chdir(working_directories[1])
3254
+ lock.release()
3255
+ assert (lock.lock_counter, lock.is_locked) == (0, False)
3256
+
3257
+
3216
3258
  @pytest.mark.parametrize("lock_type", _RELATIVE_LOCK_TYPES)
3217
3259
  def test_singleton_after_chdir_locks_the_requested_file(
3218
3260
  lock_type: type[BaseFileLock], working_directories: tuple[Path, Path]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes