Skip to content

Commit

Permalink
Install one copy of libs used by multiple extension modules
Browse files Browse the repository at this point in the history
If you have a package that contains multiple C extensions that
depend on the same shared libraries, then `delocate-wheel` saves
duplicate copies of all of the shared libraries.

This makes for packages that are several times larger than
necessary. This patch causes `delocate-wheel` to sweep up all
of the dependencies and put them in a single directory, rather
than creating duplicates.

The convention is based on the proposal in pypa/auditwheel#89
and pypa/auditwheel#90.
  • Loading branch information
lpsinger committed Feb 7, 2018
1 parent faa3ae3 commit 8bb70dc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions delocate/delocating.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import warnings
from subprocess import Popen, PIPE

from wheel.install import WHEEL_INFO_RE # type: ignore

from .pycompat import string_types
from .libsana import tree_libs, stripped_lib_dict, get_rp_stripper
from .tools import (set_install_name, zip2dir, dir2zip, validate_signature,
Expand Down Expand Up @@ -227,7 +229,7 @@ def _copy_required(lib_path, copy_filt_func, copied_libs):
# Haven't see this one before, add entry to copied_libs
out_path = pjoin(lib_path, basename(required))
if exists(out_path):
raise DelocationError(out_path + ' already exists')
continue
shutil.copy(required, lib_path)
copied2orig[out_path] = required
copied_libs[required] = procd_requirings
Expand Down Expand Up @@ -370,15 +372,12 @@ def delocate_wheel(in_wheel,
all_copied = {}
wheel_dir = realpath(pjoin(tmpdir, 'wheel'))
zip2dir(in_wheel, wheel_dir)
wheel_fname = basename(out_wheel)
lib_path = pjoin(wheel_dir, WHEEL_INFO_RE(wheel_fname).group('name') + lib_sdir)
for package_path in find_package_dirs(wheel_dir):
lib_path = pjoin(package_path, lib_sdir)
lib_path_exists = exists(lib_path)
copied_libs = delocate_path(package_path, lib_path,
lib_filt_func, copy_filt_func)
if copied_libs and lib_path_exists:
raise DelocationError(
'{0} already exists in wheel but need to copy '
'{1}'.format(lib_path, '; '.join(copied_libs)))
if len(os.listdir(lib_path)) == 0:
shutil.rmtree(lib_path)
# Check architectures
Expand Down

0 comments on commit 8bb70dc

Please sign in to comment.