Skip to content

Commit 551e822

Browse files
authored
Merge pull request #12595 from notatallshaw/update-ruff-to-v0.3.4
Update ruff to v0.3.6
2 parents 550388e + f633c5d commit 551e822

17 files changed

+52
-62
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
- id: black
2323

2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.2.0
25+
rev: v0.3.6
2626
hooks:
2727
- id: ruff
2828
args: [--fix, --exit-non-zero-on-fix]

news/12595.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update ruff pre-commit to v0.3.6

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ max-complexity = 33 # default is 10
201201
"src/pip/_internal/*" = ["PERF203"]
202202
"tests/*" = ["B011"]
203203
"tests/unit/test_finder.py" = ["C414"]
204+
"src/pip/__pip-runner__.py" = ["UP"] # Must be compatible with Python 2.7
204205

205206
[tool.ruff.lint.pylint]
206207
max-args = 15 # default is 5

src/pip/_internal/commands/search.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ def search(self, query: List[str], options: Values) -> List[Dict[str, str]]:
7575
try:
7676
hits = pypi.search({"name": query, "summary": query}, "or")
7777
except xmlrpc.client.Fault as fault:
78-
message = "XMLRPC request failed [code: {code}]\n{string}".format(
79-
code=fault.faultCode,
80-
string=fault.faultString,
78+
message = (
79+
f"XMLRPC request failed [code: {fault.faultCode}]\n{fault.faultString}"
8180
)
8281
raise CommandError(message)
8382
assert isinstance(hits, list)

src/pip/_internal/models/candidate.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ def __init__(self, name: str, version: str, link: Link) -> None:
2020
)
2121

2222
def __repr__(self) -> str:
23-
return "<InstallationCandidate({!r}, {!r}, {!r})>".format(
24-
self.name,
25-
self.version,
26-
self.link,
23+
return (
24+
f"<InstallationCandidate({self.name!r}, {self.version!r}, {self.link!r})>"
2725
)
2826

2927
def __str__(self) -> str:

src/pip/_internal/operations/build/build_tracker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import logging
44
import os
55
from types import TracebackType
6-
from typing import Dict, Generator, Optional, Set, Type, Union
6+
from typing import Dict, Generator, Optional, Type, Union
77

8-
from pip._internal.models.link import Link
98
from pip._internal.req.req_install import InstallRequirement
109
from pip._internal.utils.temp_dir import TempDirectory
1110

src/pip/_internal/operations/build/wheel_legacy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ def get_legacy_build_wheel_path(
4040
# Sort for determinism.
4141
names = sorted(names)
4242
if not names:
43-
msg = ("Legacy build of wheel for {!r} created no files.\n").format(name)
43+
msg = f"Legacy build of wheel for {name!r} created no files.\n"
4444
msg += format_command_result(command_args, command_output)
4545
logger.warning(msg)
4646
return None
4747

4848
if len(names) > 1:
4949
msg = (
50-
"Legacy build of wheel for {!r} created more than one file.\n"
51-
"Filenames (choosing first): {}\n"
52-
).format(name, names)
50+
f"Legacy build of wheel for {name!r} created more than one file.\n"
51+
f"Filenames (choosing first): {names}\n"
52+
)
5353
msg += format_command_result(command_args, command_output)
5454
logger.warning(msg)
5555

src/pip/_internal/operations/install/wheel.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,21 @@ def make_data_scheme_file(record_path: RecordPath) -> "File":
505505
_, scheme_key, dest_subpath = normed_path.split(os.path.sep, 2)
506506
except ValueError:
507507
message = (
508-
"Unexpected file in {}: {!r}. .data directory contents"
509-
" should be named like: '<scheme key>/<path>'."
510-
).format(wheel_path, record_path)
508+
f"Unexpected file in {wheel_path}: {record_path!r}. .data directory"
509+
" contents should be named like: '<scheme key>/<path>'."
510+
)
511511
raise InstallationError(message)
512512

