Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions pyodide_build/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,34 +315,38 @@ def _get_sha256_checksum(archive: Path) -> str:
return h.hexdigest()


def unpack_wheel(wheel_path: Path, target_dir: Path | None = None) -> None:
def unpack_wheel(
wheel_path: Path, target_dir: Path | None = None, verbose=True
) -> None:
if target_dir is None:
target_dir = wheel_path.parent
result = subprocess.run(
[sys.executable, "-m", "wheel", "unpack", wheel_path, "-d", target_dir],
check=False,
encoding="utf-8",
capture_output=not verbose,
)
if result.returncode != 0:
logger.error("ERROR: Unpacking wheel %s failed", wheel_path.name)
exit_with_stdio(result)


def pack_wheel(wheel_dir: Path, target_dir: Path | None = None) -> None:
def pack_wheel(wheel_dir: Path, target_dir: Path | None = None, verbose=True) -> None:
if target_dir is None:
target_dir = wheel_dir.parent
result = subprocess.run(
[sys.executable, "-m", "wheel", "pack", wheel_dir, "-d", target_dir],
check=False,
encoding="utf-8",
capture_output=not verbose,
)
if result.returncode != 0:
logger.error("ERROR: Packing wheel %s failed", wheel_dir)
exit_with_stdio(result)


@contextmanager
def modify_wheel(wheel: Path) -> Iterator[Path]:
def modify_wheel(wheel: Path, verbose=True) -> Iterator[Path]:
"""Unpacks the wheel into a temp directory and yields the path to the
unpacked directory.

Expand All @@ -353,13 +357,13 @@ def modify_wheel(wheel: Path) -> Iterator[Path]:
wheel is left unchanged.
"""
with TemporaryDirectory() as temp_dir:
unpack_wheel(wheel, Path(temp_dir))
unpack_wheel(wheel, Path(temp_dir), verbose=verbose)
name, ver, _ = wheel.name.split("-", 2)
wheel_dir_name = f"{name}-{ver}"
wheel_dir = Path(temp_dir) / wheel_dir_name
yield wheel_dir
wheel.unlink()
pack_wheel(wheel_dir, wheel.parent)
pack_wheel(wheel_dir, wheel.parent, verbose=verbose)


def retag_wheel(
Expand Down
2 changes: 1 addition & 1 deletion pyodide_build/recipe/unvendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def unvendor_tests_in_wheel(
with TemporaryDirectory() as _tmpdir:
tmpdir = Path(_tmpdir)
test_dir = tmpdir / "tests"
with modify_wheel(wheel) as wheel_extract_dir:
with modify_wheel(wheel, verbose=False) as wheel_extract_dir:
nmoved = unvendor_tests(
wheel_extract_dir,
test_dir,
Expand Down