7
7
import re
8
8
import shutil
9
9
import stat
10
+ import typing as t
10
11
from concurrent .futures import Future , ThreadPoolExecutor , as_completed
11
12
from fnmatch import fnmatch
12
13
from os .path import isabs
13
14
from pathlib import Path
14
15
from subprocess import check_call
15
- from threading import Lock
16
16
17
17
from auditwheel .patcher import ElfPatcher
18
18
@@ -69,8 +69,8 @@ def repair_wheel(
69
69
dest_dir .mkdir ()
70
70
71
71
pool = ThreadPoolExecutor ()
72
- copy_works : dict [str , Future ] = {}
73
- replace_works : dict [str , Future ] = {}
72
+ copy_works : dict [Path , Future [ t . Any ] ] = {}
73
+ replace_works : dict [Path , Future [ t . Any ] ] = {}
74
74
75
75
# here, fn is a path to an ELF file (lib or executable) in
76
76
# the wheel, and v['libs'] contains its required libs
@@ -88,22 +88,24 @@ def repair_wheel(
88
88
raise ValueError (msg )
89
89
90
90
new_soname , new_path = copylib (src_path , dest_dir , patcher , dry = True )
91
- if ( new_path_key := str ( new_path )) not in copy_works :
92
- copy_works [new_path_key ] = pool .submit (
91
+ if new_path not in copy_works :
92
+ copy_works [new_path ] = pool .submit (
93
93
copylib , src_path , dest_dir , patcher
94
94
)
95
95
else :
96
- if copy_works [new_path_key ].running () or copy_works [new_path_key ].done ():
96
+ if copy_works [new_path ].running () or copy_works [new_path ].done ():
97
97
assert new_path .exists ()
98
98
soname_map [soname ] = (new_soname , new_path )
99
99
replacements .append ((soname , new_soname ))
100
100
101
101
# Replace rpath do not need copy to be done
102
- def _inner_replace ():
102
+ def _inner_replace (
103
+ fn : Path , replacements : list [tuple [str , str ]], append_rpath : bool
104
+ ) -> None :
103
105
if replacements :
104
106
patcher .replace_needed (fn , * replacements )
105
107
106
- if len ( ext_libs ) > 0 :
108
+ if append_rpath :
107
109
new_fn = fn
108
110
if _path_is_script (fn ):
109
111
new_fn = _replace_elf_script_with_shim (match .group ("name" ), fn )
@@ -112,15 +114,20 @@ def _inner_replace():
112
114
new_rpath = os .path .join ("$ORIGIN" , new_rpath )
113
115
append_rpath_within_wheel (new_fn , new_rpath , ctx .name , patcher )
114
116
115
- replace_works [fn ] = pool .submit (_inner_replace )
117
+ replace_works [fn ] = pool .submit (
118
+ _inner_replace , fn , replacements , len (ext_libs ) > 0
119
+ )
116
120
117
121
# we grafted in a bunch of libraries and modified their sonames, but
118
122
# they may have internal dependencies (DT_NEEDED) on one another, so
119
123
# we need to update those records so each now knows about the new
120
124
# name of the other.
121
- assert all (f .exception () is None for f in as_completed (itertools .chain (
122
- copy_works .values (), replace_works .values ()
123
- )))
125
+ assert all (
126
+ f .exception () is None
127
+ for f in as_completed (
128
+ itertools .chain (copy_works .values (), replace_works .values ())
129
+ )
130
+ )
124
131
for _ , path in soname_map .values ():
125
132
needed = elf_read_dt_needed (path )
126
133
replacements = []
@@ -134,7 +141,7 @@ def _inner_replace():
134
141
ctx .out_wheel = add_platforms (ctx , abis , get_replace_platforms (abis [0 ]))
135
142
136
143
if strip :
137
- for lib , future in itertools .chain (
144
+ for lib in itertools .chain (
138
145
[path for (_ , path ) in soname_map .values ()], external_refs_by_fn .keys ()
139
146
):
140
147
logger .info ("Stripping symbols from %s" , lib )
@@ -145,11 +152,6 @@ def _inner_replace():
145
152
return ctx .out_wheel
146
153
147
154
148
- def then (pool : ThreadPoolExecutor , future : Future , * args , ** kwargs ):
149
- future .result ()
150
- pool .submit (* args , ** kwargs )
151
-
152
-
153
155
def copylib (
154
156
src_path : Path , dest_dir : Path , patcher : ElfPatcher , dry : bool = False
155
157
) -> tuple [str , Path ]:
0 commit comments