1010
1111PTH_FILENAME = 'ibm_db_dll.pth'
1212PTH_CONTENT = 'import _ibm_db_register_dll\n '
13- REGISTER_MODULE = '_ibm_db_register_dll.py'
1413
1514
1615def _record_line (name , content_bytes ):
@@ -21,43 +20,42 @@ def _record_line(name, content_bytes):
2120
2221
2322def inject_pth (whl_path ):
24- """Add ibm_db_dll.pth and _ibm_db_register_dll.py to a wheel file."""
25- # Skip if already injected
23+ """Add ibm_db_dll.pth to a wheel file and remove any misplaced copies."""
2624 with zipfile .ZipFile (whl_path , 'r' ) as zin :
27- if PTH_FILENAME in zin .namelist ():
28- print (f' { PTH_FILENAME } already in { os .path .basename (whl_path )} , skipping' )
25+ names = zin .namelist ()
26+ # Skip if the .pth file is already at the wheel root
27+ if PTH_FILENAME in names :
28+ print (f' { PTH_FILENAME } already at root of { os .path .basename (whl_path )} , skipping' )
2929 return
3030
31- # Read the register module from the repo root
32- register_module_path = os .path .join (os .path .dirname (os .path .dirname (__file__ )), REGISTER_MODULE )
33- with open (register_module_path , 'rb' ) as f :
34- register_bytes = f .read ()
35-
3631 tmp_fd , tmp_path = tempfile .mkstemp (suffix = '.whl' )
3732 os .close (tmp_fd )
3833
3934 pth_bytes = PTH_CONTENT .encode ('utf-8' )
4035 pth_record = _record_line (PTH_FILENAME , pth_bytes )
41- register_record = _record_line (REGISTER_MODULE , register_bytes )
4236
4337 with zipfile .ZipFile (whl_path , 'r' ) as zin , \
4438 zipfile .ZipFile (tmp_path , 'w' , zipfile .ZIP_DEFLATED ) as zout :
4539
4640 for item in zin .infolist ():
41+ # Drop any misplaced copies of the .pth file (absolute-path junk from data_files)
42+ if item .filename != PTH_FILENAME and item .filename .endswith ('/' + PTH_FILENAME ):
43+ print (f' Removing misplaced { item .filename } ' )
44+ continue
45+
4746 data = zin .read (item .filename )
4847
49- # Append our entries to the RECORD file
48+ # Append our .pth entry to the RECORD file
5049 if item .filename .endswith ('/RECORD' ):
51- data = data .rstrip (b'\n ' ) + b'\n ' + pth_record .encode ('utf-8' ) + b'\n ' + register_record . encode ( 'utf-8' ) + b' \n '
50+ data = data .rstrip (b'\n ' ) + b'\n ' + pth_record .encode ('utf-8' ) + b'\n '
5251
5352 zout .writestr (item , data )
5453
55- # Add the .pth file and register module at the wheel root
54+ # Add the .pth file at the wheel root
5655 zout .writestr (PTH_FILENAME , pth_bytes )
57- zout .writestr (REGISTER_MODULE , register_bytes )
5856
5957 shutil .move (tmp_path , whl_path )
60- print (f' Injected { PTH_FILENAME } and { REGISTER_MODULE } into { os .path .basename (whl_path )} ' )
58+ print (f' Injected { PTH_FILENAME } into { os .path .basename (whl_path )} ' )
6159
6260
6361def main ():
0 commit comments