Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edb8d26

Browse filesBrowse files
authored
Merge pull request #1862 from Borda/lint/ruff
lint: replace `flake8` with `ruff` check
2 parents 49cb48a + 5f889c4 commit edb8d26
Copy full SHA for edb8d26

13 files changed

+77
-50
lines changed

‎.flake8

Copy file name to clipboardExpand all lines: .flake8
-26Lines changed: 0 additions & 26 deletions
This file was deleted.

‎.pre-commit-config.yaml

Copy file name to clipboardExpand all lines: .pre-commit-config.yaml
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ repos:
1414
name: black (format)
1515
exclude: ^git/ext/
1616

17-
- repo: https://github.com/PyCQA/flake8
18-
rev: 6.1.0
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.3.0
1919
hooks:
20-
- id: flake8
21-
additional_dependencies:
22-
- flake8-bugbear==23.9.16
23-
- flake8-comprehensions==3.14.0
24-
- flake8-typing-imports==1.14.0
20+
#- id: ruff-format # todo: eventually replace Black with Ruff for consistency
21+
# args: ["--preview"]
22+
- id: ruff
23+
args: ["--fix"]
2524
exclude: ^doc|^git/ext/
2625

2726
- repo: https://github.com/shellcheck-py/shellcheck-py

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ The same linting, and running tests on all the different supported Python versio
187187
Specific tools:
188188

189189
- Configurations for `mypy`, `pytest`, `coverage.py`, and `black` are in `./pyproject.toml`.
190-
- Configuration for `flake8` is in the `./.flake8` file.
190+
- Configuration for `ruff` is in the `pyproject.toml` file.
191191

192192
Orchestration tools:
193193

‎git/index/base.py

