Skip to content

Commit f8bec2f

Browse files
authored
Fix CI and build failures (#7190)
* Migrate linting from various tooling to Ruff * Run ruff over codebase * Drop support for pypy-3.10
1 parent 7029833 commit f8bec2f

19 files changed

Lines changed: 73 additions & 72 deletions

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev", "pypy-3.10", "pypy-3.11"]
15+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev", "pypy-3.11"]
1616
os: [ubuntu-22.04, macOS-latest, windows-latest]
1717
# Pypy-3.11 can't install openssl-sys with rust
1818
# which prevents us from testing in GHA.

.pre-commit-config.yaml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,12 @@ repos:
55
rev: v4.4.0
66
hooks:
77
- id: check-yaml
8-
- id: debug-statements
98
- id: end-of-file-fixer
109
- id: trailing-whitespace
11-
- repo: https://github.com/PyCQA/isort
12-
rev: 5.12.0
10+
- repo: https://github.com/astral-sh/ruff-pre-commit
11+
rev: v0.9.3
1312
hooks:
14-
- id: isort
15-
- repo: https://github.com/psf/black
16-
rev: 23.7.0
17-
hooks:
18-
- id: black
13+
- id: ruff
14+
args: [--fix]
15+
- id: ruff-format
1916
exclude: tests/test_lowlevel.py
20-
- repo: https://github.com/asottile/pyupgrade
21-
rev: v3.10.1
22-
hooks:
23-
- id: pyupgrade
24-
args: [--py37-plus]
25-
- repo: https://github.com/PyCQA/flake8
26-
rev: 6.1.0
27-
hooks:
28-
- id: flake8

pyproject.toml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
[tool.isort]
2-
profile = "black"
3-
src_paths = ["src/requests", "test"]
4-
honor_noqa = true
1+
[tool.ruff]
2+
target-version = "py310"
3+
src = ["src/requests", "tests"]
4+
exclude = ["docs/", "ext/"]
5+
6+
[tool.ruff.lint]
7+
select = [
8+
"E", # pycodestyle errors
9+
"W", # pycodestyle warnings
10+
"F", # pyflakes
11+
"I", # isort
12+
"UP", # pyupgrade
13+
"T10", # flake8-debugger (replaces debug-statements hook)
14+
]
15+
ignore = ["E203", "E501", "UP038", "UP031"]
16+
per-file-ignores = {"src/requests/__init__.py" = ["E402", "F401"], "src/requests/compat.py" = ["E402", "F401"], "tests/compat.py" = ["F401"]}
17+
18+
[tool.ruff.lint.isort]
19+
known-first-party = ["requests"]
20+
21+
[tool.ruff.format]
22+
# Use black-compatible formatting
23+
quote-style = "double"
24+
indent-style = "space"
525

626
[tool.pytest.ini_options]
727
addopts = "--doctest-modules"

setup.cfg

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,3 @@ requires-dist =
88
charset_normalizer>=2,<4
99
idna>=2.5,<4
1010
urllib3>=1.21.1,<3
11-
12-
[flake8]
13-
ignore = E203, E501, W503
14-
per-file-ignores =
15-
src/requests/__init__.py:E402, F401
16-
src/requests/compat.py:E402, F401
17-
tests/compat.py:F401

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
2121
If you can't upgrade your Python version, you'll need to
2222
pin to an older version of Requests (<2.32.0).
23-
""".format(
24-
*(REQUIRED_PYTHON + CURRENT_PYTHON)
25-
)
23+
""".format(*(REQUIRED_PYTHON + CURRENT_PYTHON))
2624
)
2725
sys.exit(1)
2826

src/requests/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def _check_cryptography(cryptography_version):
9898
return
9999

100100
if cryptography_version < [1, 3, 4]:
101-
warning = "Old version of cryptography ({}) may cause slowdown.".format(
102-
cryptography_version
101+
warning = (
102+
f"Old version of cryptography ({cryptography_version}) may cause slowdown."
103103
)
104104
warnings.warn(warning, RequestsDependencyWarning)
105105

@@ -111,10 +111,9 @@ def _check_cryptography(cryptography_version):
111111
)
112112
except (AssertionError, ValueError):
113113
warnings.warn(
114-
"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
115-
"version!".format(
116-
urllib3.__version__, chardet_version, charset_normalizer_version
117-
),
114+
f"urllib3 ({urllib3.__version__}) or chardet "
115+
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
116+
"doesn't match a supported version!",
118117
RequestsDependencyWarning,
119118
)
120119

src/requests/_internal_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Provides utility functions that are consumed internally by Requests
66
which depend on extremely few external helpers (such as compat)
77
"""
8+
89
import re
910

1011
from .compat import builtin_str

src/requests/adapters.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
import typing
1212
import warnings
1313

14-
from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
15-
from urllib3.exceptions import HTTPError as _HTTPError
16-
from urllib3.exceptions import InvalidHeader as _InvalidHeader
1714
from urllib3.exceptions import (
15+
ClosedPoolError,
16+
ConnectTimeoutError,
1817
LocationValueError,
1918
MaxRetryError,
2019
NewConnectionError,
2120
ProtocolError,
21+
ReadTimeoutError,
22+
ResponseError,
2223
)
24+
from urllib3.exceptions import HTTPError as _HTTPError
25+
from urllib3.exceptions import InvalidHeader as _InvalidHeader
2326
from urllib3.exceptions import ProxyError as _ProxyError
24-
from urllib3.exceptions import ReadTimeoutError, ResponseError
2527
from urllib3.exceptions import SSLError as _SSLError
2628
from urllib3.poolmanager import PoolManager, proxy_from_url
2729
from urllib3.util import Timeout as TimeoutSauce
@@ -76,9 +78,9 @@ def SOCKSProxyManager(*args, **kwargs):
7678
def _urllib3_request_context(
7779
request: "PreparedRequest",
7880
verify: "bool | str | None",
79-
client_cert: "typing.Tuple[str, str] | str | None",
81+
client_cert: "tuple[str, str] | str | None",
8082
poolmanager: "PoolManager",
81-
) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])":
83+
) -> "(dict[str, typing.Any], dict[str, typing.Any])":
8284
host_params = {}
8385
pool_kwargs = {}
8486
parsed_request_url = urlparse(request.url)

src/requests/auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ def _basic_auth_str(username, password):
3535
if not isinstance(username, basestring):
3636
warnings.warn(
3737
"Non-string usernames will no longer be supported in Requests "
38-
"3.0.0. Please convert the object you've passed in ({!r}) to "
38+
f"3.0.0. Please convert the object you've passed in ({username!r}) to "
3939
"a string or bytes object in the near future to avoid "
40-
"problems.".format(username),
40+
"problems.",
4141
category=DeprecationWarning,
4242
)
4343
username = str(username)
4444

4545
if not isinstance(password, basestring):
4646
warnings.warn(
4747
"Non-string passwords will no longer be supported in Requests "
48-
"3.0.0. Please convert the object you've passed in ({!r}) to "
48+
f"3.0.0. Please convert the object you've passed in ({type(password)!r}) to "
4949
"a string or bytes object in the near future to avoid "
50-
"problems.".format(type(password)),
50+
"problems.",
5151
category=DeprecationWarning,
5252
)
5353
password = str(password)

src/requests/certs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
environment, you can change the definition of where() to return a separately
1212
packaged CA bundle.
1313
"""
14+
1415
from certifi import where
1516

1617
if __name__ == "__main__":

0 commit comments

Comments
 (0)