Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --include and --exclude options to auditwheel repair #310

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion auditwheel/main_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def configure_parser(sub_parsers):
action='store_true',
help='Strip symbols in the resulting wheel',
default=False)
p.add_argument('--include',
dest='INCLUDE',
help='Only include these libraries')
p.add_argument('--exclude',
dest='EXCLUDE',
help='Exclude these libraries')
p.add_argument('--only-plat',
dest='ONLY_PLAT',
action='store_true',
Expand Down Expand Up @@ -126,7 +132,10 @@ def execute(args, p):
out_dir=args.WHEEL_DIR,
update_tags=args.UPDATE_TAGS,
patcher=patcher,
strip=args.STRIP)
strip=args.STRIP,
include=(args.INCLUDE or '').split(','),
exclude=(args.EXCLUDE or '').split(','),
)

if out_wheel is not None:
logger.info('\nFixed-up wheel written to %s', out_wheel)
34 changes: 33 additions & 1 deletion auditwheel/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,23 @@
re.VERBOSE).match


def _is_in_list(soname: str, items: Optional[List[str]]) -> Optional[str]:
for item in (items or []):
if item in soname:
return item
return None


def _filter(items: Optional[List[str]]) -> List[str]:
return [_.strip() for _ in (items or []) if _.strip()]


def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str,
update_tags: bool, patcher: ElfPatcher,
strip: bool = False) -> Optional[str]:
strip: bool = False,
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
) -> Optional[str]:

external_refs_by_fn = get_wheel_elfdata(wheel_path)[1]

Expand All @@ -44,6 +58,10 @@ def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str,

wheel_fname = basename(wheel_path)

# Remove empty strings in include/exclude list
include = _filter(include)
exclude = _filter(exclude)

with InWheelCtx(wheel_path) as ctx:
ctx.out_wheel = pjoin(out_dir, wheel_fname)

Expand All @@ -68,6 +86,20 @@ def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str,
'library "%s" could not be located') %
soname)

# exhaustive include list
if include and not _is_in_list(soname, include):
logger.debug(
f'Excluding {soname} which is not in exhaustive '
f'include list `{", ".join(include)}`)')
continue

# exclude some libraries
exc = _is_in_list(soname, exclude)
if exc:
logger.info(
f'Excluding {soname} (match exclude string `{exc}`)')
continue

new_soname, new_path = copylib(src_path, dest_dir, patcher)
soname_map[soname] = (new_soname, new_path)
patcher.replace_needed(fn, soname, new_soname)
Expand Down