Skip to content

Commit 591430d

Browse files
authored
chore: move to ruff (#525)
1 parent c84d80e commit 591430d

33 files changed

+284
-284
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,19 @@ repos:
1919
- id: debug-statements
2020
- id: end-of-file-fixer
2121
exclude: ^cache/
22+
- id: mixed-line-ending
2223
- id: forbid-new-submodules
2324
- id: trailing-whitespace
2425

25-
- repo: https://github.com/asottile/pyupgrade
26-
rev: v3.19.1
26+
- repo: https://github.com/astral-sh/ruff-pre-commit
27+
rev: v0.8.5
2728
hooks:
28-
- id: pyupgrade
29-
args: ["--py39-plus"]
30-
31-
- repo: https://github.com/psf/black
32-
rev: 24.10.0
33-
hooks:
34-
- id: black
35-
36-
- repo: https://github.com/PyCQA/isort
37-
rev: 5.13.2
38-
hooks:
39-
- id: isort
40-
args: ["-a", "from __future__ import annotations"]
41-
exclude: ^tests/integration/.*/src/.*pyx$
42-
43-
- repo: https://github.com/PyCQA/flake8
44-
rev: 7.1.1
45-
hooks:
46-
- id: flake8
29+
- id: ruff
30+
args: ["--fix", "--show-fixes"]
31+
- id: ruff-format
4732

4833
- repo: https://github.com/pre-commit/mirrors-mypy
49-
rev: v1.14.0
34+
rev: v1.14.1
5035
hooks:
5136
- id: mypy
5237
exclude: ^tests/integration/.*/.*$

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_dist(session: nox.Session) -> None:
103103

104104
def _test_dist(session: nox.Session, path: str, pattern: str) -> None:
105105
(dist_path,) = Path(path).glob(pattern)
106-
session.install(f"{str(dist_path)}[test]")
106+
session.install(f"{dist_path!s}[test]")
107107
session.run("pytest", "tests/unit")
108108

109109

pyproject.toml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ build-backend = "setuptools.build_meta"
55
[tool.setuptools_scm]
66
# enable version inference
77

8-
[tool.black]
9-
target-version = ["py39", "py310", "py311", "py312", "py313"]
10-
extend-exclude = "src/auditwheel/_vendor"
11-
12-
[tool.isort]
13-
py_version = 39
14-
profile = "black"
15-
extend_skip_glob = "src/auditwheel/_vendor/**/*.py"
16-
178
[tool.mypy]
189
follow_imports = "silent"
1910
ignore_missing_imports = true
@@ -23,3 +14,39 @@ warn_unused_ignores = true
2314
module = "auditwheel._vendor.*"
2415
follow_imports = "skip"
2516
ignore_errors = true
17+
18+
[tool.pytest.ini_options]
19+
log_cli = true
20+
log_cli_level = 20
21+
22+
[tool.ruff]
23+
target-version = "py39"
24+
exclude = ["src/auditwheel/_vendor"]
25+
26+
[tool.ruff.lint]
27+
extend-select = [
28+
"B", # flake8-bugbear
29+
"I", # isort
30+
"ARG", # flake8-unused-arguments
31+
"C4", # flake8-comprehensions
32+
"EM", # flake8-errmsg
33+
"ICN", # flake8-import-conventions
34+
"ISC", # flake8-implicit-str-concat
35+
"G", # flake8-logging-format
36+
"PGH", # pygrep-hooks
37+
"PIE", # flake8-pie
38+
"PL", # pylint
39+
"PT", # flake8-pytest-style
40+
"RET", # flake8-return
41+
"RUF", # Ruff-specific
42+
"SIM", # flake8-simplify
43+
"TID251", # flake8-tidy-imports.banned-api
44+
"UP", # pyupgrade
45+
"YTT", # flake8-2020
46+
"EXE", # flake8-executable
47+
"PYI", # flake8-pyi
48+
]
49+
ignore = [
50+
"ISC001", # Conflicts with formatter
51+
"PLR", # Design related pylint codes
52+
]

scripts/calculate_symbol_versions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
import argparse
10+
import contextlib
1011
import json
1112
import os
1213
import platform
@@ -32,16 +33,17 @@ def choose_policy(name, policies):
3233
try:
3334
return next(policy for policy in policies if policy["name"] == name)
3435
except StopIteration:
35-
raise RuntimeError(f"Unknown policy {name}")
36+
msg = f"Unknown policy {name}"
37+
raise RuntimeError(msg) from None
3638

3739

3840
def find_library(library):
3941
for p in LIBRARY_PATHS:
4042
path = os.path.join(p, library)
4143
if os.path.exists(path):
4244
return path
43-
else:
44-
raise RuntimeError(f"Unknown library {library}")
45+
msg = f"Unknown library {library}"
46+
raise RuntimeError(msg)
4547

4648

4749
def versionify(version_string):
@@ -67,11 +69,8 @@ def calculate_symbol_versions(libraries, symbol_versions, arch):
6769
if section:
6870
for _, verdef_iter in section.iter_versions():
6971
for vernaux in verdef_iter:
70-
for symbol_name in symbol_versions:
71-
try:
72-
name, version = vernaux.name.split("_", 1)
73-
except ValueError:
74-
pass
72+
with contextlib.suppress(ValueError):
73+
name, version = vernaux.name.split("_", 1)
7574
if (
7675
name in calculated_symbol_versions
7776
and version != "PRIVATE"

setup.cfg

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,3 @@ where = src
4444
[options.entry_points]
4545
console_scripts =
4646
auditwheel = auditwheel.main:main
47-
48-
[tool:pytest]
49-
log_cli = true
50-
log_cli_level = 20
51-
52-
[flake8]
53-
ignore = E203,W503
54-
max-line-length = 88
55-
exclude =
56-
_vendor

setup.py

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": ["pytest>=3.4", "jsonschema", "pypatchelf", "pretend", "docker"],
77
"coverage": ["pytest-cov"],
88
}
9-
extras["develop"] = sum(extras.values(), [])
109
extras["coverage"] += extras["test"]
10+
extras["develop"] = list({dep for deps in extras.values() for dep in deps})
1111

1212
setup(extras_require=extras)

src/auditwheel/condatools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def __enter__(self):
3232

3333
def iter_files(self) -> list[str]:
3434
if self.path is None:
35-
raise ValueError("This function should be called from context manager")
35+
msg = "This function should be called from context manager"
36+
raise ValueError(msg)
3637
files = os.path.join(self.path, "info", "files")
3738
with open(files) as f:
3839
return [line.strip() for line in f.readlines()]

src/auditwheel/elfutils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def elf_read_dt_needed(fn: str) -> list[str]:
1616
elf = ELFFile(f)
1717
section = elf.get_section_by_name(".dynamic")
1818
if section is None:
19-
raise ValueError("Could not find soname in %s" % fn)
19+
msg = f"Could not find soname in {fn}"
20+
raise ValueError(msg)
2021

2122
for t in section.iter_tags():
2223
if t.entry.d_tag == "DT_NEEDED":

src/auditwheel/genericpkgctx.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ def InGenericPkgCtx(
1616
if out_path is not None:
1717
raise NotImplementedError()
1818
return InCondaPkgCtx(in_path)
19-
20-
raise ValueError(
21-
"Invalid package: %s. File formats supported: " ".whl, .tar.bz2" % in_path
22-
)
19+
msg = f"Invalid package: {in_path}. File formats supported: .whl, .tar.bz2"
20+
raise ValueError(msg)

src/auditwheel/lddtree.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ def parse_ld_paths(str_ldpaths: str, path: str, root: str = "") -> list[str]:
106106
for ldpath in str_ldpaths.split(":"):
107107
if ldpath == "":
108108
# The ldso treats "" paths as $PWD.
109-
ldpath = os.getcwd()
109+
ldpath_ = os.getcwd()
110110
elif "$ORIGIN" in ldpath:
111-
ldpath = ldpath.replace("$ORIGIN", os.path.dirname(os.path.abspath(path)))
111+
ldpath_ = ldpath.replace("$ORIGIN", os.path.dirname(os.path.abspath(path)))
112112
else:
113-
ldpath = root + ldpath
114-
ldpaths.append(normpath(ldpath))
113+
ldpath_ = root + ldpath
114+
ldpaths.append(normpath(ldpath_))
115115
return [p for p in dedupe(ldpaths) if os.path.isdir(p)]
116116

117117

@@ -140,8 +140,8 @@ def parse_ld_so_conf(ldso_conf: str, root: str = "/", _first: bool = True) -> li
140140
try:
141141
log.debug("%sparse_ld_so_conf(%s)", dbg_pfx, ldso_conf)
142142
with open(ldso_conf) as f:
143-
for line in f.readlines():
144-
line = line.split("#", 1)[0].strip()
143+
for input_line in f.readlines():
144+
line = input_line.split("#", 1)[0].strip()
145145
if not line:
146146
continue
147147
if line.startswith("include "):
@@ -242,15 +242,7 @@ def compatible_elfs(elf1: ELFFile, elf2: ELFFile) -> bool:
242242
"""
243243
osabis = frozenset(e.header["e_ident"]["EI_OSABI"] for e in (elf1, elf2))
244244
compat_sets = (
245-
frozenset(
246-
"ELFOSABI_%s" % x
247-
for x in (
248-
"NONE",
249-
"SYSV",
250-
"GNU",
251-
"LINUX",
252-
)
253-
),
245+
frozenset(f"ELFOSABI_{x}" for x in ("NONE", "SYSV", "GNU", "LINUX")),
254246
)
255247
return (
256248
(len(osabis) == 1 or any(osabis.issubset(x) for x in compat_sets))
@@ -302,8 +294,7 @@ def lddtree(
302294
ldpaths: dict[str, list[str]] | None = None,
303295
display: str | None = None,
304296
exclude: frozenset[str] = frozenset(),
305-
_first: bool = True,
306-
_all_libs: dict = {},
297+
_all_libs: dict | None = None,
307298
) -> dict:
308299
"""Parse the ELF dependency tree of the specified file
309300
@@ -324,8 +315,6 @@ def lddtree(
324315
The path to show rather than ``path``
325316
exclude
326317
List of soname (DT_NEEDED) to exclude from the tree
327-
_first
328-
Recursive use only; is this the first ELF?
329318
_all_libs
330319
Recursive use only; dict of all libs we've seen
331320
@@ -350,7 +339,8 @@ def lddtree(
350339
if not ldpaths:
351340
ldpaths = load_ld_paths().copy()
352341

353-
if _first:
342+
_first = _all_libs is None
343+
if _all_libs is None:
354344
_all_libs = {}
355345

356346
ret: dict[str, Any] = {
@@ -363,7 +353,7 @@ def lddtree(
363353
"libs": _all_libs,
364354
}
365355

366-
log.debug("lddtree(%s)" % path)
356+
log.debug("lddtree(%s)", path)
367357

368358
with open(path, "rb") as f:
369359
elf = ELFFile(f)
@@ -407,7 +397,7 @@ def lddtree(
407397
runpaths = parse_ld_paths(t.runpath, path=path, root=root)
408398
elif t.entry.d_tag == "DT_NEEDED":
409399
if any(fnmatch(t.needed, e) for e in exclude):
410-
log.info(f"Excluding {t.needed}")
400+
log.info("Excluding %s", t.needed)
411401
else:
412402
libs.append(t.needed)
413403
if runpaths:
@@ -457,7 +447,6 @@ def lddtree(
457447
ldpaths,
458448
display=fullpath,
459449
exclude=exclude,
460-
_first=False,
461450
_all_libs=_all_libs,
462451
)
463452
_all_libs[lib]["needed"] = lret["needed"]

0 commit comments

Comments
 (0)