def copy_file(filename, destination): """Copy the file and put the correct tag""" print("Updating file %s" % filename) out_dir = os.path.abspath(destination) tags = filename[:-4].split("-") tags[-2] = tags[-2].replace("m", "") new_name = "-".join(tags) + ".whl" wheel_flag = "-".join(tags[2:]) with InWheelCtx(os.path.join(destination, filename)) as ctx: info_fname = os.path.join(_dist_info_dir(ctx.path), 'WHEEL') infos = pkginfo.read_pkg_info(info_fname) print("Current Tags: ", ", ".join([v for k, v in infos.items() if k == "Tag"])) print("Adding Tag", wheel_flag) del infos['Tag'] infos.add_header('Tag', wheel_flag) pkginfo.write_pkg_info(info_fname, infos) ctx.out_wheel = os.path.join(out_dir, new_name) print("Saving new wheel into %s" % ctx.out_wheel)
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 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) if update_tags: ctx.out_wheel = add_platforms(ctx, [abi], get_replace_platforms(abi)) return ctx.out_wheel
def copy_file(filename): """Copy the file and put the correct tag""" print("Updating file %s" % filename) out_dir = os.path.abspath(DIRECTORY) tags = filename[:-4].split("-") tags[-2] = tags[-2].replace("m", "") new_name = "-".join(tags) + ".whl" wheel_flag = "-".join(tags[2:]) with InWheelCtx(os.path.join(DIRECTORY, filename)) as ctx: info_fname = os.path.join(_dist_info_dir(ctx.path), 'WHEEL') infos = pkginfo.read_pkg_info(info_fname) print("Changing Tag %s to %s" % (infos["Tag"], wheel_flag)) del infos['Tag'] infos.add_header('Tag', wheel_flag) pkginfo.write_pkg_info(info_fname, infos) ctx.out_wheel = os.path.join(out_dir, new_name) print("Saving new wheel into %s" % ctx.out_wheel)
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: dest_dir = pjoin(pkg_root, lib_sdir) if not exists(dest_dir): os.mkdir(dest_dir) ext_libs = v[abi]['libs'] # type: Dict[str, str] for soname, src_path in ext_libs.items(): if src_path is None: raise ValueError( ('Cannot repair wheel, because required ' 'library "%s" could not be located') % soname) new_soname, new_path = copylib(src_path, dest_dir) soname_map[soname] = (new_soname, new_path) check_call( ['patchelf', '--replace-needed', soname, new_soname, fn]) if len(ext_libs) > 0: patchelf_set_rpath(fn, dest_dir) # we grafted in a bunch of libraries and modifed their sonames, but # they may have internal dependencies (DT_NEEDED) on one another, so # we need to update those records so each now knows about the new # name of the other. for old_soname, (new_soname, path) in soname_map.items(): needed = elf_read_dt_needed(path) for n in needed: if n in soname_map: check_call([ 'patchelf', '--replace-needed', n, soname_map[n][0], path ]) check_call([ 'patchelf', '--force-rpath', '--set-rpath', '$ORIGIN/.libs:$ORIGIN/lib', 'xacc/_pyxacc.so' ]) if update_tags: ctx.out_wheel = add_platforms(ctx, [abi], get_replace_platforms(abi)) return ctx.out_wheel