* feat: add Pyodide support Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com> Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com> tests: fix two merge issues Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> fix: include schema Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Try to fix xbuildenv path [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Try to install pyodide-build from main branch Try again Try again Update constraints file Try again Remove unused variable Drop constraints Remove --download option Fix xbuildenv install Try again Try again [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: remove pinning on pyodide Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Update for Pyodide 0.26.0a5 * Install pyodide-build from pypi * Update docs/options.md Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> * Unxfail things that look like they were just a version mismatch * refactor: add constraints for pyodide Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * chore: minor cleanup Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Apply suggestions from code review * Apply suggestion from code review * refactor: minor touchup Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * ci: xfail the pyodide test Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * review: use a pinned version of node * fix tests * review: error out on Windows * test: check node & test on macos arm64 * chore: minor cleanup * Add reference to emscripten libc issue * Apply suggestion from code review * review: use a pinned pip in test virtual environment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: rework test virtual environment seed packages * chore: workaround direct invocation of pytest This allows to still test direct invocation of `pytest` on most platforms (including pyodide on Linux) but falls back to `python -m pytest` when running pyodide on macOS. * Use release version of pyodide * fix: tests for 0.26.0 & parallel initialization of xbuildenv * Debug CI * fix: test/test_build_frontend_args.py * Revert "Debug CI" This reverts commit 917646cffc96dbfc619c47d1c03a828f447bcdb7. --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
154 lines
5.2 KiB
Python
154 lines
5.2 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from . import test_projects, utils
|
|
|
|
project_with_environment_asserts = test_projects.new_c_project(
|
|
setup_py_add=textwrap.dedent(
|
|
r"""
|
|
import os
|
|
|
|
# explode if environment isn't correct, as set in CIBW_ENVIRONMENT
|
|
CIBW_TEST_VAR = os.environ.get("CIBW_TEST_VAR")
|
|
CIBW_TEST_VAR_2 = os.environ.get("CIBW_TEST_VAR_2")
|
|
CIBW_TEST_VAR_3 = os.environ.get("CIBW_TEST_VAR_3")
|
|
PATH = os.environ.get("PATH")
|
|
|
|
if CIBW_TEST_VAR != "a b c":
|
|
raise Exception('CIBW_TEST_VAR should equal "a b c". It was "%s"' % CIBW_TEST_VAR)
|
|
if CIBW_TEST_VAR_2 != "1":
|
|
raise Exception('CIBW_TEST_VAR_2 should equal "1". It was "%s"' % CIBW_TEST_VAR_2)
|
|
if CIBW_TEST_VAR_3 != "test string 3":
|
|
raise Exception('CIBW_TEST_VAR_3 should equal "test string 3". It was "%s"' % CIBW_TEST_VAR_3)
|
|
if "/opt/cibw_test_path" not in PATH:
|
|
raise Exception('PATH should contain "/opt/cibw_test_path". It was "%s"' % PATH)
|
|
if "$PATH" in PATH:
|
|
raise Exception('$PATH should be expanded in PATH. It was "%s"' % PATH)
|
|
"""
|
|
)
|
|
)
|
|
|
|
|
|
def test(tmp_path):
|
|
python_echo = f"'{sys.executable}' -c \"import sys; print(*sys.argv[1:])\""
|
|
project_dir = tmp_path / "project"
|
|
project_with_environment_asserts.generate(project_dir)
|
|
|
|
# write some information into the CIBW_ENVIRONMENT, for expansion and
|
|
# insertion into the environment by cibuildwheel. This is checked
|
|
# in setup.py
|
|
actual_wheels = utils.cibuildwheel_run(
|
|
project_dir,
|
|
add_env={
|
|
"CIBW_ENVIRONMENT": """CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH=$PATH:/opt/cibw_test_path""",
|
|
"CIBW_ENVIRONMENT_WINDOWS": f'''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$({python_echo} 'test string 3')" PATH="$PATH;/opt/cibw_test_path"''',
|
|
},
|
|
single_python=True,
|
|
)
|
|
|
|
# also check that we got the right wheels built
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
|
assert set(actual_wheels) == set(expected_wheels)
|
|
|
|
|
|
def test_overridden_path(tmp_path, capfd):
|
|
project_dir = tmp_path / "project"
|
|
output_dir = tmp_path / "output"
|
|
|
|
project = test_projects.new_c_project()
|
|
project.generate(project_dir)
|
|
output_dir.mkdir()
|
|
|
|
# mess up PATH, somehow
|
|
if utils.platform == "linux":
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
utils.cibuildwheel_run(
|
|
project_dir,
|
|
output_dir=output_dir,
|
|
add_env={
|
|
"CIBW_BEFORE_ALL": "mkdir new_path && touch new_path/python && chmod +x new_path/python",
|
|
"CIBW_ENVIRONMENT": '''PATH="$(pwd)/new_path:$PATH"''',
|
|
},
|
|
)
|
|
else:
|
|
new_path = tmp_path / "another_bin"
|
|
new_path.mkdir()
|
|
(new_path / "python").touch(mode=0o777)
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
utils.cibuildwheel_run(
|
|
project_dir,
|
|
output_dir=output_dir,
|
|
add_env={
|
|
"NEW_PATH": str(new_path),
|
|
"CIBW_ENVIRONMENT": f'''PATH="$NEW_PATH{os.pathsep}$PATH"''',
|
|
},
|
|
)
|
|
|
|
assert len(os.listdir(output_dir)) == 0
|
|
captured = capfd.readouterr()
|
|
assert "python available on PATH doesn't match our installed instance" in captured.err.replace(
|
|
"venv", "installed"
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"build_frontend",
|
|
[
|
|
pytest.param("pip", marks=utils.skip_if_pyodide("No pip for pyodide")),
|
|
"build",
|
|
],
|
|
)
|
|
def test_overridden_pip_constraint(tmp_path, build_frontend):
|
|
"""
|
|
Verify that users can use PIP_CONSTRAINT to specify a specific version of
|
|
a build-system.requires dependency, by asserting the version of pytz in the
|
|
setup.py.
|
|
"""
|
|
project_dir = tmp_path / "project"
|
|
|
|
project = test_projects.new_c_project(
|
|
setup_py_add=textwrap.dedent(
|
|
"""
|
|
import pytz
|
|
assert pytz.__version__ == "2022.4", f"{pytz.__version__!r} != '2022.4'"
|
|
"""
|
|
)
|
|
)
|
|
project.files["pyproject.toml"] = textwrap.dedent(
|
|
"""
|
|
[build-system]
|
|
requires = ["setuptools", "pytz"]
|
|
build-backend = "setuptools.build_meta"
|
|
"""
|
|
)
|
|
project.generate(project_dir)
|
|
|
|
if utils.platform == "linux":
|
|
# put the constraints file in the project directory, so it's available
|
|
# in the docker container
|
|
constraints_file = project_dir / "constraints.txt"
|
|
else:
|
|
constraints_file = tmp_path / "constraints.txt"
|
|
|
|
constraints_file.write_text("pytz==2022.4")
|
|
|
|
actual_wheels = utils.cibuildwheel_run(
|
|
project_dir,
|
|
add_env={
|
|
"CIBW_BUILD_FRONTEND": build_frontend,
|
|
"PIP_CONSTRAINT": str(constraints_file),
|
|
"CIBW_ENVIRONMENT_LINUX": "PIP_CONSTRAINT=./constraints.txt",
|
|
},
|
|
single_python=True,
|
|
)
|
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
|
assert set(actual_wheels) == set(expected_wheels)
|