513513
try:
514514
scheme_path = scheme_paths[scheme_key]
515515
except KeyError:
516516
valid_scheme_keys = ", ".join(sorted(scheme_paths))
517517
message = (
518-
"Unknown scheme key used in {}: {} (for file {!r}). .data"
519-
" directory contents should be in subdirectories named"
520-
" with a valid scheme key ({})"
521-
).format(wheel_path, scheme_key, record_path, valid_scheme_keys)
518+
f"Unknown scheme key used in {wheel_path}: {scheme_key} "
519+
f"(for file {record_path!r}). .data directory contents "
520+
f"should be in subdirectories named with a valid scheme "
521+
f"key ({valid_scheme_keys})"
522+
)
522523
raise InstallationError(message)
523524

524525
dest_path = os.path.join(scheme_path, dest_subpath)

src/pip/_internal/req/constructors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def parse_editable(editable_req: str) -> Tuple[Optional[str], str, Set[str]]:
132132
package_name = link.egg_fragment
133133
if not package_name:
134134
raise InstallationError(
135-
"Could not detect requirement name for '{}', please specify one "
136-
"with #egg=your_package_name".format(editable_req)
135+
f"Could not detect requirement name for '{editable_req}', "
136+
"please specify one with #egg=your_package_name"
137137
)
138138
return package_name, url, set()
139139

src/pip/_internal/req/req_install.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ def __str__(self) -> str:
222222
return s
223223