Copy file name to clipboardExpand all lines: git/index/base.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def write(
248248
# Make sure we have our entries read before getting a write lock.
249249
# Otherwise it would be done when streaming.
250250
# This can happen if one doesn't change the index, but writes it right away.
251-
self.entries
251+
self.entries # noqa: B018
252252
lfd = LockedFD(file_path or self._file_path)
253253
stream = lfd.open(write=True, stream=True)
254254

@@ -397,7 +397,7 @@ def from_tree(cls, repo: "Repo", *treeish: Treeish, **kwargs: Any) -> "IndexFile
397397
with TemporaryFileSwap(join_path_native(repo.git_dir, "index")):
398398
repo.git.read_tree(*arg_list, **kwargs)
399399
index = cls(repo, tmp_index)
400-
index.entries # Force it to read the file as we will delete the temp-file.
400+
index.entries # noqa: B018 # Force it to read the file as we will delete the temp-file.
401401
return index
402402
# END index merge handling
403403

@@ -1339,7 +1339,7 @@ def handle_stderr(proc: "Popen[bytes]", iter_checked_out_files: Iterable[PathLik
13391339
# Make sure we have our entries loaded before we start checkout_index, which
13401340
# will hold a lock on it. We try to get the lock as well during our entries
13411341
# initialization.
1342-
self.entries
1342+
self.entries # noqa: B018
13431343

13441344
args.append("--stdin")
13451345
kwargs["as_process"] = True
@@ -1379,7 +1379,7 @@ def handle_stderr(proc: "Popen[bytes]", iter_checked_out_files: Iterable[PathLik
13791379
self._flush_stdin_and_wait(proc, ignore_stdout=True)
13801380
except GitCommandError:
13811381
# Without parsing stdout we don't know what failed.
1382-
raise CheckoutError(
1382+
raise CheckoutError( # noqa: B904
13831383
"Some files could not be checked out from the index, probably because they didn't exist.",
13841384
failed_files,
13851385
[],

‎git/objects/blob.py

Copy file name to clipboardExpand all lines: git/objects/blob.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from mimetypes import guess_type
77
from . import base
88

9-
from git.types import Literal
9+
10+
try:
11+
from typing import Literal
12+
except ImportError:
13+
from typing_extensions import Literal
1014

1115
__all__ = ("Blob",)
1216

‎git/objects/commit.py

Copy file name to clipboardExpand all lines: git/objects/commit.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
Dict,
4545
)
4646

47-
from git.types import PathLike, Literal
47+
from git.types import PathLike
48+
49+
try:
50+
from typing import Literal
51+
except ImportError:
52+
from typing_extensions import Literal
4853

4954
if TYPE_CHECKING:
5055
from git.repo import Repo

‎git/objects/submodule/base.py

Copy file name to clipboardExpand all lines: git/objects/submodule/base.py
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING, cast
4545
from typing import Any, Iterator, Union
4646

47-
from git.types import Commit_ish, Literal, PathLike, TBD
47+
from git.types import Commit_ish, PathLike, TBD
48+
49+
try:
50+
from typing import Literal
51+
except ImportError:
52+
from typing_extensions import Literal
4853

4954
if TYPE_CHECKING:
5055
from git.index import IndexFile
@@ -1445,7 +1450,7 @@ def exists(self) -> bool:
14451450

14461451
try:
14471452
try:
1448-
self.path
1453+
self.path # noqa: B018
14491454
return True
14501455
except Exception:
14511456
return False

‎git/objects/tag.py

Copy file name to clipboardExpand all lines: git/objects/tag.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
from typing import List, TYPE_CHECKING, Union
1818

19-
from git.types import Literal
19+
try:
20+
from typing import Literal
21+
except ImportError:
22+
from typing_extensions import Literal
2023

2124
if TYPE_CHECKING:
2225
from git.repo import Repo

‎git/objects/tree.py

Copy file name to clipboardExpand all lines: git/objects/tree.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
TYPE_CHECKING,
3232
)
3333

34-
from git.types import PathLike, Literal
34+
from git.types import PathLike
35+
36+
try:
37+
from typing import Literal
38+
except ImportError:
39+
from typing_extensions import Literal
3540

3641
if TYPE_CHECKING:
3742
from git.repo import Repo

‎git/objects/util.py

Copy file name to clipboardExpand all lines: git/objects/util.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def _list_traverse(
439439

440440
if not as_edge:
441441
out: IterableList[Union["Commit", "Submodule", "Tree", "Blob"]] = IterableList(id)
442-
out.extend(self.traverse(as_edge=as_edge, *args, **kwargs))
442+
out.extend(self.traverse(as_edge=as_edge, *args, **kwargs)) # noqa: B026
443443
return out
444444
# Overloads in subclasses (mypy doesn't allow typing self: subclass).
445445
# Union[IterableList['Commit'], IterableList['Submodule'], IterableList[Union['Submodule', 'Tree', 'Blob']]]

‎git/refs/symbolic.py

Copy file name to clipboardExpand all lines: git/refs/symbolic.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def is_valid(self) -> bool:
496496
valid object or reference.
497497
"""
498498
try:
499-
self.object
499+
self.object # noqa: B018
500500
except (OSError, ValueError):
501501
return False
502502
else:
@@ -510,7 +510,7 @@ def is_detached(self) -> bool:
510510
instead to another reference.
511511
"""
512512
try:
513-
self.ref
513+
self.ref # noqa: B018
514514
return False
515515
except TypeError:
516516
return True

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+35-1Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ warn_unreachable = true
2929
show_error_codes = true
3030
implicit_reexport = true
3131
# strict = true
32-
3332
# TODO: Remove when 'gitdb' is fully annotated.
3433
exclude = ["^git/ext/gitdb"]
3534
[[tool.mypy.overrides]]
@@ -47,3 +46,38 @@ omit = ["*/git/ext/*"]
4746
line-length = 120
4847
target-version = ["py37"]
4948
extend-exclude = "git/ext/gitdb"
49+
50+
[tool.ruff]
51+
target-version = "py37"
52+
line-length = 120
53+
# Exclude a variety of commonly ignored directories.
54+
exclude = [
55+
"git/ext/",
56+
"doc",
57+
"build",
58+
"dist",
59+
]
60+
# Enable Pyflakes `E` and `F` codes by default.
61+
lint.select = [
62+
"E",
63+
"W", # see: https://pypi.org/project/pycodestyle
64+
"F", # see: https://pypi.org/project/pyflakes
65+
# "I", #see: https://pypi.org/project/isort/
66+
# "S", # see: https://pypi.org/project/flake8-bandit
67+
# "UP", # see: https://docs.astral.sh/ruff/rules/#pyupgrade-up
68+
]
69+
lint.extend-select = [
70+
#"A", # see: https://pypi.org/project/flake8-builtins
71+
"B", # see: https://pypi.org/project/flake8-bugbear
72+
"C4", # see: https://pypi.org/project/flake8-comprehensions
73+
"TCH004", # see: https://docs.astral.sh/ruff/rules/runtime-import-in-type-checking-block/
74+
]
75+
lint.ignore = [
76+
"E203",
77+
"E731", # Do not assign a `lambda` expression, use a `def`
78+
]
79+
lint.ignore-init-module-imports = true
80+
lint.unfixable = ["F401"]
81+
82+
[tool.ruff.lint.per-file-ignores]
83+
"test/**" = ["B018"]

‎requirements-dev.txt

Copy file name to clipboardExpand all lines: requirements-dev.txt
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33

44
# libraries for additional local testing/linting - to be added to test-requirements.txt when all pass
55

6-
flake8-type-checking;python_version>="3.8" # checks for TYPE_CHECKING only imports
7-
86
pytest-icdiff
97
# pytest-profiling

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.