2022-07-14 13:36:57 +02:00
|
|
|
from __future__ import annotations
|
2021-06-23 10:47:18 -04:00
|
|
|
|
2023-08-07 18:01:10 +02:00
|
|
|
import json
|
|
|
|
|
import subprocess
|
|
|
|
|
from typing import Generator
|
|
|
|
|
|
2020-12-21 11:06:25 +00:00
|
|
|
import pytest
|
|
|
|
|
|
2024-06-09 15:45:31 -04:00
|
|
|
from cibuildwheel.util import detect_ci_provider, find_uv
|
2023-08-07 18:01:10 +02:00
|
|
|
|
2024-05-28 04:34:10 +02:00
|
|
|
from .utils import EMULATED_ARCHS, platform
|
2023-08-07 18:01:10 +02:00
|
|
|
|
2020-12-21 11:06:25 +00:00
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def pytest_addoption(parser: pytest.Parser) -> None:
|
2020-12-21 11:06:25 +00:00
|
|
|
parser.addoption(
|
2024-05-28 04:34:10 +02:00
|
|
|
"--run-emulation",
|
|
|
|
|
action="store",
|
|
|
|
|
default=None,
|
|
|
|
|
help="run emulation tests",
|
|
|
|
|
choices=("all", *EMULATED_ARCHS),
|
2020-12-21 11:06:25 +00:00
|
|
|
)
|
2022-06-27 19:08:46 +01:00
|
|
|
parser.addoption("--run-podman", action="store_true", default=False, help="run podman tests")
|
2022-09-25 10:42:19 +02:00
|
|
|
parser.addoption(
|
|
|
|
|
"--run-cp38-universal2",
|
|
|
|
|
action="store_true",
|
|
|
|
|
default=False,
|
|
|
|
|
help="macOS cp38 uses the universal2 installer",
|
|
|
|
|
)
|
2021-06-23 10:47:18 -04:00
|
|
|
|
|
|
|
|
|
2024-06-17 07:07:35 +02:00
|
|
|
@pytest.fixture(params=["pip", "build"])
|
|
|
|
|
def build_frontend_env_nouv(request: pytest.FixtureRequest) -> dict[str, str]:
|
|
|
|
|
frontend = request.param
|
|
|
|
|
if platform == "pyodide" and frontend == "pip":
|
2024-05-28 05:31:36 -07:00
|
|
|
pytest.skip("Can't use pip as build frontend for pyodide platform")
|
2024-06-09 15:45:31 -04:00
|
|
|
|
2024-06-17 07:07:35 +02:00
|
|
|
return {"CIBW_BUILD_FRONTEND": frontend}
|
2023-08-07 18:01:10 +02:00
|
|
|
|
|
|
|
|
|
2024-08-21 00:34:31 -04:00
|
|
|
@pytest.fixture
|
2024-06-09 15:45:31 -04:00
|
|
|
def build_frontend_env(build_frontend_env_nouv: dict[str, str]) -> dict[str, str]:
|
2024-06-17 07:07:35 +02:00
|
|
|
frontend = build_frontend_env_nouv["CIBW_BUILD_FRONTEND"]
|
|
|
|
|
if frontend != "build" or platform == "pyodide" or find_uv() is None:
|
|
|
|
|
return build_frontend_env_nouv
|
2024-06-09 15:45:31 -04:00
|
|
|
|
2024-06-17 07:07:35 +02:00
|
|
|
return {"CIBW_BUILD_FRONTEND": "build[uv]"}
|
2024-06-09 15:45:31 -04:00
|
|
|
|
|
|
|
|
|
2024-08-21 00:34:31 -04:00
|
|
|
@pytest.fixture
|
2023-08-07 18:01:10 +02:00
|
|
|
def docker_cleanup() -> Generator[None, None, None]:
|
|
|
|
|
def get_images() -> set[str]:
|
2023-09-08 11:02:04 +02:00
|
|
|
if detect_ci_provider() is None or platform != "linux":
|
|
|
|
|
return set()
|
2023-08-07 18:01:10 +02:00
|
|
|
images = subprocess.run(
|
|
|
|
|
["docker", "image", "ls", "--format", "{{json .ID}}"],
|
|
|
|
|
text=True,
|
|
|
|
|
check=True,
|
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
|
).stdout
|
|
|
|
|
return {json.loads(image.strip()) for image in images.splitlines() if image.strip()}
|
|
|
|
|
|
|
|
|
|
images_before = get_images()
|
|
|
|
|
try:
|
|
|
|
|
yield
|
|
|
|
|
finally:
|
|
|
|
|
images_after = get_images()
|
|
|
|
|
for image in images_after - images_before:
|
|
|
|
|
subprocess.run(["docker", "rmi", image], check=False)
|