@@ -47,8 +47,8 @@ def run_command(cmd: List[str], cwd: Path = None, env: dict = os.environ) -> sub
4747
4848def merge_wheels (wheels : List [Path ], output_dir : Path ) -> Path :
4949 """Merge multiple wheels into a single wheel with version-specific binaries."""
50- print ("\n === Merging wheels ===" )
51- print (f"Input wheels: { [w .name for w in wheels ]} " )
50+ print ("\n === Merging wheels ===" , file = sys . stderr )
51+ print (f"Input wheels: { [w .name for w in wheels ]} " , file = sys . stderr )
5252
5353 if len (wheels ) == 1 :
5454 raise RuntimeError ("only one wheel is provided, nothing to merge" )
@@ -59,11 +59,11 @@ def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:
5959 extracted_wheels = []
6060
6161 for i , wheel in enumerate (wheels ):
62- print (f"Extracting wheel { i + 1 } /{ len (wheels )} : { wheel .name } " )
62+ print (f"Extracting wheel { i + 1 } /{ len (wheels )} : { wheel .name } " , file = sys . stderr )
6363 # Extract wheel - wheel unpack creates the directory itself
6464 run_command (
6565 [
66- "python" ,
66+ sys . executable ,
6767 "-m" ,
6868 "wheel" ,
6969 "unpack" ,
@@ -99,18 +99,18 @@ def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:
9999 cuda_version = wheels [i ].name .split (".cu" )[1 ].split ("." )[0 ]
100100 base_dir = Path ("cuda" ) / "core" / "experimental"
101101 # Copy from other wheels
102- print (f" Copying { wheel_dir } to { base_wheel } " )
102+ print (f" Copying { wheel_dir } to { base_wheel } " , file = sys . stderr )
103103 shutil .copytree (wheel_dir / base_dir , base_wheel / base_dir / f"cu{ cuda_version } " )
104104
105105 # Overwrite the __init__.py in versioned dirs
106- open (base_wheel / base_dir / f"cu{ cuda_version } " / "__init__.py" , "w" ). close ( )
106+ os . truncate (base_wheel / base_dir / f"cu{ cuda_version } " / "__init__.py" , 0 )
107107
108108 # The base dir should only contain __init__.py, the include dir, and the versioned dirs
109- files_to_remove = os .listdir (base_wheel / base_dir )
109+ files_to_remove = os .scandir (base_wheel / base_dir )
110110 for f in files_to_remove :
111- f_abspath = base_wheel / base_dir / f
112- if f not in ("__init__.py" , "cu12" , "cu13" , "include" ):
113- if os . path . isdir ( f_abspath ):
111+ f_abspath = f . path
112+ if f . name not in ("__init__.py" , "cu12" , "cu13" , "include" ):
113+ if f . is_dir ( ):
114114 shutil .rmtree (f_abspath )
115115 else :
116116 os .remove (f_abspath )
@@ -119,15 +119,12 @@ def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:
119119 output_dir .mkdir (parents = True , exist_ok = True )
120120
121121 # Create a clean wheel name without CUDA version suffixes
122- base_wheel_name = wheels [0 ].name
123- # Remove any .cu* suffix from the wheel name
124- if ".cu" in base_wheel_name :
125- base_wheel_name = base_wheel_name .split (".cu" )[0 ] + ".whl"
122+ base_wheel_name = wheels [0 ].with_suffix (".whl" ).name
126123
127- print (f"Repacking merged wheel as: { base_wheel_name } " )
124+ print (f"Repacking merged wheel as: { base_wheel_name } " , file = sys . stderr )
128125 run_command (
129126 [
130- "python" ,
127+ sys . executable ,
131128 "-m" ,
132129 "wheel" ,
133130 "pack" ,
@@ -143,7 +140,7 @@ def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:
143140 raise RuntimeError ("Failed to create merged wheel" )
144141
145142 merged_wheel = output_wheels [0 ]
146- print (f"Successfully merged wheel: { merged_wheel } " )
143+ print (f"Successfully merged wheel: { merged_wheel } " , file = sys . stderr )
147144 return merged_wheel
148145
149146
@@ -155,32 +152,32 @@ def main():
155152
156153 args = parser .parse_args ()
157154
158- print ("cuda.core Wheel Merger" )
159- print ("======================" )
155+ print ("cuda.core Wheel Merger" , file = sys . stderr )
156+ print ("======================" , file = sys . stderr )
160157
161158 # Convert wheel paths to Path objects and validate
162159 wheels = []
163160 for wheel_path in args .wheels :
164161 wheel = Path (wheel_path )
165162 if not wheel .exists ():
166- print (f"Error: Wheel not found: { wheel } " )
163+ print (f"Error: Wheel not found: { wheel } " , file = sys . stderr )
167164 sys .exit (1 )
168165 if not wheel .name .endswith (".whl" ):
169- print (f"Error: Not a wheel file: { wheel } " )
166+ print (f"Error: Not a wheel file: { wheel } " , file = sys . stderr )
170167 sys .exit (1 )
171168 wheels .append (wheel )
172169
173170 if not wheels :
174- print ("Error: No wheels provided" )
171+ print ("Error: No wheels provided" , file = sys . stderr )
175172 sys .exit (1 )
176173
177174 output_dir = Path (args .output_dir )
178175
179176 # Check that we have wheel tool available
180177 try :
181- run_command ([ "python" , "-m" , " wheel" , "--help" ])
182- except Exception :
183- print ("Error: wheel package not available. Install with: pip install wheel" )
178+ import wheel
179+ except ImportError :
180+ print ("Error: wheel package not available. Install with: pip install wheel" , file = sys . stderr )
184181 sys .exit (1 )
185182
186183 # Merge the wheels
0 commit comments