Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions ci/tools/merge_cuda_core_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import subprocess
import sys
import tempfile
import zipfile
from pathlib import Path
from typing import List

Expand All @@ -46,6 +47,37 @@ def run_command(cmd: List[str], cwd: Path = None, env: dict = os.environ) -> sub
return result


def print_wheel_directory_structure(wheel_path: Path, filter_prefix: str = "cuda/core/", label: str = None):
"""Print the directory structure of a wheel file, similar to unzip -l output.

Args:
wheel_path: Path to the wheel file to inspect
filter_prefix: Only show files matching this prefix (default: "cuda/core/")
label: Optional label to print before the structure (e.g., "Input wheel 1: name.whl")
"""
if label:
print(f"\n--- {label} ---", file=sys.stderr)
try:
with zipfile.ZipFile(wheel_path, "r") as zf:
print(f"{'Length':>10} {'Date':>12} {'Time':>8} Name", file=sys.stderr)
print("-" * 80, file=sys.stderr)
total_size = 0
file_count = 0
for name in sorted(zf.namelist()):
if filter_prefix in name:
info = zf.getinfo(name)
total_size += info.file_size
file_count += 1
date_time = info.date_time
date_str = f"{date_time[0]:04d}-{date_time[1]:02d}-{date_time[2]:02d}"
time_str = f"{date_time[3]:02d}:{date_time[4]:02d}:{date_time[5]:02d}"
print(f"{info.file_size:10d} {date_str} {time_str} {name}", file=sys.stderr)
print("-" * 80, file=sys.stderr)
print(f"{total_size:10d} {file_count} files", file=sys.stderr)
except Exception as e:
print(f"Warning: Could not list wheel contents: {e}", file=sys.stderr)


def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:
"""Merge multiple wheels into a single wheel with version-specific binaries."""
print("\n=== Merging wheels ===", file=sys.stderr)
Expand Down Expand Up @@ -91,6 +123,11 @@ def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:

extracted_wheels.append(extract_dir)

# Debug: Show directory structure of input wheels
print("\n=== Input wheel directory structures ===", file=sys.stderr)
for i, wheel in enumerate(wheels):
print_wheel_directory_structure(wheel, label=f"Input wheel {i + 1}: {wheel.name}")

# Use the first wheel as the base and merge binaries from others
base_wheel = extracted_wheels[0]

Expand Down Expand Up @@ -142,6 +179,11 @@ def merge_wheels(wheels: List[Path], output_dir: Path) -> Path:

merged_wheel = output_wheels[0]
print(f"Successfully merged wheel: {merged_wheel}", file=sys.stderr)

# Debug: Show directory structure of output wheel
print("\n=== Output wheel directory structure ===", file=sys.stderr)
print_wheel_directory_structure(merged_wheel)

return merged_wheel


Expand Down
Loading