@@ -98,73 +98,74 @@ def mangle_filename(old_filename, new_filename, mapping):
9898wheel_name = args .WHEEL_FILE
9999print (wheel_name )
100100print (os .path .join (wheel_name , "opengate_core-*-win_amd64.whl" ))
101- wheel_name = glob .glob (os .path .join (wheel_name , "opengate_core-*-win_amd64.whl" ))[0 ]
102- print (wheel_name )
103- repaired_wheel = os .path .join (
104- os .path .abspath (args .WHEEL_DIR ), os .path .basename (wheel_name )
105- )
101+ wheel_names = glob .glob (os .path .join (wheel_name , "opengate_core-*-win_amd64.whl" ))
102+ for wheel_name in wheel_names :
103+ print (wheel_name )
104+ repaired_wheel = os .path .join (
105+ os .path .abspath (args .WHEEL_DIR ), os .path .basename (wheel_name )
106+ )
107+
108+ old_wheel_dir = tempfile .mkdtemp ()
109+ new_wheel_dir = tempfile .mkdtemp ()
110+ package_name = os .path .basename (wheel_name ).split ("-" )[0 ]
111+ bundle_name = package_name + ".libs"
112+ bundle_path = os .path .join (new_wheel_dir , bundle_name )
113+ os .makedirs (bundle_path )
114+
115+ with zipfile .ZipFile (wheel_name , "r" ) as wheel :
116+ wheel .extractall (old_wheel_dir )
117+ wheel .extractall (new_wheel_dir )
118+ pyd_rel_paths = [
119+ os .path .normpath (path ) for path in wheel .namelist () if path .endswith (".pyd" )
120+ ]
121+
122+ dll_dependencies = {}
123+ for rel_path in pyd_rel_paths :
124+ abs_path = os .path .join (old_wheel_dir , rel_path )
125+ print (rel_path )
126+ dll_dependencies .update (find_dll_dependencies (abs_path , args .DLL_DIR ))
127+
128+ for dll , dependencies in dll_dependencies .items ():
129+ mapping = {}
130+
131+ print (dll )
132+ print (dependencies )
106133
107- old_wheel_dir = tempfile .mkdtemp ()
108- new_wheel_dir = tempfile .mkdtemp ()
109- package_name = os .path .basename (wheel_name ).split ("-" )[0 ]
110- bundle_name = package_name + ".libs"
111- bundle_path = os .path .join (new_wheel_dir , bundle_name )
112- os .makedirs (bundle_path )
113-
114- with zipfile .ZipFile (wheel_name , "r" ) as wheel :
115- wheel .extractall (old_wheel_dir )
116- wheel .extractall (new_wheel_dir )
117- pyd_rel_paths = [
118- os .path .normpath (path ) for path in wheel .namelist () if path .endswith (".pyd" )
119- ]
120-
121- dll_dependencies = {}
122- for rel_path in pyd_rel_paths :
123- abs_path = os .path .join (old_wheel_dir , rel_path )
124- print (rel_path )
125- dll_dependencies .update (find_dll_dependencies (abs_path , args .DLL_DIR ))
126-
127- for dll , dependencies in dll_dependencies .items ():
128- mapping = {}
129-
130- print (dll )
131- print (dependencies )
132-
133- if dll .endswith (".pyd" ):
134- rel_path = next (path for path in pyd_rel_paths if path .endswith (dll ))
135-
136- for dep in dependencies :
137- src_path = os .path .join (args .DLL_DIR , dep )
138- hashed_name = hash_filename (src_path ) # already basename
139- new_path = os .path .join (bundle_path , hashed_name )
140134 if dll .endswith (".pyd" ):
141- bundle_rel_path = os .path .join (
142- "..\\ " * rel_path .count (os .path .sep ), bundle_name
143- )
144- mapping [dep .encode ("ascii" )] = os .path .join (
145- bundle_rel_path , hashed_name
146- ).encode ("ascii" )
147- else :
148- mapping [dep .encode ("ascii" )] = hashed_name .encode ("ascii" )
149- if not os .path .exists (new_path ):
150- shutil .copy2 (src_path , new_path )
135+ rel_path = next (path for path in pyd_rel_paths if path .endswith (dll ))
136+
137+ for dep in dependencies :
138+ src_path = os .path .join (args .DLL_DIR , dep )
139+ hashed_name = hash_filename (src_path ) # already basename
140+ new_path = os .path .join (bundle_path , hashed_name )
141+ if dll .endswith (".pyd" ):
142+ bundle_rel_path = os .path .join (
143+ "..\\ " * rel_path .count (os .path .sep ), bundle_name
144+ )
145+ mapping [dep .encode ("ascii" )] = os .path .join (
146+ bundle_rel_path , hashed_name
147+ ).encode ("ascii" )
148+ else :
149+ mapping [dep .encode ("ascii" )] = hashed_name .encode ("ascii" )
150+ if not os .path .exists (new_path ):
151+ shutil .copy2 (src_path , new_path )
151152
152- if dll .endswith (".pyd" ):
153- old_name = os .path .join (old_wheel_dir , rel_path )
154- new_name = os .path .join (new_wheel_dir , rel_path )
155- else :
156- old_name = os .path .join (args .DLL_DIR , dll )
157- hashed_name = hash_filename (old_name ) # already basename
158- new_name = os .path .join (bundle_path , hashed_name )
159-
160- mangle_filename (old_name , new_name , mapping )
161-
162- pathlib .Path (os .path .dirname (repaired_wheel )).mkdir (parents = True , exist_ok = True )
163- with zipfile .ZipFile (repaired_wheel , "w" , zipfile .ZIP_DEFLATED ) as new_wheel :
164- for root , dirs , files in os .walk (new_wheel_dir ):
165- new_root = os .path .relpath (root , new_wheel_dir )
166- for file in files :
167- new_wheel .write (os .path .join (root , file ), os .path .join (new_root , file ))
153+ if dll .endswith (".pyd" ):
154+ old_name = os .path .join (old_wheel_dir , rel_path )
155+ new_name = os .path .join (new_wheel_dir , rel_path )
156+ else :
157+ old_name = os .path .join (args .DLL_DIR , dll )
158+ hashed_name = hash_filename (old_name ) # already basename
159+ new_name = os .path .join (bundle_path , hashed_name )
160+
161+ mangle_filename (old_name , new_name , mapping )
162+
163+ pathlib .Path (os .path .dirname (repaired_wheel )).mkdir (parents = True , exist_ok = True )
164+ with zipfile .ZipFile (repaired_wheel , "w" , zipfile .ZIP_DEFLATED ) as new_wheel :
165+ for root , dirs , files in os .walk (new_wheel_dir ):
166+ new_root = os .path .relpath (root , new_wheel_dir )
167+ for file in files :
168+ new_wheel .write (os .path .join (root , file ), os .path .join (new_root , file ))
168169
169170now = datetime .now ()
170171print (now .strftime ("%H:%M:%S" ))
0 commit comments