Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def xacc_repair_wheel(wheel_path: str, abi: str, lib_sdir: str, out_dir: str,
update_tags: bool) -> Optional[str]:
external_refs_by_fn = get_wheel_elfdata(wheel_path)[1]
soname_map = {} # type: Dict[str, str]
if not isabs(out_dir):
out_dir = abspath(out_dir)
wheel_fname = basename(wheel_path)
with InWheelCtx(wheel_path) as ctx:
ctx.out_wheel = pjoin(out_dir, wheel_fname)
# here, fn is a path to a python extension library in
# the wheel, and v['libs'] contains its required libs
for fn, v in external_refs_by_fn.items():
# pkg_root should resolve to like numpy/ or scipy/
# note that it's possible for the wheel to contain
# more than one pkg, which is why we detect the pkg root
# for each fn.
pkg_root = fn.split(os.sep)[0]
if pkg_root == fn:
# this file is an extension that's not contained in a
# directory -- just supposed to be directly in site-packages
dest_dir = lib_sdir + pkg_root.split('.')[0]
else:
parsed_fname = WHEEL_INFO_RE.search(basename(args.WHEEL_FILE))
in_fname_tags = parsed_fname.groupdict()['plat'].split('.')
logger.info('%s receives the following tag: "%s".',
basename(args.WHEEL_FILE), wheel_abi.overall_tag)
logger.info('Use ``auditwheel show`` for more details')
if wheel_abi.overall_tag in in_fname_tags:
logger.info('No tags to be added. Exiting.')
return 1
# todo: move more of this logic to separate file
if not exists(args.WHEEL_DIR):
os.makedirs(args.WHEEL_DIR)
with InWheelCtx(args.WHEEL_FILE) as ctx:
try:
out_wheel = add_platforms(ctx, [wheel_abi.overall_tag])
except WheelToolsError as e:
logger.exception('\n%s.', repr(e))
return 1
if out_wheel:
# tell context manager to write wheel on exit with
# the proper output directory
ctx.out_wheel = join(args.WHEEL_DIR, basename(out_wheel))
logger.info('\nUpdated wheel written to %s', out_wheel)
return 0
@click.command()
@click.argument('wheel', type=click.Path(exists=True))
def main(wheel):
dir = os.path.dirname(os.path.abspath(wheel))
with InWheelCtx(wheel) as ctx:
try:
new_wheel = add_platforms(ctx, ['manylinux1_x86_64'], remove_platforms=('linux_x86_64',))
except WheelToolsError as e:
click.echo(str(e), err=True)
raise
if new_wheel:
ctx.out_wheel = os.path.normpath(os.path.join(dir, new_wheel))
click.echo('Updated wheel written to %s' % ctx.out_wheel)
def repair_wheel(wheel_path: str, abi: str, lib_sdir: str, out_dir: str,
update_tags: bool, patcher: ElfPatcher) -> Optional[str]:
external_refs_by_fn = get_wheel_elfdata(wheel_path)[1]
# Do not repair a pure wheel, i.e. has no external refs
if not external_refs_by_fn:
return None
soname_map = {} # type: Dict[str, Tuple[str, str]]
if not isabs(out_dir):
out_dir = abspath(out_dir)
wheel_fname = basename(wheel_path)
with InWheelCtx(wheel_path) as ctx:
ctx.out_wheel = pjoin(out_dir, wheel_fname)
match = WHEEL_INFO_RE(wheel_fname)
if not match:
raise ValueError("Failed to parse wheel file name: %s",
wheel_fname)
dest_dir = match.group('name') + lib_sdir
if not exists(dest_dir):
os.mkdir(dest_dir)
# here, fn is a path to a python extension library in
# the wheel, and v['libs'] contains its required libs
for fn, v in external_refs_by_fn.items():
def InGenericPkgCtx(in_path, out_path=None):
"""Factory that returns a InWheelCtx or InCondaPkgCtx
context manager depending on the file extension
"""
if in_path.endswith('.whl'):
return InWheelCtx(in_path, out_path)
if in_path.endswith('.tar.bz2'):
if out_path is not None:
raise NotImplementedError()
return InCondaPkgCtx(in_path)
raise ValueError("Invalid package: %s. File formats supported: "
".whl, .tar.bz2" % in_path)