Skip to content

Commit 72a32e9

Browse files
authored
Merge pull request #12073 from pfmoore/ruff
Switch to ruff for linting
2 parents 5e8e88e + bdef915 commit 72a32e9

File tree

10 files changed

+66
-26
lines changed

10 files changed

+66
-26
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,11 @@ repos:
2121
hooks:
2222
- id: black
2323

24-
- repo: https://github.com/PyCQA/flake8
25-
rev: 6.0.0
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
# Ruff version.
26+
rev: v0.0.270
2627
hooks:
27-
- id: flake8
28-
additional_dependencies: [
29-
'flake8-bugbear',
30-
'flake8-logging-format',
31-
'flake8-implicit-str-concat',
32-
]
33-
exclude: tests/data
34-
35-
- repo: https://github.com/PyCQA/isort
36-
rev: 5.12.0
37-
hooks:
38-
- id: isort
39-
files: \.py$
28+
- id: ruff
4029

4130
- repo: https://github.com/pre-commit/mirrors-mypy
4231
rev: v0.961

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def pinned_requirements(path: Path) -> Iterator[Tuple[str, str]]:
219219
new_version = old_version
220220
for inner_name, inner_version in pinned_requirements(vendor_txt):
221221
if inner_name == name:
222-
# this is a dedicated assignment, to make flake8 happy
222+
# this is a dedicated assignment, to make lint happy
223223
new_version = inner_version
224224
break
225225
else:

pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,38 @@ setuptools = "pkg_resources"
7171
CacheControl = "https://raw.githubusercontent.com/ionrock/cachecontrol/v0.12.6/LICENSE.txt"
7272
distlib = "https://bitbucket.org/pypa/distlib/raw/master/LICENSE.txt"
7373
webencodings = "https://github.com/SimonSapin/python-webencodings/raw/master/LICENSE"
74+
75+
[tool.ruff]
76+
extend-exclude = [
77+
"./build",
78+
".scratch",
79+
"_vendor",
80+
"data",
81+
]
82+
ignore = [
83+
"B019",
84+
"B020",
85+
"B904", # Ruff enables opinionated warnings by default
86+
"B905", # Ruff enables opinionated warnings by default
87+
"G202",
88+
]
89+
line-length = 88
90+
select = [
91+
"B",
92+
"E",
93+
"F",
94+
"W",
95+
"G",
96+
"ISC",
97+
"I",
98+
]
99+
100+
[tool.ruff.per-file-ignores]
101+
"noxfile.py" = ["G"]
102+
"tests/*" = ["B011"]
103+
104+
[tool.ruff.isort]
105+
# We need to explicitly make pip "first party" as it's imported by code in
106+
# the docs and tests directories.
107+
known-first-party = ["pip"]
108+
known-third-party = ["pip._vendor"]

src/pip/_internal/network/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ def handle_401(self, resp: Response, **kwargs: Any) -> Response:
514514

515515
# Consume content and release the original connection to allow our new
516516
# request to reuse the same one.
517-
resp.content
517+
# The result of the assignment isn't used, it's just needed to consume
518+
# the content.
519+
_ = resp.content
518520
resp.raw.release_conn()
519521

520522
# Add our new username and password to the request

tests/functional/test_install_compat.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
import pytest
99

10-
from tests.lib import pyversion # noqa: F401
11-
from tests.lib import PipTestEnvironment, TestData, assert_all_changes
10+
from tests.lib import (
11+
PipTestEnvironment,
12+
TestData,
13+
assert_all_changes,
14+
pyversion, # noqa: F401
15+
)
1216

1317

1418
@pytest.mark.network

tests/functional/test_install_upgrade.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
import pytest
88

9-
from tests.lib import pyversion # noqa: F401
10-
from tests.lib import PipTestEnvironment, ResolverVariant, TestData, assert_all_changes
9+
from tests.lib import (
10+
PipTestEnvironment,
11+
ResolverVariant,
12+
TestData,
13+
assert_all_changes,
14+
pyversion, # noqa: F401
15+
)
1116
from tests.lib.local_repos import local_checkout
1217
from tests.lib.wheel import make_wheel
1318

tests/functional/test_install_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import pytest
1010

11-
from tests.lib import pyversion # noqa: F401
1211
from tests.lib import (
1312
PipTestEnvironment,
1413
TestData,
1514
create_basic_wheel_for_package,
1615
need_svn,
16+
pyversion, # noqa: F401
1717
)
1818
from tests.lib.local_repos import local_checkout
1919
from tests.lib.venv import VirtualEnvironment

tests/functional/test_install_vcs_git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
import pytest
55

6-
from tests.lib import pyversion # noqa: F401
76
from tests.lib import (
87
PipTestEnvironment,
98
_change_test_package_version,
109
_create_test_package,
10+
pyversion, # noqa: F401
1111
)
1212
from tests.lib.git_submodule_helpers import (
1313
_change_test_package_submodule,

tests/functional/test_wheel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
import pytest
88

99
from pip._internal.cli.status_codes import ERROR
10-
from tests.lib import pyversion # noqa: F401
11-
from tests.lib import PipTestEnvironment, TestData
10+
from tests.lib import (
11+
PipTestEnvironment,
12+
TestData,
13+
pyversion, # noqa: F401
14+
)
1215

1316

1417
def add_files_to_dist_directory(folder: Path) -> None:

tests/lib/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ def run(
684684
# Pass expect_stderr=True to allow any stderr. We do this because
685685
# we do our checking of stderr further on in check_stderr().
686686
kw["expect_stderr"] = True
687-
result = super().run(cwd=cwd, *args, **kw)
687+
# Ignore linter check
688+
# B026 Star-arg unpacking after a keyword argument is strongly discouraged
689+
result = super().run(cwd=cwd, *args, **kw) # noqa: B026
688690

689691
if expect_error and not allow_error:
690692
if result.returncode == 0:

0 commit comments

Comments
 (0)