2022-07-14 13:36:57 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2022-04-01 16:50:01 +01:00
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import textwrap
|
2024-10-22 10:16:59 -04:00
|
|
|
from collections.abc import Mapping
|
2022-04-01 16:50:01 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
from tempfile import TemporaryDirectory
|
2024-05-27 22:34:22 -04:00
|
|
|
|
2022-04-01 16:50:01 +01:00
|
|
|
from test.test_projects.base import TestProject
|
|
|
|
|
|
|
|
|
|
from . import test_projects, utils
|
|
|
|
|
|
|
|
|
|
# utilities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_sdist(project: TestProject, working_dir: Path) -> Path:
|
|
|
|
|
project_dir = working_dir / "project"
|
|
|
|
|
project_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
project.generate(project_dir)
|
|
|
|
|
|
|
|
|
|
sdist_dir = working_dir / "sdist"
|
|
|
|
|
subprocess.run(
|
2022-04-26 22:21:27 -04:00
|
|
|
[sys.executable, "-m", "build", "--sdist", "--outdir", str(sdist_dir), str(project_dir)],
|
|
|
|
|
check=True,
|
2022-04-01 16:50:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return next(sdist_dir.glob("*.tar.gz"))
|
|
|
|
|
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def cibuildwheel_from_sdist_run(
|
|
|
|
|
sdist_path: Path | str,
|
|
|
|
|
add_env: Mapping[str, str] | None = None,
|
|
|
|
|
config_file: str | None = None,
|
|
|
|
|
) -> list[str]:
|
2022-04-01 16:50:01 +01:00
|
|
|
env = os.environ.copy()
|
|
|
|
|
|
|
|
|
|
if add_env:
|
|
|
|
|
env.update(add_env)
|
|
|
|
|
|
2024-05-26 12:41:20 +02:00
|
|
|
env["CIBW_BUILD"] = "cp{}{}-*".format(*utils.SINGLE_PYTHON_VERSION)
|
|
|
|
|
|
2022-04-01 16:50:01 +01:00
|
|
|
with TemporaryDirectory() as tmp_output_dir:
|
|
|
|
|
subprocess.run(
|
|
|
|
|
[
|
|
|
|
|
sys.executable,
|
|
|
|
|
"-m",
|
2022-04-26 22:21:27 -04:00
|
|
|
"cibuildwheel",
|
2022-04-01 16:50:01 +01:00
|
|
|
*(["--config-file", config_file] if config_file else []),
|
|
|
|
|
"--output-dir",
|
2022-04-26 22:21:27 -04:00
|
|
|
str(tmp_output_dir),
|
|
|
|
|
str(sdist_path),
|
2022-04-01 16:50:01 +01:00
|
|
|
],
|
|
|
|
|
env=env,
|
|
|
|
|
check=True,
|
|
|
|
|
)
|
|
|
|
|
return os.listdir(tmp_output_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# tests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple(tmp_path):
|
2022-04-03 10:51:59 +01:00
|
|
|
basic_project = test_projects.new_c_project()
|
|
|
|
|
|
2022-04-01 16:50:01 +01:00
|
|
|
# make an sdist of the project
|
|
|
|
|
sdist_dir = tmp_path / "sdist"
|
|
|
|
|
sdist_dir.mkdir()
|
|
|
|
|
sdist_path = make_sdist(basic_project, sdist_dir)
|
|
|
|
|
|
2024-01-24 21:19:24 +02:00
|
|
|
setup_py_assertion_snippet = textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
assert os.path.exists('setup.py')
|
|
|
|
|
assert os.path.exists('{package}/setup.py')
|
|
|
|
|
""",
|
|
|
|
|
)
|
2024-03-11 20:54:37 +00:00
|
|
|
setup_py_assertion_cmd = f'python -c "{setup_py_assertion_snippet !s}"'
|
2024-01-24 21:19:24 +02:00
|
|
|
|
2022-04-01 16:50:01 +01:00
|
|
|
# build the wheels from sdist
|
|
|
|
|
actual_wheels = cibuildwheel_from_sdist_run(
|
2024-05-26 12:41:20 +02:00
|
|
|
sdist_path, add_env={"CIBW_BEFORE_BUILD": setup_py_assertion_cmd}
|
2022-04-01 16:50:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# check that the expected wheels are produced
|
2024-05-26 12:41:20 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
2022-04-01 16:50:01 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_external_config_file_argument(tmp_path, capfd):
|
2022-04-03 10:51:59 +01:00
|
|
|
basic_project = test_projects.new_c_project()
|
|
|
|
|
|
2022-04-01 16:50:01 +01:00
|
|
|
# make an sdist of the project
|
|
|
|
|
sdist_dir = tmp_path / "sdist"
|
|
|
|
|
sdist_dir.mkdir()
|
|
|
|
|
sdist_path = make_sdist(basic_project, sdist_dir)
|
|
|
|
|
|
|
|
|
|
# add a config file
|
|
|
|
|
config_file = tmp_path / "config.toml"
|
|
|
|
|
config_file.write_text(
|
|
|
|
|
textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
[tool.cibuildwheel]
|
|
|
|
|
before-all = 'echo "test log statement from before-all"'
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# build the wheels from sdist
|
2024-05-26 12:41:20 +02:00
|
|
|
actual_wheels = cibuildwheel_from_sdist_run(sdist_path, config_file=str(config_file))
|
2022-04-01 16:50:01 +01:00
|
|
|
|
|
|
|
|
# check that the expected wheels are produced
|
2024-05-26 12:41:20 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
2022-04-01 16:50:01 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
|
|
|
|
|
|
|
|
|
# check that before-all was run
|
|
|
|
|
captured = capfd.readouterr()
|
|
|
|
|
assert "test log statement from before-all" in captured.out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_config_in_pyproject_toml(tmp_path, capfd):
|
|
|
|
|
# make a project with a pyproject.toml
|
|
|
|
|
project = test_projects.new_c_project()
|
|
|
|
|
project.files["pyproject.toml"] = textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
[tool.cibuildwheel]
|
|
|
|
|
before-build = 'echo "test log statement from before-build 8419"'
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# make an sdist of the project
|
|
|
|
|
sdist_dir = tmp_path / "sdist"
|
|
|
|
|
sdist_dir.mkdir()
|
|
|
|
|
sdist_path = make_sdist(project, sdist_dir)
|
|
|
|
|
|
|
|
|
|
# build the wheels from sdist
|
2024-05-26 12:41:20 +02:00
|
|
|
actual_wheels = cibuildwheel_from_sdist_run(sdist_path)
|
2022-04-01 16:50:01 +01:00
|
|
|
|
|
|
|
|
# check that the expected wheels are produced
|
2024-05-26 12:41:20 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
2022-04-01 16:50:01 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
|
|
|
|
|
|
|
|
|
# check that before-build was run
|
|
|
|
|
captured = capfd.readouterr()
|
|
|
|
|
assert "test log statement from before-build 8419" in captured.out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_internal_config_file_argument(tmp_path, capfd):
|
|
|
|
|
# make a project with a config file inside
|
|
|
|
|
project = test_projects.new_c_project(
|
|
|
|
|
setup_cfg_add="include_package_data = True",
|
|
|
|
|
)
|
|
|
|
|
project.files["wheel_build_config.toml"] = textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
[tool.cibuildwheel]
|
|
|
|
|
before-all = 'echo "test log statement from before-all 1829"'
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
project.files["MANIFEST.in"] = textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
include wheel_build_config.toml
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# make an sdist of the project
|
|
|
|
|
sdist_dir = tmp_path / "sdist"
|
|
|
|
|
sdist_dir.mkdir()
|
|
|
|
|
sdist_path = make_sdist(project, sdist_dir)
|
|
|
|
|
|
2022-04-03 10:51:59 +01:00
|
|
|
# build the wheels from sdist, referencing the config file inside
|
2022-04-01 16:50:01 +01:00
|
|
|
actual_wheels = cibuildwheel_from_sdist_run(
|
2024-05-26 12:41:20 +02:00
|
|
|
sdist_path, config_file="{package}/wheel_build_config.toml"
|
2022-04-01 16:50:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# check that the expected wheels are produced
|
2024-05-26 12:41:20 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
2022-04-01 16:50:01 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
|
|
|
|
|
|
|
|
|
# check that before-all was run
|
|
|
|
|
captured = capfd.readouterr()
|
|
|
|
|
assert "test log statement from before-all 1829" in captured.out
|