diff --git a/tests/conftest.py b/tests/conftest.py index 1d71451..b5c495a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,10 +19,30 @@ def top_level_dir() -> Path: @pytest.fixture(scope="session") -def buildenv(tmp_path_factory: pytest.TempPathFactory) -> VEnv: +def wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path: + return tmp_path_factory.mktemp("wheelhouse") + + +@pytest.fixture(scope="session") +def buildenv(tmp_path_factory: pytest.TempPathFactory, top_level_dir: Path, wheelhouse: Path) -> VEnv: path = tmp_path_factory.mktemp("cmake_env") venv = VEnv(path) + # install cmake in the venv as it is used as a python module venv.install("cmake") + # fill wheelhouse with all required wheels + # This enable this project to be always the current source, not from a remote index + # This also serves as a manual cache, making everything faster when running all tests + # All builds must use: "--find-links", wheelhouse.as_posix(), "--no-index" + venv.module("pip", "wheel", + "cmake", + "scikit-build-core", + "hatchling", + "vtk==9.6.0", + "vtk-sdk==9.6.0", + top_level_dir.as_posix(), + "--extra-index-url", "https://vtk.org/files/wheel-sdks", + "--wheel-dir", wheelhouse.as_posix() + ) return venv @@ -58,21 +78,7 @@ def dependency(buildenv: VEnv, tmp_path_factory: pytest.TempPathFactory, curdir: @pytest.fixture(scope="session") -def wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path: - return tmp_path_factory.mktemp("wheelhouse") - - -@pytest.fixture(scope="session") -def vtksdk_helper(buildenv: VEnv, top_level_dir: Path, wheelhouse: Path) -> None: - buildenv.module( - "pip", "wheel", top_level_dir.as_posix(), - "--wheel-dir", wheelhouse.as_posix() - ) - assert list(wheelhouse.glob("vtk_sdk_python_wheel_helper-*.whl")) - - -@pytest.fixture(scope="session") -def basic_project(buildenv: VEnv, curdir: Path, dependency: str, wheelhouse: Path, vtksdk_helper) -> None: +def basic_project(buildenv: VEnv, curdir: Path, dependency: str, wheelhouse: Path) -> None: os.environ["Dependency_ROOT"] = dependency basic_project_src = (curdir / "BasicProject").as_posix() @@ -80,14 +86,13 @@ def basic_project(buildenv: VEnv, curdir: Path, dependency: str, wheelhouse: Pat "pip", "wheel", basic_project_src, "--wheel-dir", wheelhouse.as_posix(), "--find-links", wheelhouse.as_posix(), - "--extra-index-url", "https://vtk.org/files/wheel-sdks", - "--extra-index-url", "https://wheels.vtk.org" + "--no-index" ) assert list(wheelhouse.glob("basic_project-*.whl")) @pytest.fixture(scope="session") -def basic_project_sdk(buildenv: VEnv, curdir: Path, dependency: str, wheelhouse: Path, vtksdk_helper) -> None: +def basic_project_sdk(buildenv: VEnv, curdir: Path, dependency: str, wheelhouse: Path) -> None: os.environ["Dependency_ROOT"] = dependency basic_project_src = (curdir / "BasicProject" / "SDK").as_posix() @@ -95,14 +100,12 @@ def basic_project_sdk(buildenv: VEnv, curdir: Path, dependency: str, wheelhouse: "pip", "wheel", basic_project_src, "--wheel-dir", wheelhouse.as_posix(), "--find-links", wheelhouse.as_posix(), - "--extra-index-url", "https://vtk.org/files/wheel-sdks", - "--extra-index-url", "https://wheels.vtk.org" + "--no-index" ) - assert list(wheelhouse.glob("basic_project_sdk-*.whl")) # tmp virtualenv for the test projects @pytest.fixture() -def virtualenv(tmp_path: Path, top_level_dir: Path) -> VEnv: +def virtualenv(tmp_path: Path, buildenv) -> VEnv: path = tmp_path / "venv" - return VEnv(path) + return VEnv(path) \ No newline at end of file diff --git a/tests/packages/all_modules/CMakeLists.txt b/tests/packages/all_modules/CMakeLists.txt new file mode 100644 index 0000000..e809897 --- /dev/null +++ b/tests/packages/all_modules/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.27...3.31) # min required because of VTK::x11 + +project(${SKBUILD_PROJECT_NAME} + VERSION ${SKBUILD_PROJECT_VERSION} + LANGUAGES CXX +) + +# Find the VTK-SDK provided VTK package +# It will be found in a temporary folder generated by scikit-build-core +# thanks to the [entry-point mecanism](https://github.com/Kitware/vtk-sdk-python-distributions) +find_package(VTK CONFIG REQUIRED COMPONENTS CommonCore Python) +# this is a workaround for a VTK-SDK issue on Windows, caused by vtkRenderingOpenXR module. +# This should later become the only find_package, and it should be REQUIRED! +# See https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12363 for more info +find_package(VTK CONFIG QUIET) + +list(REMOVE_ITEM VTK_LIBRARIES + # Public dependency to OpenXR loader makes these hard to import, ignore them + VTK::RenderingOpenXR + VTK::RenderingOpenXRRemoting +) + +list(JOIN VTK_LIBRARIES "\n " VTK_LIBRARIES) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/vtk.module.in + ${CMAKE_CURRENT_SOURCE_DIR}/Dummy/vtk.module + @ONLY +) + +set(modules Dummy::Dummy) + +include(VTKSDKPythonWheelHelper) +vtksdk_build_modules(${SKBUILD_PROJECT_NAME} MODULES ${modules}) +vtksdk_generate_package_init(${SKBUILD_PROJECT_NAME} MODULES ${modules}) diff --git a/tests/packages/all_modules/Dummy/CMakeLists.txt b/tests/packages/all_modules/Dummy/CMakeLists.txt new file mode 100644 index 0000000..43f48bf --- /dev/null +++ b/tests/packages/all_modules/Dummy/CMakeLists.txt @@ -0,0 +1 @@ +vtk_module_add_module(Dummy::Dummy CLASSES vtkDummy) diff --git a/tests/packages/all_modules/Dummy/vtkDummy.cxx b/tests/packages/all_modules/Dummy/vtkDummy.cxx new file mode 100644 index 0000000..0185cf5 --- /dev/null +++ b/tests/packages/all_modules/Dummy/vtkDummy.cxx @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +// SPDX-License-Identifier: BSD-3-Clause +#include "vtkDummy.h" +#include "vtkObjectFactory.h" + +//------------------------------------------------------------------------------ +vtkStandardNewMacro(vtkDummy); + +//------------------------------------------------------------------------------ +void vtkDummy::PrintSelf(ostream& os, vtkIndent indent) +{ + os << indent << "vtkDummy:\n"; + this->Superclass::PrintSelf(os, indent.GetNextIndent()); +} diff --git a/tests/packages/all_modules/Dummy/vtkDummy.h b/tests/packages/all_modules/Dummy/vtkDummy.h new file mode 100644 index 0000000..66b8a57 --- /dev/null +++ b/tests/packages/all_modules/Dummy/vtkDummy.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +// SPDX-License-Identifier: BSD-3-Clause +#ifndef vtkDummy_h +#define vtkDummy_h + +#include "vtkDummyModule.h" // For export macro +#include "vtkObject.h" + +class VTKDUMMY_EXPORT vtkDummy : public vtkObject +{ +public: + static vtkDummy* New(); + vtkTypeMacro(vtkDummy, vtkObject); + void PrintSelf(ostream& os, vtkIndent indent) override; + + vtkDummy() = default; + ~vtkDummy() override = default; + +private: + vtkDummy(const vtkDummy&) = delete; + void operator=(const vtkDummy&) = delete; +}; + +#endif diff --git a/tests/packages/all_modules/pyproject.toml b/tests/packages/all_modules/pyproject.toml new file mode 100644 index 0000000..ae185d7 --- /dev/null +++ b/tests/packages/all_modules/pyproject.toml @@ -0,0 +1,12 @@ +[build-system] +requires = [ + "scikit-build-core", + "vtk-sdk==9.6.0", # Version of "vtk-sdk" should always be specified using "==X.Y.Z" and match the one associated with the "vtk" dependency below. + "vtk-sdk-python-wheel-helper" +] +build-backend = "scikit_build_core.build" + +[project] +name = "all-modules" +version = "1.2.3" +dependencies = ["vtk==9.6.0"] diff --git a/tests/packages/all_modules/vtk.module.in b/tests/packages/all_modules/vtk.module.in new file mode 100644 index 0000000..18c4be9 --- /dev/null +++ b/tests/packages/all_modules/vtk.module.in @@ -0,0 +1,12 @@ +# Note: This file is actually generated and should neither be edited nor committed! +NAME + Dummy::Dummy +LIBRARY_NAME + vtkDummy +SPDX_LICENSE_IDENTIFIER + BSD-3-Clause +SPDX_COPYRIGHT_TEXT + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +DEPENDS + @VTK_LIBRARIES@ + diff --git a/tests/test_all_modules.py b/tests/test_all_modules.py new file mode 100644 index 0000000..05ec32b --- /dev/null +++ b/tests/test_all_modules.py @@ -0,0 +1,17 @@ +""" +This creates a venv and does pip install basic_project_sdk in it, then build another project that consummes the sdk +""" + +from pathlib import Path +from .venv import VEnv + +def test_all_modules(virtualenv: VEnv, curdir: Path, wheelhouse: Path): + all_modules_src = (curdir / "packages" / "all_modules").as_posix() + virtualenv.module( + "pip", "install", all_modules_src, + "--find-links", wheelhouse.as_posix(), + "--no-index", + "--verbose" + ) + + virtualenv.execute("from all_modules import vtkDummy; print(vtkDummy()); exit(0)") diff --git a/tests/test_build_module.py b/tests/test_build_module.py index a2d5f0d..4acdd85 100644 --- a/tests/test_build_module.py +++ b/tests/test_build_module.py @@ -10,8 +10,7 @@ def test_build_module(virtualenv: VEnv, curdir: Path, wheelhouse: Path, basic_pr virtualenv.module( "pip", "install", test_src, "--find-links", wheelhouse.as_posix(), - "--extra-index-url", "https://vtk.org/files/wheel-sdks", - "--extra-index-url", "https://wheels.vtk.org", + "--no-index", "--verbose" ) diff --git a/tests/test_find_package.py b/tests/test_find_package.py index 9d0ece1..c503929 100644 --- a/tests/test_find_package.py +++ b/tests/test_find_package.py @@ -10,5 +10,6 @@ def test_find_package(virtualenv: VEnv, curdir: Path, wheelhouse: Path, basic_pr virtualenv.module( "pip", "install", test_src, "--find-links", wheelhouse.as_posix(), + "--no-index", "--verbose" ) diff --git a/vtk_sdk_python_wheel_helper/VTKSDKPackageInit.cmake b/vtk_sdk_python_wheel_helper/VTKSDKPackageInit.cmake index 5313b4e..258975b 100644 --- a/vtk_sdk_python_wheel_helper/VTKSDKPackageInit.cmake +++ b/vtk_sdk_python_wheel_helper/VTKSDKPackageInit.cmake @@ -79,11 +79,16 @@ function(vtksdk_generate_package_init package_name) if(NOT module MATCHES "^VTK::") continue() endif() - # Exclude this module as it is not wrapped in python - if(module MATCHES "VTK::WrappingPythonCore") + # Ignore unwrapped modules + vtk_module_get_property(${module} PROPERTY INTERFACE_vtk_module_exclude_wrap VARIABLE _wrap) + if(_wrap) continue() endif() vtk_module_get_property(${module} PROPERTY INTERFACE_vtk_module_library_name VARIABLE _name) + # Ignore modules without a library name, this probably means that it is an INTERFACE library + if(NOT _name) + continue() + endif() string(APPEND PACKAGE_INIT "import vtkmodules.${_name}\n") set(need_del_vtkmodules TRUE) endforeach()