2020-07-21 18:41:51 +02:00
|
|
|
import subprocess
|
2020-05-02 22:50:52 +01:00
|
|
|
import textwrap
|
2026-04-01 10:23:02 -04:00
|
|
|
from pathlib import Path
|
2020-05-02 22:50:52 +01:00
|
|
|
|
2021-01-06 13:50:58 -05:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from . import test_projects, utils
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2024-05-28 05:31:36 -07:00
|
|
|
# pyodide does not support building without isolation, need to check the base_prefix
|
2025-05-16 11:11:16 +01:00
|
|
|
SYS_PREFIX = f"sys.{'base_' if utils.get_platform() == 'pyodide' else ''}prefix"
|
2024-05-28 05:31:36 -07:00
|
|
|
|
|
|
|
|
|
2020-05-17 16:54:33 +01:00
|
|
|
project_with_before_build_asserts = test_projects.new_c_project(
|
2021-04-30 17:56:34 -04:00
|
|
|
setup_py_add=textwrap.dedent(
|
2024-05-28 05:31:36 -07:00
|
|
|
rf"""
|
2021-02-18 08:15:37 +01:00
|
|
|
import os
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2024-02-29 22:27:09 +01:00
|
|
|
# assert that the Python version as written to pythonversion_bb.txt in the CIBW_BEFORE_BUILD step
|
2020-05-02 16:54:19 +01:00
|
|
|
# is the same one as is currently running.
|
2024-05-26 12:40:11 +02:00
|
|
|
with open('pythonversion_bb.txt') as f:
|
2020-05-02 16:54:19 +01:00
|
|
|
stored_version = f.read()
|
2020-05-02 22:42:35 +01:00
|
|
|
print('stored_version', stored_version)
|
|
|
|
|
print('sys.version', sys.version)
|
2020-05-02 16:54:19 +01:00
|
|
|
assert stored_version == sys.version
|
|
|
|
|
|
2024-05-26 12:40:11 +02:00
|
|
|
# check that the prefix also was written
|
|
|
|
|
with open('pythonprefix_bb.txt') as f:
|
|
|
|
|
stored_prefix = f.read()
|
|
|
|
|
print('stored_prefix', stored_prefix)
|
2024-05-28 05:31:36 -07:00
|
|
|
print('{SYS_PREFIX}', {SYS_PREFIX})
|
2024-05-26 12:40:11 +02:00
|
|
|
# Works around path-comparison bugs caused by short-paths on Windows e.g.
|
|
|
|
|
# vssadm~1 instead of vssadministrator
|
2021-06-23 10:47:18 -04:00
|
|
|
|
2024-05-28 05:31:36 -07:00
|
|
|
assert os.path.samefile(stored_prefix, {SYS_PREFIX})
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2020-05-02 16:54:19 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-04-01 10:23:02 -04:00
|
|
|
def test(tmp_path: Path) -> None:
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-05-02 16:54:19 +01:00
|
|
|
project_with_before_build_asserts.generate(project_dir)
|
|
|
|
|
|
2021-04-30 17:56:34 -04:00
|
|
|
before_build = (
|
2025-04-29 00:25:17 +02:00
|
|
|
"""python -c "import pathlib, sys; pathlib.Path('{project}/pythonversion_bb.txt').write_text(sys.version)" && """
|
|
|
|
|
f'''python -c "import pathlib, sys; pathlib.Path('{{project}}/pythonprefix_bb.txt').write_text({SYS_PREFIX})"'''
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2025-03-21 09:49:04 -04:00
|
|
|
frontend = "build"
|
2025-05-16 11:11:16 +01:00
|
|
|
if utils.get_platform() != "pyodide":
|
2025-03-21 09:49:04 -04:00
|
|
|
before_build = f"python -m pip install setuptools && {before_build}"
|
|
|
|
|
frontend = f"{frontend};args: --no-isolation"
|
2020-07-20 00:46:36 +02:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
# build the wheels
|
2021-04-30 17:56:34 -04:00
|
|
|
actual_wheels = utils.cibuildwheel_run(
|
|
|
|
|
project_dir,
|
|
|
|
|
add_env={
|
|
|
|
|
# write python version information to a temporary file, this is
|
|
|
|
|
# checked in setup.py
|
2024-05-26 12:40:11 +02:00
|
|
|
"CIBW_BEFORE_BUILD": before_build,
|
2025-03-21 09:49:04 -04:00
|
|
|
"CIBW_BUILD_FRONTEND": frontend,
|
2021-04-30 17:56:34 -04:00
|
|
|
},
|
|
|
|
|
)
|
2020-05-02 16:54:19 +01:00
|
|
|
|
|
|
|
|
# also check that we got the right wheels
|
2021-05-03 11:45:43 -04:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
2020-05-02 16:54:19 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
2020-07-21 18:41:51 +02:00
|
|
|
|
|
|
|
|
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_failing_command(tmp_path: Path) -> None:
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-07-21 18:41:51 +02:00
|
|
|
test_projects.new_c_project().generate(project_dir)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
2021-04-30 17:56:34 -04:00
|
|
|
utils.cibuildwheel_run(
|
|
|
|
|
project_dir,
|
|
|
|
|
add_env={
|
2021-05-03 11:45:43 -04:00
|
|
|
"CIBW_BEFORE_BUILD": "false",
|
|
|
|
|
"CIBW_BEFORE_BUILD_WINDOWS": "exit /b 1",
|
2021-04-30 17:56:34 -04:00
|
|
|
},
|
|
|
|
|
)
|
2020-07-21 18:41:51 +02:00
|
|
|
|
|
|
|
|
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_cwd(tmp_path: Path) -> None:
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-07-21 18:41:51 +02:00
|
|
|
test_projects.new_c_project().generate(project_dir)
|
|
|
|
|
|
2021-04-30 17:56:34 -04:00
|
|
|
actual_wheels = utils.cibuildwheel_run(
|
|
|
|
|
project_dir,
|
|
|
|
|
add_env={
|
2021-05-03 11:45:43 -04:00
|
|
|
"CIBW_BEFORE_BUILD": f'''python -c "import os; assert os.getcwd() == {str(project_dir)!r}"''',
|
|
|
|
|
"CIBW_BEFORE_BUILD_LINUX": '''python -c "import os; assert os.getcwd() == '/project'"''',
|
2021-04-30 17:56:34 -04:00
|
|
|
},
|
2024-05-26 12:41:20 +02:00
|
|
|
single_python=True,
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2020-07-21 18:41:51 +02:00
|
|
|
|
2024-05-26 12:41:20 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
2020-07-21 18:41:51 +02:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|