Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edb8d26

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

File tree

13 files changed

+77
-50
lines changed

13 files changed

+77
-50
lines changed

.flake8

Lines changed: 0 additions & 26 deletions
This file was deleted.

.pre-commit-config.yaml

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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']]]

0 commit comments

Comments
 (0)