55import re
66import shutil
77import stat
8- from collections import OrderedDict
8+ from collections import OrderedDict , defaultdict
99from os .path import abspath , basename , dirname , exists , isabs
1010from os .path import join as pjoin
1111from subprocess import check_call
12- from typing import Dict , Iterable , List , Optional , Tuple
12+ from typing import Dict , Iterable , List , Optional , Set , Tuple
1313
1414from auditwheel .patcher import ElfPatcher
1515
@@ -73,6 +73,8 @@ def repair_wheel(
7373 for fn , v in external_refs_by_fn .items ():
7474 ext_libs = v [abis [0 ]]["libs" ] # type: Dict[str, str]
7575 replacements = [] # type: List[Tuple[str, str]]
76+ src_path_to_real_sonames = {} # type: Dict[str, str]
77+ same_soname_libs = defaultdict (set ) # type: Dict[str, Set[str]]
7678 for soname , src_path in ext_libs .items ():
7779 if src_path is None :
7880 raise ValueError (
@@ -83,10 +85,23 @@ def repair_wheel(
8385 % soname
8486 )
8587
86- if not copy_site_libs and "site-packages" in str (src_path ).split (
87- os .path .sep
88- ):
88+ real_soname = patcher .get_soname (src_path )
89+ src_path_to_real_sonames [soname ] = real_soname
90+ same_soname_libs [real_soname ].add (soname )
91+
92+ if not copy_site_libs :
93+ for soname , src_path in ext_libs .items ():
94+ if "site-packages" in str (src_path ).split (os .path .sep ):
95+ try :
96+ del same_soname_libs [src_path_to_real_sonames [soname ]]
97+ except KeyError :
98+ pass
99+
100+ for real_soname , sonames in same_soname_libs .items ():
101+ if len (sonames ) == 0 :
89102 continue
103+ soname = sonames .pop () # only keep one .so file (remove duplicates)
104+ src_path = ext_libs [soname ]
90105
91106 new_soname , new_path = copylib (src_path , dest_dir , patcher )
92107 soname_map [soname ] = (new_soname , new_path )
0 commit comments