Skip to content

Commit fac01db

Browse files
author
Ashley Anderson
committed
Update API for 'replace_needed' to accept multiple so-name replacement pairs (based on review).
Rebased on main to incorporate CI fixes.
1 parent 141b568 commit fac01db

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

src/auditwheel/patcher.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
from distutils.spawn import find_executable
33
from itertools import chain
44
from subprocess import CalledProcessError, check_call, check_output
5-
from typing import Iterable, Tuple
5+
from typing import Tuple
66

77

88
class ElfPatcher:
9-
def replace_needed(self, file_name: str, so_name: str, new_so_name: str) -> None:
10-
raise NotImplementedError
11-
12-
def replace_needed_multiple(
13-
self, file_name: str, so_name_pairs: Iterable[Tuple[str, str]]
14-
) -> None:
9+
def replace_needed(self, file_name: str, *old_new_pairs: Tuple[str, str]) -> None:
1510
raise NotImplementedError
1611

1712
def set_soname(self, file_name: str, new_so_name: str) -> None:
@@ -48,17 +43,12 @@ class Patchelf(ElfPatcher):
4843
def __init__(self) -> None:
4944
_verify_patchelf()
5045

51-
def replace_needed(self, file_name: str, so_name: str, new_so_name: str) -> None:
52-
check_call(["patchelf", "--replace-needed", so_name, new_so_name, file_name])
53-
54-
def replace_needed_multiple(
55-
self, file_name: str, so_name_pairs: Iterable[Tuple[str, str]]
56-
) -> None:
46+
def replace_needed(self, file_name: str, *old_new_pairs: Tuple[str, str]) -> None:
5747
check_call(
5848
[
5949
"patchelf",
6050
*chain.from_iterable(
61-
("--replace-needed", *pair) for pair in so_name_pairs
51+
("--replace-needed", *pair) for pair in old_new_pairs
6252
),
6353
file_name,
6454
]

src/auditwheel/repair.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def repair_wheel(
8383
soname_map[soname] = (new_soname, new_path)
8484
replacements.append((soname, new_soname))
8585
if replacements:
86-
patcher.replace_needed_multiple(fn, replacements)
86+
patcher.replace_needed(fn, *replacements)
8787

8888
if len(ext_libs) > 0:
8989
new_rpath = os.path.relpath(dest_dir, os.path.dirname(fn))
@@ -101,7 +101,7 @@ def repair_wheel(
101101
if n in soname_map:
102102
replacements.append((n, soname_map[n][0]))
103103
if replacements:
104-
patcher.replace_needed_multiple(path, replacements)
104+
patcher.replace_needed(path, *replacements)
105105

106106
if update_tags:
107107
ctx.out_wheel = add_platforms(ctx, abis, get_replace_platforms(abis[0]))

tests/unit/test_elfpatcher.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ def test_patchelf_version_check_fail(check_output, version):
4141
class TestPatchElf:
4242
""" "Validate that patchelf is invoked with the correct arguments."""
4343

44-
def test_replace_needed(self, check_call, _0, _1):
44+
def test_replace_needed_one(self, check_call, _0, _1):
4545
patcher = Patchelf()
4646
filename = "test.so"
4747
soname_old = "TEST_OLD"
4848
soname_new = "TEST_NEW"
49-
patcher.replace_needed(filename, soname_old, soname_new)
49+
patcher.replace_needed(filename, (soname_old, soname_new))
5050
check_call.assert_called_once_with(
5151
["patchelf", "--replace-needed", soname_old, soname_new, filename]
5252
)
5353

54-
def test_replace_needed_multiple(self, check_call, _0, _1):
54+
def test_replace_needed_multple(self, check_call, _0, _1):
5555
patcher = Patchelf()
5656
filename = "test.so"
5757
replacements = [
5858
("TEST_OLD1", "TEST_NEW1"),
5959
("TEST_OLD2", "TEST_NEW2"),
6060
]
61-
patcher.replace_needed_multiple(filename, replacements)
61+
patcher.replace_needed(filename, *replacements)
6262
check_call.assert_called_once_with(
6363
[
6464
"patchelf",

0 commit comments

Comments
 (0)