From 07ad119e8705eccfbfd309b2c4019d838b673143 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 16 Nov 2022 14:45:27 -0500 Subject: [PATCH] TST: adding isolated build test Signed-off-by: Henry Schreiner --- .github/workflows/ci-sage.yml | 2 +- pyproject.toml | 1 + tests/conftest.py | 55 +++++++++++++++++++++++++++++++++++ tests/test_pep518.py | 24 +++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/test_pep518.py diff --git a/.github/workflows/ci-sage.yml b/.github/workflows/ci-sage.yml index 53651b931..3568890dc 100644 --- a/.github/workflows/ci-sage.yml +++ b/.github/workflows/ci-sage.yml @@ -109,7 +109,7 @@ jobs: # Extra packages to install as system packages extra_sage_packages: "liblzma bzip2 libffi libpng python3 ninja_build" # Sage distribution packages to build - targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES="meson_python" meson_python + targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES="meson_python" python_build meson_python # Standard setting: Test the current beta release of Sage: sage_repo: sagemath/sage sage_ref: develop diff --git a/pyproject.toml b/pyproject.toml index 698e3fbb9..a18c3d46f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ dynamic = [ [project.optional-dependencies] test = [ + 'build', 'pytest', 'pytest-cov', 'pytest-mock', diff --git a/tests/conftest.py b/tests/conftest.py index be36e33bb..475cb96fa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ import re import shutil import subprocess +import sys import tempfile from venv import EnvBuilder @@ -120,3 +121,57 @@ def fixture(tmp_dir_session): globals()[f'package_{normalized}'] = generate_package_fixture(package) globals()[f'sdist_{normalized}'] = generate_sdist_fixture(package) globals()[f'wheel_{normalized}'] = generate_wheel_fixture(package) + + +@pytest.fixture(scope='session') +def pep518_wheelhouse(tmpdir_factory): + wheelhouse = tmpdir_factory.mktemp('wheelhouse') + dist = tmpdir_factory.mktemp('dist') + subprocess.run( + [sys.executable, '-m', 'build', '--wheel', '--outdir', str(dist)], + cwd=str(package_dir.parent.parent), + check=True, + ) + (wheel_path,) = dist.visit('*.whl') + subprocess.run( + [ + sys.executable, + '-m', + 'pip', + 'download', + '-q', + '-d', + str(wheelhouse), + str(wheel_path), + ], + check=True, + ) + subprocess.run( + [ + sys.executable, + '-m', + 'pip', + 'download', + '-q', + '-d', + str(wheelhouse), + 'build', + 'colorama', + 'meson', + 'ninja', + 'patchelf', + 'pyproject-metadata', + 'tomli', + 'typing-extensions', + 'wheel', + ], + check=True, + ) + return str(wheelhouse) + + +@pytest.fixture +def pep518(pep518_wheelhouse, monkeypatch): + monkeypatch.setenv('PIP_FIND_LINKS', pep518_wheelhouse) + monkeypatch.setenv('PIP_NO_INDEX', 'true') + return pep518_wheelhouse diff --git a/tests/test_pep518.py b/tests/test_pep518.py new file mode 100644 index 000000000..a2367fa6c --- /dev/null +++ b/tests/test_pep518.py @@ -0,0 +1,24 @@ +import subprocess +import sys + +import pytest + +from .conftest import cd_package, in_git_repo_context + + +@pytest.mark.parametrize( + ('package'), + [ + 'purelib-and-platlib', + ] +) +@pytest.mark.parametrize( + 'build_arg', ['', '--wheel'], ids=['sdist_to_wheel', 'wheel_directly'] +) +@pytest.mark.xfail(sys.platform.startswith('cygwin'), reason='ninja pip package not available on cygwin', strict=True) +def test_pep518(pep518, package, build_arg, tmp_path): + dist = tmp_path / 'dist' + + with cd_package(package) as package_dir, in_git_repo_context(): + build_args = [build_arg] if build_arg else [] + subprocess.run([sys.executable, '-m', 'build', f'--outdir={dist}', *build_args], cwd=package_dir, check=True)