Skip to content

Commit 3a2c323

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a7e341b commit 3a2c323

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
lines changed

src/auditwheel/elfutils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from typing import Iterator
66

77
from elftools.common.exceptions import ELFError
8-
from elftools.elf.elffile import ELFFile
98
from elftools.elf.dynamic import DynamicSegment
9+
from elftools.elf.elffile import ELFFile
1010

11-
from .libc import Libc
1211
from .lddtree import parse_ld_paths
12+
from .libc import Libc
1313

1414

1515
def elf_read_dt_needed(fn: str) -> list[str]:
@@ -164,6 +164,7 @@ def filter_undefined_symbols(
164164
result[lib] = sorted(intersection)
165165
return result
166166

167+
167168
def elf_get_platform_info(path: str) -> tuple[Libc | None, str | None]:
168169
with open(path, "rb") as f:
169170
try:
@@ -179,19 +180,19 @@ def elf_get_platform_info(path: str) -> tuple[Libc | None, str | None]:
179180
"ARM": "armv7l",
180181
"RISC-V": "riscv64",
181182
}[elf.get_machine_arch()]
182-
if arch == 'ppc64' and elf.header.e_ident.EI_DATA == 'ELFDATA2LSB':
183-
arch = 'ppc64le'
183+
if arch == "ppc64" and elf.header.e_ident.EI_DATA == "ELFDATA2LSB":
184+
arch = "ppc64le"
184185

185186
libc = None
186187
for seg in elf.iter_segments():
187188
if not isinstance(seg, DynamicSegment):
188189
continue
189190
for tag in seg.iter_tags():
190191
if tag.entry.d_tag == "DT_NEEDED":
191-
if tag.needed == 'libc.so.6':
192+
if tag.needed == "libc.so.6":
192193
libc = Libc.GLIBC
193194
break
194-
if tag.needed.startswith('libc.musl-'):
195+
if tag.needed.startswith("libc.musl-"):
195196
libc = Libc.MUSL
196197
break
197198
break

src/auditwheel/main_repair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def execute(args, p):
150150
'cannot repair "%s" to "%s" ABI because of the presence '
151151
"of too-recent versioned symbols. You'll need to compile "
152152
"the wheel on an older toolchain or pick a newer platform."
153-
% (wheel_file, args.PLAT)
153+
% (wheel_file, args.PLAT)
154154
)
155155
p.error(msg)
156156

src/auditwheel/musllinux.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from auditwheel.error import InvalidLibc
99

1010
LOG = logging.getLogger(__name__)
11-
VERSION_RE = re.compile(b'[^.](?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)\0')
11+
VERSION_RE = re.compile(b"[^.](?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)\0")
1212

1313

1414
class MuslVersion(NamedTuple):
@@ -28,14 +28,16 @@ def find_musl_libc(library_path: str | None = None) -> pathlib.Path | None:
2828

2929
def get_musl_version(ld_path: pathlib.Path) -> MuslVersion | None:
3030
try:
31-
with open(ld_path, 'rb') as fp:
31+
with open(ld_path, "rb") as fp:
3232
text = fp.read()
3333
except FileNotFoundError:
3434
return None
3535

3636
for match in VERSION_RE.finditer(text):
3737
return MuslVersion(
38-
int(match.group("major")), int(match.group("minor")), int(match.group("patch"))
38+
int(match.group("major")),
39+
int(match.group("minor")),
40+
int(match.group("patch")),
3941
)
4042

4143
LOG.error("Failed to determine musl version", exc_info=True)

src/auditwheel/policy/__init__.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
from __future__ import annotations
22

3+
import copy
34
import json
45
import logging
56
import platform as _platform_module
67
import re
78
import struct
89
import sys
9-
import copy
1010
from collections import defaultdict
1111
from os.path import abspath, dirname, join
1212
from pathlib import Path
1313
from typing import Any, Generator
1414

15-
from auditwheel.elfutils import filter_undefined_symbols, is_subdir, \
16-
elf_get_platform_info
15+
from auditwheel.elfutils import (
16+
elf_get_platform_info,
17+
filter_undefined_symbols,
18+
is_subdir,
19+
)
1720
from auditwheel.wheeltools import InWheelCtx
1821

