Skip to content

Commit b8ae5a1

Browse files
[pre-commit.ci] pre-commit autoupdate (#305)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 58dd73a commit b8ae5a1

File tree

11 files changed

+72
-88
lines changed

11 files changed

+72
-88
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ repos:
44
hooks:
55
- id: end-of-file-fixer
66
- id: trailing-whitespace
7-
- repo: https://github.com/astral-sh/ruff-pre-commit
8-
rev: "v0.2.0"
7+
- repo: https://github.com/codespell-project/codespell
8+
rev: v2.2.6
99
hooks:
10-
- id: ruff
11-
args: [--fix, --exit-non-zero-on-fix]
12-
- repo: https://github.com/psf/black
13-
rev: 24.1.1
14-
hooks:
15-
- id: black
10+
- id: codespell
11+
args: ["--write-changes"]
1612
- repo: https://github.com/tox-dev/tox-ini-fmt
1713
rev: "1.3.1"
1814
hooks:
@@ -22,7 +18,13 @@ repos:
2218
rev: "1.7.0"
2319
hooks:
2420
- id: pyproject-fmt
25-
additional_dependencies: ["tox>=4.11.4"]
21+
additional_dependencies: ["tox>=4.12.1"]
22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
rev: "v0.2.1"
24+
hooks:
25+
- id: ruff-format
26+
- id: ruff
27+
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
2628
- repo: meta
2729
hooks:
2830
- id: check-hooks-apply

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Changelog
22
=========
33
v3.12.0 (2023-04-18)
44
--------------------
5-
- Make the thread local behaviour something the caller can enable/disable via a flag during the lock creation, it's on
5+
- Make the thread local behavior something the caller can enable/disable via a flag during the lock creation, it's on
66
by default.
77
- Better error handling on Windows.
88

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# noqa: INP001
22
"""Configuration for Sphinx."""
3+
34
from __future__ import annotations
45

56
from datetime import datetime, timezone
@@ -50,10 +51,11 @@ def setup(app: Sphinx) -> None:
5051
Setup app.
5152
5253
:param app: the app
54+
5355
"""
5456

5557
class PatchedPythonDomain(PythonDomain):
56-
def resolve_xref( # noqa: PLR0913
58+
def resolve_xref( # noqa: PLR0913, PLR0917
5759
self,
5860
env: BuildEnvironment,
5961
fromdocname: str,

pyproject.toml

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,43 @@ build.hooks.vcs.version-file = "src/filelock/version.py"
6565
build.targets.sdist.include = ["/src", "/tests", "/tox.ini"]
6666
version.source = "vcs"
6767

68-
[tool.black]
69-
line-length = 120
70-
7168
[tool.ruff]
72-
select = ["ALL"]
7369
line-length = 120
7470
target-version = "py38"
75-
isort = {known-first-party = ["filelock"], required-imports = ["from __future__ import annotations"]}
76-
ignore = [
77-
"ANN101", # Missing type annotation for `self` in method
78-
"D301", # Use `r"""` if any backslashes in a docstring
79-
"D205", # 1 blank line required between summary line and description
80-
"D401", # First line of docstring should be in imperative mood
81-
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
82-
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
83-
"S104", # Possible binding to all interface
71+
lint.isort = { known-first-party = ["filelock"], required-imports = ["from __future__ import annotations"] }
72+
lint.select = ["ALL"]
73+
lint.ignore = [
74+
"ANN101", # Missing type annotation for `self` in method
75+
"D301", # Use `r"""` if any backslashes in a docstring
76+
"D205", # 1 blank line required between summary line and description
77+
"D401", # First line of docstring should be in imperative mood
78+
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
79+
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
80+
"S104", # Possible binding to all interface
81+
"COM812", # Conflict with formatter
82+
"ISC001", # Conflict with formatter
83+
"CPY", # No copyright statements
8484
]
85-
[tool.ruff.per-file-ignores]
85+
lint.preview = true
86+
format.preview = true
87+
format.docstring-code-format = true
88+
format.docstring-code-line-length = 100
89+
[tool.ruff.lint.per-file-ignores]
8690
"tests/**/*.py" = [
87-
"S101", # asserts allowed in tests...
88-
"FBT", # don"t care about booleans as positional arguments in tests
89-
"INP001", # no implicit namespace
90-
"D", # don"t care about documentation in tests
91-
"S603", # `subprocess` call: check for execution of untrusted input
92-
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
91+
"S101", # asserts allowed in tests...
92+
"FBT", # don"t care about booleans as positional arguments in tests
93+
"INP001", # no implicit namespace
94+
"D", # don"t care about documentation in tests
95+
"S603", # `subprocess` call: check for execution of untrusted input
96+
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
9397
]
9498

99+
[tool.codespell]
100+
builtin = "clear,usage,en-GB_to_en-US"
101+
count = true
102+
quiet-level = 3
103+
ignore-words-list = "master"
104+
95105
[tool.coverage]
96106
html.show_contexts = true
97107
html.skip_covered = false

src/filelock/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141

4242

4343
__all__ = [
44-
"__version__",
44+
"AcquireReturnProxy",
45+
"BaseFileLock",
4546
"FileLock",
4647
"SoftFileLock",
4748
"Timeout",
4849
"UnixFileLock",
4950
"WindowsFileLock",
50-
"BaseFileLock",
51-
"AcquireReturnProxy",
51+
"__version__",
5252
]

src/filelock/_api.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# is not called twice when entering the with statement. If we would simply return *self*, the lock would be acquired
3131
# again in the *__enter__* method of the BaseFileLock, but not released again automatically. issue #37 (memory leak)
3232
class AcquireReturnProxy:
33-
"""A context aware object that will release the lock file when exiting."""
33+
"""A context-aware object that will release the lock file when exiting."""
3434

3535
def __init__(self, lock: BaseFileLock) -> None:
3636
self.lock = lock
@@ -115,13 +115,14 @@ def __init__( # noqa: PLR0913
115115
:param lock_file: path to the file
116116
:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in \
117117
the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it \
118-
to a negative value. A timeout of 0 means, that there is exactly one attempt to acquire the file lock.
118+
to a negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
119119
:param mode: file permissions for the lockfile
120120
:param thread_local: Whether this object's internal context should be thread local or not. If this is set to \
121121
``False`` then the lock will be reentrant across threads.
122122
:param is_singleton: If this is set to ``True`` then only one instance of this class will be created \
123123
per lock file. This is useful if you want to use the lock object for reentrant locking without needing \
124124
to pass the same object around.
125+
125126
"""
126127
self._is_thread_local = thread_local
127128
self._is_singleton = is_singleton
@@ -164,6 +165,7 @@ def timeout(self, value: float | str) -> None:
164165
Change the default timeout value.
165166
166167
:param value: the new value, in seconds
168+
167169
"""
168170
self._context.timeout = float(value)
169171

@@ -272,10 +274,11 @@ def acquire(
272274

273275
def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002
274276
"""
275-
Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0. Also
276-
note, that the lock file itself is not automatically deleted.
277+
Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0.
278+
Also note, that the lock file itself is not automatically deleted.
277279
278280
:param force: If true, the lock counter is ignored and the lock is released in every case/
281+
279282
"""
280283
if self.is_locked:
281284
self._context.lock_counter -= 1
@@ -293,6 +296,7 @@ def __enter__(self) -> Self:
293296
Acquire the lock.
294297
295298
:return: the lock object
299+
296300
"""
297301
self.acquire()
298302
return self
@@ -309,6 +313,7 @@ def __exit__(
309313
:param exc_type: the exception type if raised
310314
:param exc_value: the exception value if raised
311315
:param traceback: the exception traceback if raised
316+
312317
"""
313318
self.release()
314319

@@ -318,6 +323,6 @@ def __del__(self) -> None:
318323

319324

320325
__all__ = [
321-
"BaseFileLock",
322326
"AcquireReturnProxy",
327+
"BaseFileLock",
323328
]

src/filelock/_unix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ def _release(self) -> None:
6060

6161

6262
__all__ = [
63-
"has_fcntl",
6463
"UnixFileLock",
64+
"has_fcntl",
6565
]

src/filelock/_util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
def raise_on_not_writable_file(filename: str) -> None:
1111
"""
1212
Raise an exception if attempting to open the file for writing would fail.
13-
This is done so files that will never be writable can be separated from
14-
files that are writable but currently locked
13+
14+
This is done so files that will never be writable can be separated from files that are writable but currently
15+
locked.
16+
1517
:param filename: file to check
1618
:raises OSError: as if the file was opened for writing.
19+
1720
"""
1821
try: # use stat to do exists + can write to check without race condition
1922
file_stat = os.stat(filename) # noqa: PTH116
@@ -35,13 +38,15 @@ def raise_on_not_writable_file(filename: str) -> None:
3538

3639
def ensure_directory_exists(filename: Path | str) -> None:
3740
"""
38-
Ensure the directory containing the file exists (create it if necessary)
41+
Ensure the directory containing the file exists (create it if necessary).
42+
3943
:param filename: file.
44+
4045
"""
4146
Path(filename).parent.mkdir(parents=True, exist_ok=True)
4247

4348

4449
__all__ = [
45-
"raise_on_not_writable_file",
4650
"ensure_directory_exists",
51+
"raise_on_not_writable_file",
4752
]

tests/test_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import pickle
3+
import pickle # noqa: S403
44

55
from filelock import Timeout
66

tests/test_filelock.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ def test_ro_file(lock_type: type[BaseFileLock], tmp_file_ro: Path) -> None:
112112
(
113113
pytest.param(PermissionError, "Permission denied:", ".", id="current_directory")
114114
if sys.platform == "win32"
115+
# Should be IsADirectoryError on MacOS and Linux
115116
else (
116-
# Should be IsADirectoryError on MacOS and Linux
117117
pytest.param(IsADirectoryError, "Is a directory", ".", id="current_directory")
118-
if sys.platform in ["darwin", "linux"]
119-
else
118+
if sys.platform in {"darwin", "linux"}
120119
# Should be some type of OSError at least on other operating systems
121-
pytest.param(OSError, None, ".", id="current_directory")
120+
else pytest.param(OSError, None, ".", id="current_directory")
122121
)
123122
),
124123
]

0 commit comments

Comments
 (0)