Skip to content

Commit

Permalink
Add ability to pass wildcard arguments to --exclude (pypa#508)
Browse files Browse the repository at this point in the history
* Add ability to pass wildcard arguments to --exclude

Fixes pypa#500

* Test sequences

* add comment about wheel metadata

---------

Co-authored-by: mayeut <[email protected]>
  • Loading branch information
KyleFromNVIDIA and mayeut authored Jan 4, 2025
1 parent 5ba0b78 commit c84d80e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/auditwheel/lddtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import glob
import logging
import os
from fnmatch import fnmatch
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -405,7 +406,7 @@ def lddtree(
elif t.entry.d_tag == "DT_RUNPATH":
runpaths = parse_ld_paths(t.runpath, path=path, root=root)
elif t.entry.d_tag == "DT_NEEDED":
if t.needed in exclude:
if any(fnmatch(t.needed, e) for e in exclude):
log.info(f"Excluding {t.needed}")
else:
libs.append(t.needed)
Expand Down
5 changes: 4 additions & 1 deletion src/auditwheel/main_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def configure_parser(sub_parsers):
"--exclude",
dest="EXCLUDE",
help="Exclude SONAME from grafting into the resulting wheel "
"(can be specified multiple times)",
"Please make sure wheel metadata reflects your dependencies. "
"See https://github.com/pypa/auditwheel/pull/411#issuecomment-1500826281 "
"(can be specified multiple times) "
"(can contain wildcards, for example libfoo.so.*)",
action="append",
default=[],
)
Expand Down
3 changes: 2 additions & 1 deletion src/auditwheel/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import stat
from collections.abc import Iterable
from fnmatch import fnmatch
from os.path import abspath, basename, dirname, exists, isabs
from os.path import join as pjoin
from pathlib import Path
Expand Down Expand Up @@ -70,7 +71,7 @@ def repair_wheel(
ext_libs: dict[str, str] = v[abis[0]]["libs"]
replacements: list[tuple[str, str]] = []
for soname, src_path in ext_libs.items():
assert soname not in exclude
assert not any(fnmatch(soname, e) for e in exclude)

if src_path is None:
raise ValueError(
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_bundled_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
[
("cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libffi.so.5"}, frozenset()),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["libffi.so.5"])),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libffi.so.5"},
frozenset(["libffi.so.noexist", "libnoexist.so.*"]),
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
set(),
frozenset(["libffi.so.[4,5]"]),
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libffi.so.5"},
frozenset(["libffi.so.[6,7]"]),
),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["libffi.so.*"])),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["*"])),
(
"python_snappy-0.5.2-pp260-pypy_41-linux_x86_64.whl",
{"libsnappy.so.1"},
Expand Down

0 comments on commit c84d80e

Please sign in to comment.