feat: support pypa build (#521)
* feat: support pypa build fix: update `cibuildwheel.linux.troubleshoot` to know about build Workaround issue with PyPy venv module by installing build[virtualenv] fix: test_dependency_constraints_file when using build fix: test/test_pep518.py fix: use `strtobool` to parse `CIBW_PYPA_BUILD` fix: update `cibuildwheel.linux.troubleshoot` to know about `python -m pip wheel` test: use `build_mode` in `test/test_dependency_versions.py` tests * refactor: use build-backend instead * Apply suggestions from code review Co-authored-by: Joe Rickerby <joerick@mac.com> * refactor: use literal types for build_frontend * refactor(tests): build_mode -> build_frontend_env * Update test/test_before_build.py Co-authored-by: Joe Rickerby <joerick@mac.com>
This commit is contained in:
co-authored by
Joe Rickerby
parent
9e1369e07d
commit
515e9be2c4
+11
-2
@@ -1,7 +1,9 @@
|
||||
from typing import Dict
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
def pytest_addoption(parser) -> None:
|
||||
parser.addoption(
|
||||
"--run-emulation", action="store_true", default=False, help="run emulation tests"
|
||||
)
|
||||
@@ -11,7 +13,7 @@ def pytest_configure(config):
|
||||
config.addinivalue_line("markers", "emulation: mark test requiring qemu binfmt_misc to run")
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
def pytest_collection_modifyitems(config, items) -> None:
|
||||
if config.getoption("--run-emulation"):
|
||||
# --run-emulation given in cli: do not skip emulation tests
|
||||
return
|
||||
@@ -19,3 +21,10 @@ def pytest_collection_modifyitems(config, items):
|
||||
for item in items:
|
||||
if "emulation" in item.keywords:
|
||||
item.add_marker(skip_emulation)
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
params=[{"CIBW_BUILD_FRONTEND": "pip"}, {"CIBW_BUILD_FRONTEND": "build"}], ids=["pip", "build"]
|
||||
)
|
||||
def build_frontend_env(request) -> Dict[str, str]:
|
||||
return request.param # type: ignore
|
||||
|
||||
@@ -18,12 +18,12 @@ basic_project = test_projects.new_c_project(
|
||||
)
|
||||
|
||||
|
||||
def test(tmp_path):
|
||||
def test(tmp_path, build_frontend_env):
|
||||
project_dir = tmp_path / "project"
|
||||
basic_project.generate(project_dir)
|
||||
|
||||
# build the wheels
|
||||
actual_wheels = utils.cibuildwheel_run(project_dir)
|
||||
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=build_frontend_env)
|
||||
|
||||
# check that the expected wheels are produced
|
||||
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
||||
|
||||
@@ -25,8 +25,13 @@ project_with_before_build_asserts = test_projects.new_c_project(
|
||||
stored_executable = f.read()
|
||||
print('stored_executable', stored_executable)
|
||||
print('sys.executable', sys.executable)
|
||||
|
||||
# windows/mac are case insensitive
|
||||
assert os.path.realpath(stored_executable).lower() == os.path.realpath(sys.executable).lower()
|
||||
stored_path = os.path.realpath(stored_executable).lower()
|
||||
current_path = os.path.realpath(sys.executable).lower()
|
||||
|
||||
# TODO: This is not valid in an virtual environment
|
||||
assert stored_path == current_path, '{0} != {1}'.format(stored_path, current_path)
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
@@ -48,7 +48,7 @@ def get_versions_from_constraint_file(constraint_file):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.9"])
|
||||
def test_pinned_versions(tmp_path, python_version):
|
||||
def test_pinned_versions(tmp_path, python_version, build_frontend_env):
|
||||
if utils.platform == "linux":
|
||||
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
|
||||
|
||||
@@ -85,6 +85,7 @@ def test_pinned_versions(tmp_path, python_version):
|
||||
add_env={
|
||||
"CIBW_BUILD": build_pattern,
|
||||
"CIBW_ENVIRONMENT": cibw_environment_option,
|
||||
**build_frontend_env,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -107,7 +108,7 @@ def test_pinned_versions(tmp_path, python_version):
|
||||
assert set(actual_wheels) == set(expected_wheels)
|
||||
|
||||
|
||||
def test_dependency_constraints_file(tmp_path):
|
||||
def test_dependency_constraints_file(tmp_path, build_frontend_env):
|
||||
if utils.platform == "linux":
|
||||
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
|
||||
|
||||
@@ -118,7 +119,7 @@ def test_dependency_constraints_file(tmp_path):
|
||||
"pip": "20.0.2",
|
||||
"setuptools": "53.0.0",
|
||||
"wheel": "0.34.2",
|
||||
"virtualenv": "20.0.10",
|
||||
"virtualenv": "20.0.35",
|
||||
}
|
||||
|
||||
constraints_file = tmp_path / "constraints.txt"
|
||||
@@ -129,6 +130,7 @@ def test_dependency_constraints_file(tmp_path):
|
||||
setuptools=={setuptools}
|
||||
wheel=={wheel}
|
||||
virtualenv=={virtualenv}
|
||||
importlib-metadata<3,>=0.12; python_version < "3.8"
|
||||
""".format(
|
||||
**tool_versions
|
||||
)
|
||||
@@ -149,6 +151,7 @@ def test_dependency_constraints_file(tmp_path):
|
||||
add_env={
|
||||
"CIBW_ENVIRONMENT": cibw_environment_option,
|
||||
"CIBW_DEPENDENCY_VERSIONS": str(constraints_file),
|
||||
**build_frontend_env,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
+11
-4
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
import textwrap
|
||||
|
||||
from . import test_projects, utils
|
||||
@@ -33,13 +32,13 @@ build-backend = "setuptools.build_meta"
|
||||
"""
|
||||
|
||||
|
||||
def test_pep518(tmp_path):
|
||||
def test_pep518(tmp_path, build_frontend_env):
|
||||
|
||||
project_dir = tmp_path / "project"
|
||||
basic_project.generate(project_dir)
|
||||
|
||||
# build the wheels
|
||||
actual_wheels = utils.cibuildwheel_run(project_dir)
|
||||
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=build_frontend_env)
|
||||
|
||||
# check that the expected wheels are produced
|
||||
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
||||
@@ -50,4 +49,12 @@ def test_pep518(tmp_path):
|
||||
assert not (project_dir / "42").exists()
|
||||
assert not (project_dir / "4.1.2").exists()
|
||||
|
||||
assert len(os.listdir(project_dir)) == len(basic_project.files)
|
||||
# pypa/build creates a "build" folder & a "*.egg-info" folder for the wheel being built,
|
||||
# this should be harmless so remove them
|
||||
contents = [
|
||||
item
|
||||
for item in project_dir.iterdir()
|
||||
if item.name != "build" and not item.name.endswith(".egg-info")
|
||||
]
|
||||
|
||||
assert len(contents) == len(basic_project.files)
|
||||
|
||||
@@ -16,7 +16,7 @@ raise Exception('this build will fail')
|
||||
"""
|
||||
|
||||
|
||||
def test_failed_project_with_so_files(tmp_path, capfd):
|
||||
def test_failed_project_with_so_files(tmp_path, capfd, build_frontend_env):
|
||||
if utils.platform != "linux":
|
||||
pytest.skip("this test is only relevant to the linux build")
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_failed_project_with_so_files(tmp_path, capfd):
|
||||
so_file_project.generate(project_dir)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
utils.cibuildwheel_run(project_dir)
|
||||
utils.cibuildwheel_run(project_dir, add_env=build_frontend_env)
|
||||
|
||||
captured = capfd.readouterr()
|
||||
print("out", captured.out)
|
||||
|
||||
Reference in New Issue
Block a user