From 04055f9ecbeec08be03ef47c204a059aced11533 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 25 Nov 2025 15:19:44 +0100 Subject: [PATCH] Move pybind11 to its own extra Signed-off-by: Cristian Le --- .distro/python-scikit-build-core.spec | 6 +++++- pyproject.toml | 6 +++++- tests/conftest.py | 9 ++++++++- tests/test_pyproject_pep517.py | 2 ++ tests/test_pyproject_pep518.py | 4 ++++ tests/test_setuptools_pep517.py | 3 +++ tests/test_setuptools_pep518.py | 2 ++ 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.distro/python-scikit-build-core.spec b/.distro/python-scikit-build-core.spec index 0c516cbb..852b2688 100644 --- a/.distro/python-scikit-build-core.spec +++ b/.distro/python-scikit-build-core.spec @@ -1,5 +1,8 @@ %global debug_package %{nil} +# Whether to run additional tests, enabled by default +%bcond optional_tests 1 + Name: python-scikit-build-core Version: 0.0.0 Release: %autorelease @@ -47,7 +50,7 @@ cp -p src/scikit_build_core/_vendor/pyproject_metadata/LICENSE LICENSE-pyproject %generate_buildrequires export HATCH_METADATA_CLASSIFIERS_NO_VERIFY=1 -%pyproject_buildrequires -g test,test-meta,test-numpy +%pyproject_buildrequires -g test%{?with_optional_tests:,test-meta,test-numpy,test-pybind11} %build @@ -62,6 +65,7 @@ export HATCH_METADATA_CLASSIFIERS_NO_VERIFY=1 %check %pyproject_check_import +# Additional tests from optional_tests are automatically skipped/picked-up by pytest %pytest \ -m "not network" diff --git a/pyproject.toml b/pyproject.toml index e3e3a1a6..c702fbfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,6 @@ test = [ "cattrs >=22.2.0", "pip>=23; python_version<'3.13'", "pip>=24.1; python_version>='3.13'", - "pybind11 >=2.11", "pytest >=7.2", "pytest-subprocess >=1.5", 'pytest-xdist >=3.1', @@ -111,6 +110,10 @@ test-schema = [ "fastjsonschema", "validate-pyproject", ] +test-pybind11 = [ + { include-group = "test" }, + "pybind11 >=2.11", +] cov = [ { include-group = "test" }, "pytest-cov", @@ -120,6 +123,7 @@ dev = [ { include-group = "test-hatchling" }, { include-group = "test-meta" }, { include-group = "test-numpy" }, + { include-group = "test-pybind11" }, { include-group = "test-schema" }, "rich", ] diff --git a/tests/conftest.py b/tests/conftest.py index db9eda95..e5b35188 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -51,7 +51,6 @@ def pep518_wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path: "cython", "hatchling", "pip", - "pybind11", "setuptools", "virtualenv", "wheel", @@ -63,6 +62,9 @@ def pep518_wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path: if importlib.util.find_spec("ninja") is not None: packages.append("ninja") + if importlib.util.find_spec("pybind11") is not None: + packages.append("pybind11") + subprocess.run( [ sys.executable, @@ -374,6 +376,11 @@ def find_spec(name: str, package: str | None = None) -> Any: monkeypatch.setattr(importlib.util, "find_spec", find_spec) +@pytest.fixture +def pybind11(): + return pytest.importorskip("pybind11") + + def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: for item in items: # Ensure all tests using virtualenv are marked as such diff --git a/tests/test_pyproject_pep517.py b/tests/test_pyproject_pep517.py index c7b730c9..457002f1 100644 --- a/tests/test_pyproject_pep517.py +++ b/tests/test_pyproject_pep517.py @@ -197,6 +197,7 @@ def test_passing_cxx_flags(monkeypatch, env_var, setting, tmp_path: Path): @pytest.mark.compile @pytest.mark.configure @pytest.mark.usefixtures("package_simple_pyproject_ext") +@pytest.mark.usefixtures("pybind11") def test_pep517_wheel(virtualenv, tmp_path: Path): dist = tmp_path / "dist" out = build_wheel( @@ -249,6 +250,7 @@ def test_pep517_wheel(virtualenv, tmp_path: Path): @pytest.mark.compile @pytest.mark.configure @pytest.mark.usefixtures("package_simple_pyproject_source_dir") +@pytest.mark.usefixtures("pybind11") def test_pep517_wheel_source_dir(virtualenv, tmp_path: Path): dist = tmp_path / "dist" out = build_wheel(str(dist), config_settings={"skbuild.wheel.build-tag": "1foo"}) diff --git a/tests/test_pyproject_pep518.py b/tests/test_pyproject_pep518.py index 91d551fe..b4f1b826 100644 --- a/tests/test_pyproject_pep518.py +++ b/tests/test_pyproject_pep518.py @@ -25,6 +25,7 @@ def compute_uncompressed_hash(inp: Path): @pytest.mark.network @pytest.mark.integration +@pytest.mark.usefixtures("pybind11") def test_pep518_sdist(isolated, package_simple_pyproject_ext, tmp_path: Path): correct_metadata = textwrap.dedent( """\ @@ -166,6 +167,7 @@ def test_pep518_wheel_sdist_with_cmake_config( @pytest.mark.configure @pytest.mark.integration @pytest.mark.usefixtures("package_simple_pyproject_ext") +@pytest.mark.usefixtures("pybind11") @pytest.mark.parametrize( "build_args", [(), ("--wheel",)], ids=["sdist_to_wheel", "wheel_directly"] ) @@ -211,6 +213,7 @@ def test_pep518_wheel(isolated, build_args, tmp_path: Path): "build_args", [(), ("--wheel",)], ids=["sdist_to_wheel", "wheel_directly"] ) @pytest.mark.usefixtures("package_simple_pyproject_ext") +@pytest.mark.usefixtures("pybind11") def test_pep518_rebuild_build_dir(isolated, tmp_path, build_args): isolated.install("build[virtualenv]") @@ -256,6 +259,7 @@ def test_pep518_rebuild_build_dir(isolated, tmp_path, build_args): @pytest.mark.configure @pytest.mark.integration @pytest.mark.usefixtures("package_simple_pyproject_ext") +@pytest.mark.usefixtures("pybind11") def test_pep518_pip(isolated): isolated.install("-v", ".") diff --git a/tests/test_setuptools_pep517.py b/tests/test_setuptools_pep517.py index b4eb4447..9aaee6a3 100644 --- a/tests/test_setuptools_pep517.py +++ b/tests/test_setuptools_pep517.py @@ -69,6 +69,7 @@ def test_pep517_sdist(tmp_path: Path): @pytest.mark.configure @pytest.mark.broken_on_urct @pytest.mark.usefixtures("package_simple_setuptools_ext") +@pytest.mark.usefixtures("pybind11") def test_pep517_wheel(virtualenv, tmp_path: Path): dist = tmp_path / "dist" out = build_wheel(str(dist)) @@ -149,6 +150,7 @@ def test_toml_sdist(tmp_path: Path): @pytest.mark.compile @pytest.mark.configure @pytest.mark.usefixtures("package_toml_setuptools_ext") +@pytest.mark.usefixtures("pybind11") @pytest.mark.skipif( setuptools_version < Version("61.0"), reason="Requires setuptools 61+" ) @@ -183,6 +185,7 @@ def test_toml_wheel(virtualenv, tmp_path: Path): @pytest.mark.compile @pytest.mark.configure @pytest.mark.usefixtures("package_mixed_setuptools") +@pytest.mark.usefixtures("pybind11") def test_mixed_wheel(virtualenv, tmp_path: Path): dist = tmp_path / "dist" out = build_wheel(str(dist)) diff --git a/tests/test_setuptools_pep518.py b/tests/test_setuptools_pep518.py index cf1d066e..42b943cd 100644 --- a/tests/test_setuptools_pep518.py +++ b/tests/test_setuptools_pep518.py @@ -18,6 +18,7 @@ strict=False, ) @pytest.mark.usefixtures("package_simple_setuptools_ext") +@pytest.mark.usefixtures("pybind11") def test_pep518_wheel(isolated, tmp_path: Path): dist = tmp_path / "dist" isolated.install("build[virtualenv]") @@ -56,6 +57,7 @@ def test_pep518_wheel(isolated, tmp_path: Path): strict=False, ) @pytest.mark.usefixtures("package_simple_setuptools_ext") +@pytest.mark.usefixtures("pybind11") def test_pep518_pip(isolated): isolated.install("-v", ".")