From 9fc8a9ebd64238a437875312e3eb4c5609daf77b Mon Sep 17 00:00:00 2001 From: Cyrille Rossant Date: Wed, 26 May 2021 14:03:54 +0200 Subject: [PATCH 1/4] Add --include and --exclude options to auditwheel repair --- auditwheel/main_repair.py | 11 ++++++++++- auditwheel/repair.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/auditwheel/main_repair.py b/auditwheel/main_repair.py index 0f357cf6..d7f50a64 100644 --- a/auditwheel/main_repair.py +++ b/auditwheel/main_repair.py @@ -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', @@ -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) diff --git a/auditwheel/repair.py b/auditwheel/repair.py index 17bcf1fb..6450d6d9 100644 --- a/auditwheel/repair.py +++ b/auditwheel/repair.py @@ -28,9 +28,22 @@ re.VERBOSE).match +def _is_in_list(soname : str, l: Optional[List[str]]) -> str: + for item in l: + if item in soname: + return item + + +def _filter(l : List[str]) -> List[str]: + return [_.strip() for _ in l 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] @@ -44,6 +57,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) @@ -68,6 +85,19 @@ 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 include list' + f' `{", ".join(include)}`)') + continue + + # exclude some libraries + exc = _is_in_list(soname, exclude) + if exc: + logger.info(f'Excluding {soname} (matched 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) From 3ad7503cce64440a81e3bef15fa0d221b2f19ae4 Mon Sep 17 00:00:00 2001 From: Cyrille Rossant Date: Wed, 26 May 2021 17:24:01 +0200 Subject: [PATCH 2/4] Flakify --- auditwheel/repair.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/auditwheel/repair.py b/auditwheel/repair.py index 6450d6d9..485837fc 100644 --- a/auditwheel/repair.py +++ b/auditwheel/repair.py @@ -28,13 +28,13 @@ re.VERBOSE).match -def _is_in_list(soname : str, l: Optional[List[str]]) -> str: - for item in l: +def _is_in_list(soname: str, items: Optional[List[str]]) -> str: + for item in items: if item in soname: return item -def _filter(l : List[str]) -> List[str]: +def _filter(l: List[str]) -> List[str]: return [_.strip() for _ in l if _.strip()] @@ -88,14 +88,15 @@ def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str, # exhaustive include list if include and not _is_in_list(soname, include): logger.debug( - f'Excluding {soname} which is not in exhaustive include list' - f' `{", ".join(include)}`)') + 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} (matched exclude string `{exc}`)') + logger.info( + f'Excluding {soname} (match exclude string `{exc}`)') continue new_soname, new_path = copylib(src_path, dest_dir, patcher) From ffe4d02897b5387b80fe2ae30d9d80d072a0ec2b Mon Sep 17 00:00:00 2001 From: Cyrille Rossant Date: Thu, 27 May 2021 09:05:20 +0200 Subject: [PATCH 3/4] Flakify --- auditwheel/repair.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auditwheel/repair.py b/auditwheel/repair.py index 485837fc..55210d6b 100644 --- a/auditwheel/repair.py +++ b/auditwheel/repair.py @@ -34,8 +34,8 @@ def _is_in_list(soname: str, items: Optional[List[str]]) -> str: return item -def _filter(l: List[str]) -> List[str]: - return [_.strip() for _ in l if _.strip()] +def _filter(items: List[str]) -> List[str]: + return [_.strip() for _ in items if _.strip()] def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str, From 607b8f7e978beaff12de9810a772fe0d64136bc2 Mon Sep 17 00:00:00 2001 From: Cyrille Rossant Date: Thu, 27 May 2021 11:32:04 +0200 Subject: [PATCH 4/4] Fixing typing hints --- auditwheel/repair.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/auditwheel/repair.py b/auditwheel/repair.py index 55210d6b..69848b8f 100644 --- a/auditwheel/repair.py +++ b/auditwheel/repair.py @@ -28,14 +28,15 @@ re.VERBOSE).match -def _is_in_list(soname: str, items: Optional[List[str]]) -> str: - for item in items: +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: List[str]) -> List[str]: - return [_.strip() for _ in items if _.strip()] +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,