224224
def __repr__(self) -> str:
225-
return "<{} object: {} editable={!r}>".format(
226-
self.__class__.__name__, str(self), self.editable
225+
return (
226+
f"<{self.__class__.__name__} object: "
227+
f"{str(self)} editable={self.editable!r}>"
227228
)
228229

229230
def format_debug(self) -> str:

src/pip/_internal/req/req_uninstall.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,9 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
510510

511511
elif dist.installed_by_distutils:
512512
raise UninstallationError(
513-
"Cannot uninstall {!r}. It is a distutils installed project "
514-
"and thus we cannot accurately determine which files belong "
515-
"to it which would lead to only a partial uninstall.".format(
516-
dist.raw_name,
517-
)
513+
f"Cannot uninstall {dist.raw_name!r}. It is a distutils installed "
514+
"project and thus we cannot accurately determine which files belong "
515+
"to it which would lead to only a partial uninstall."
518516
)
519517

520518
elif dist.installed_as_egg:

src/pip/_internal/resolution/legacy/resolver.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ def _check_dist_requires_python(
104104
return
105105

106106
raise UnsupportedPythonVersion(
107-
"Package {!r} requires a different Python: {} not in {!r}".format(
108-
dist.raw_name, version, requires_python
109-
)
107+
f"Package {dist.raw_name!r} requires a different Python: "
108+
f"{version} not in {requires_python!r}"
110109
)
111110

112111

@@ -263,9 +262,8 @@ def _add_requirement_to_set(
263262
)
264263
if has_conflicting_requirement:
265264
raise InstallationError(
266-
"Double requirement given: {} (already in {}, name={!r})".format(
267-
install_req, existing_req, install_req.name
268-
)
265+
f"Double requirement given: {install_req} "
266+
f"(already in {existing_req}, name={install_req.name!r})"
269267
)
270268

271269
# When no existing requirement exists, add the requirement as a

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,9 @@ def version(self) -> CandidateVersion:
191191
return self._version
192192

193193
def format_for_error(self) -> str:
194-
return "{} {} (from {})".format(
195-
self.name,
196-
self.version,
197-
self._link.file_path if self._link.is_file else self._link,
194+
return (
195+
f"{self.name} {self.version} "
196+
f"(from {self._link.file_path if self._link.is_file else self._link})"
198197
)
199198

200199
def _prepare_distribution(self) -> BaseDistribution:
@@ -269,9 +268,9 @@ def __init__(
269268
# Version may not be present for PEP 508 direct URLs
270269
if version is not None:
271270
wheel_version = Version(wheel.version)
272-
assert version == wheel_version, "{!r} != {!r} for wheel {}".format(
273-
version, wheel_version, name
274-
)
271+
assert (
272+
version == wheel_version
273+
), f"{version!r} != {wheel_version!r} for wheel {name}"
275274

276275
if cache_entry is not None:
277276
assert ireq.link.is_wheel

src/pip/_internal/utils/direct_url_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def direct_url_as_pep440_direct_reference(direct_url: DirectUrl, name: str) -> s
1212
requirement = name + " @ "
1313
fragments = []
1414
if isinstance(direct_url.info, VcsInfo):
15-
requirement += "{}+{}@{}".format(
16-
direct_url.info.vcs, direct_url.url, direct_url.info.commit_id
15+
requirement += (
16+
f"{direct_url.info.vcs}+{direct_url.url}@{direct_url.info.commit_id}"
1717
)
1818
elif isinstance(direct_url.info, ArchiveInfo):
1919
requirement += direct_url.url

tests/functional/test_build_env.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ def run_with_build_env(
2424
test_script_contents: Optional[str] = None,
2525
) -> TestPipResult:
2626
build_env_script = script.scratch_path / "build_env.py"
27+
scratch_path = str(script.scratch_path)
2728
build_env_script.write_text(
2829
dedent(
29-
"""
30+
f"""
3031
import subprocess
3132
import sys
3233
@@ -42,7 +43,7 @@ def run_with_build_env(
4243
4344
link_collector = LinkCollector(
4445
session=PipSession(),
45-
search_scope=SearchScope.create([{scratch!r}], [], False),
46+
search_scope=SearchScope.create([{scratch_path!r}], [], False),
4647
)
4748
selection_prefs = SelectionPreferences(
4849
allow_yanked=True,
@@ -54,9 +55,7 @@ def run_with_build_env(
5455
5556
with global_tempdir_manager():
5657
build_env = BuildEnvironment()
57-
""".format(
58-
scratch=str(script.scratch_path)
59-
)
58+
"""
6059
)
6160
+ indent(dedent(setup_script_contents), " ")
6261
+ indent(

tests/functional/test_new_resolver_hashes.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,15 @@ def test_new_resolver_hash_intersect_from_constraint(
8989
script: PipTestEnvironment,
9090
) -> None:
9191
find_links = _create_find_links(script)
92+
sdist_hash = find_links.sdist_hash
9293

9394
constraints_txt = script.scratch_path / "constraints.txt"
94-
constraints_txt.write_text(
95-
f"base==0.1.0 --hash=sha256:{find_links.sdist_hash}",
96-
)
95+
constraints_txt.write_text(f"base==0.1.0 --hash=sha256:{sdist_hash}")
9796
requirements_txt = script.scratch_path / "requirements.txt"
9897
requirements_txt.write_text(
99-
"""
100-
base==0.1.0 --hash=sha256:{sdist_hash} --hash=sha256:{wheel_hash}
101-
""".format(
102-
sdist_hash=find_links.sdist_hash,
103-
wheel_hash=find_links.wheel_hash,
104-
),
98+
f"""
99+
base==0.1.0 --hash=sha256:{sdist_hash} --hash=sha256:{find_links.wheel_hash}
100+
""",
105101
)
106102

107103
result = script.pip(

tests/unit/test_collector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@ def test_get_index_content_invalid_content_type(
802802
assert (
803803
"pip._internal.index.collector",
804804
logging.WARNING,
805-
"Skipping page {} because the GET request got Content-Type: {}. "
806-
"The only supported Content-Types are application/vnd.pypi.simple.v1+json, "
807-
"application/vnd.pypi.simple.v1+html, and text/html".format(url, content_type),
805+
f"Skipping page {url} because the GET request got Content-Type: {content_type}."
806+
" The only supported Content-Types are application/vnd.pypi.simple.v1+json, "
807+
"application/vnd.pypi.simple.v1+html, and text/html",
808808
) in caplog.record_tuples
809809

810810

0 commit comments

Comments
 (0)