Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -58,51 +78,34 @@ 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()
buildenv.module(
"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()
buildenv.module(
"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)
34 changes: 34 additions & 0 deletions tests/packages/all_modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
1 change: 1 addition & 0 deletions tests/packages/all_modules/Dummy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vtk_module_add_module(Dummy::Dummy CLASSES vtkDummy)
14 changes: 14 additions & 0 deletions tests/packages/all_modules/Dummy/vtkDummy.cxx
Original file line number Diff line number Diff line change
@@ -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());
}
24 changes: 24 additions & 0 deletions tests/packages/all_modules/Dummy/vtkDummy.h
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/packages/all_modules/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
12 changes: 12 additions & 0 deletions tests/packages/all_modules/vtk.module.in
Original file line number Diff line number Diff line change
@@ -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@

17 changes: 17 additions & 0 deletions tests/test_all_modules.py
Original file line number Diff line number Diff line change
@@ -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)")
3 changes: 1 addition & 2 deletions tests/test_build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 1 addition & 0 deletions tests/test_find_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
9 changes: 7 additions & 2 deletions vtk_sdk_python_wheel_helper/VTKSDKPackageInit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down