1922
from ..libc import Libc, get_libc
@@ -64,15 +67,23 @@ def _reload_policies(self):
6467
if self._libc_variant is None:
6568
self._libc_variant = get_libc() if self._musl_policy is None else Libc.MUSL
6669

67-
if self._libc_variant is not None and self._libc_variant != Libc.MUSL and self._musl_policy is not None:
68-
raise ValueError(f"'musl_policy' shall be None for libc {self._libc_variant.name}")
70+
if (
71+
self._libc_variant is not None
72+
and self._libc_variant != Libc.MUSL
73+
and self._musl_policy is not None
74+
):
75+
raise ValueError(
76+
f"'musl_policy' shall be None for libc {self._libc_variant.name}"
77+
)
6978

70-
if self._libc_variant == Libc.MUSL:
79+
if self._libc_variant == Libc.MUSL:
7180
if self._musl_policy is None:
7281
libc_path = find_musl_libc(self._library_path)
7382
if libc_path is not None:
7483
musl_version = get_musl_version(libc_path)
75-
self._musl_policy = f"musllinux_{musl_version.major}_{musl_version.minor}"
84+
self._musl_policy = (
85+
f"musllinux_{musl_version.major}_{musl_version.minor}"
86+
)
7687
elif _MUSL_POLICY_RE.match(self._musl_policy) is None:
7788
raise ValueError(f"Invalid 'musl_policy': '{self._musl_policy}'")
7889

@@ -87,12 +98,16 @@ def _reload_policies(self):
8798
self._musl_policy,
8899
}:
89100
continue
90-
versioning = policy["symbol_versions"] if policy["name"] != "linux" else {arch: [] for arch in ALL_ARCHES}
101+
versioning = (
102+
policy["symbol_versions"]
103+
if policy["name"] != "linux"
104+
else {arch: [] for arch in ALL_ARCHES}
105+
)
91106
for arch, versions in versioning.items():
92107
if self._arch_name is not None and self._arch_name != arch:
93108
continue
94109
archpolicy = copy.copy(policy)
95-
110+
96111
archpolicy["arch"] = arch
97112
if archpolicy["name"] != "linux":
98113
archpolicy["symbol_versions"] = versions
@@ -141,7 +156,9 @@ def get_policy_by_name(self, name: str) -> dict | None:
141156
raise RuntimeError("Internal error. Policies should be unique")
142157
return matches[0]
143158

144-
def get_policy_name(self, priority: int, default_arch: str | None = None) -> str | None:
159+
def get_policy_name(
160+
self, priority: int, default_arch: str | None = None
161+
) -> str | None:
145162
matches = [p["name"] for p in self._policies if p["priority"] == priority]
146163
if len(matches) == 0:
147164
return None
@@ -165,7 +182,9 @@ def get_policy_name(self, priority: int, default_arch: str | None = None) -> str
165182
if len(matches2) > 1:
166183
raise RuntimeError("Internal error. Priorities should be unique.")
167184
return matches2[0]
168-
raise RuntimeError("Internal error. Every policy should have a known architecture.")
185+
raise RuntimeError(
186+
"Internal error. Every policy should have a known architecture."
187+
)
169188

170189
def get_priority_by_name(self, name: str) -> int | None:
171190
policy = self.get_policy_by_name(name)

tests/unit/test_musllinux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

33
import subprocess
4-
from unittest.mock import patch
54
from io import BytesIO
5+
from unittest.mock import patch
66

77
import pytest
88

@@ -29,7 +29,7 @@ def test_get_musl_version_invalid_path():
2929

3030
@patch("auditwheel.musllinux.open")
3131
def test_get_musl_version_invalid_version(run_mock):
32-
run_mock.return_value = BytesIO(b'jklasdfjkl Version 1.1')
32+
run_mock.return_value = BytesIO(b"jklasdfjkl Version 1.1")
3333
assert get_musl_version("anything") is None
3434

3535

0 commit comments

Comments
 (0)