From 674648a9d79545bc3a3124dfa5718aea1dfc6f6c Mon Sep 17 00:00:00 2001 From: Alexy Pellegrini Date: Mon, 25 Mar 2024 10:41:24 +0100 Subject: [PATCH 01/19] Add support for packaging VTK SDK as a wheel This pulls a tar.xz archive from https://vtk.org/files/wheel-sdks and package it as a wheel using scikit-build-core. This wheel will then be added to a pip repository to be fetch through build requirements. --- CMakeLists.txt | 65 ++++++++++++++++++++++++++++--- cmake/vtk-config-version.cmake.in | 1 + cmake/vtk-config.cmake.in | 1 + cmake/vtk-sdk-urls.cmake | 13 +++++++ pyproject.toml | 2 + src/main.cpp | 27 ------------- src/vtk_sdk/_core.pyi | 4 -- src/vtk_sdk/cmake/__init__.py | 1 + tests/test_compiled.py | 11 ------ 9 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 cmake/vtk-config-version.cmake.in create mode 100644 cmake/vtk-config.cmake.in create mode 100644 cmake/vtk-sdk-urls.cmake delete mode 100644 src/main.cpp delete mode 100644 src/vtk_sdk/_core.pyi create mode 100644 src/vtk_sdk/cmake/__init__.py delete mode 100644 tests/test_compiled.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 791b1e4..e372804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,61 @@ -cmake_minimum_required(VERSION 3.15...3.26) -project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) +cmake_minimum_required(VERSION 3.21) -set(PYBIND11_FINDPYTHON ON) -find_package(pybind11 CONFIG REQUIRED) +set(VTK_VERSION + "9.2.5" + CACHE STRING "VTK SDK version to package") +project( + vtk-sdk + VERSION ${VTK_VERSION} + DESCRIPTION "VTK SDK python distributions" + HOMEPAGE_URL "https://github.com/Kitware/vtk-sdk-python-distributions" + LANGUAGES NONE) -pybind11_add_module(_core MODULE src/main.cpp) -install(TARGETS _core DESTINATION ${SKBUILD_PROJECT_NAME}) +find_package( + Python + COMPONENTS Interpreter Development.Module + REQUIRED) + +include(cmake/vtk-sdk-urls.cmake) +include(FetchContent) + +set(download_dir ${PROJECT_BINARY_DIR}) +set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk) +# FetchContent will download and extract our archive! +FetchContent_Populate( + vtkwheelsdk + URL ${VTK_SDK_BINARY_URL} DOWNLOAD_DIR ${download_dir} + SOURCE_DIR ${extract_dir}) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake @ONLY) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config-version.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake @ONLY) + +# "/" after ${extract_dir} is required so the folder content is copied to dest, +# instead of the folder itself! +install( + DIRECTORY ${extract_dir}/ + DESTINATION vtk_sdk + PATTERN "bin/*" EXCLUDE) + +install( + DIRECTORY ${extract_dir}/bin/ + DESTINATION vtk_sdk/bin + PATTERN + "*" + PERMISSIONS + OWNER_READ + OWNER_WRITE + OWNER_EXECUTE + GROUP_READ + GROUP_EXECUTE + WORLD_READ + WORLD_EXECUTE) + +install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/vtk_sdk/cmake/__init__.py + ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake + DESTINATION vtk_sdk/cmake) diff --git a/cmake/vtk-config-version.cmake.in b/cmake/vtk-config-version.cmake.in new file mode 100644 index 0000000..aa0b38b --- /dev/null +++ b/cmake/vtk-config-version.cmake.in @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@VTK_VERSION@.data/headers/cmake/vtk-config-version.cmake) diff --git a/cmake/vtk-config.cmake.in b/cmake/vtk-config.cmake.in new file mode 100644 index 0000000..79b77d5 --- /dev/null +++ b/cmake/vtk-config.cmake.in @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@VTK_VERSION@.data/headers/cmake/vtk-config.cmake) diff --git a/cmake/vtk-sdk-urls.cmake b/cmake/vtk-sdk-urls.cmake new file mode 100644 index 0000000..608593a --- /dev/null +++ b/cmake/vtk-sdk-urls.cmake @@ -0,0 +1,13 @@ +# VTK SDK is currently stored as a tar.xz archive on a Kitware hosted server +set(python_cp "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") + +# enable any linux to download the right tar.xz +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(VTK_SDK_BINARY_URL + "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${python_cp}-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz" + ) +else() + set(VTK_SDK_BINARY_URL + "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${Python_SOABI}.tar.xz" + ) +endif() diff --git a/pyproject.toml b/pyproject.toml index 0002726..0af9b33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,8 @@ Homepage = "https://github.com/Kitware/vtk-sdk-python-distributions" Discussions = "https://github.com/Kitware/vtk-sdk-python-distributions/discussions" Changelog = "https://github.com/Kitware/vtk-sdk-python-distributions/releases" +[project.entry-points."cmake.prefix"] +any = "vtk_sdk.cmake" [tool.scikit-build] minimum-version = "0.8.2" diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index d570cd0..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -int add(int i, int j) { return i + j; } - -namespace py = pybind11; - -PYBIND11_MODULE(_core, m) { - m.doc() = R"pbdoc( - Pybind11 example plugin - ----------------------- - .. currentmodule:: python_example - .. autosummary:: - :toctree: _generate - add - subtract - )pbdoc"; - - m.def("add", &add, R"pbdoc( - Add two numbers - Some other explanation about the add function. - )pbdoc"); - - m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc( - Subtract two numbers - Some other explanation about the subtract function. - )pbdoc"); -} diff --git a/src/vtk_sdk/_core.pyi b/src/vtk_sdk/_core.pyi deleted file mode 100644 index 537c611..0000000 --- a/src/vtk_sdk/_core.pyi +++ /dev/null @@ -1,4 +0,0 @@ -from __future__ import annotations - -def add(_x: int, _y: int) -> int: ... -def subtract(_x: int, _y: int) -> int: ... diff --git a/src/vtk_sdk/cmake/__init__.py b/src/vtk_sdk/cmake/__init__.py new file mode 100644 index 0000000..7739ada --- /dev/null +++ b/src/vtk_sdk/cmake/__init__.py @@ -0,0 +1 @@ +# This module is here because the path of the actual vtk-config.cmake file is not a valid module name diff --git a/tests/test_compiled.py b/tests/test_compiled.py deleted file mode 100644 index d0342ca..0000000 --- a/tests/test_compiled.py +++ /dev/null @@ -1,11 +0,0 @@ -from __future__ import annotations - -import vtk_sdk._core as m - - -def test_add(): - assert m.add(2, 3) == 5 - - -def test_subtract(): - assert m.subtract(7, 5) == 2 From 138c3092d3e18017269103dc6c1f80cd2b8ba00b Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 10:53:30 -0400 Subject: [PATCH 02/19] style: Re-organize CMakeLists into "section" to improve readability --- CMakeLists.txt | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e372804..ad33317 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,23 +15,22 @@ find_package( COMPONENTS Interpreter Development.Module REQUIRED) +# ---------------------------------------------------------------------------- +# Download and extract vtk-wheel-sdk archive + include(cmake/vtk-sdk-urls.cmake) -include(FetchContent) set(download_dir ${PROJECT_BINARY_DIR}) set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk) -# FetchContent will download and extract our archive! + +include(FetchContent) FetchContent_Populate( vtkwheelsdk URL ${VTK_SDK_BINARY_URL} DOWNLOAD_DIR ${download_dir} SOURCE_DIR ${extract_dir}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake @ONLY) - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config-version.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake @ONLY) +# ---------------------------------------------------------------------------- +# Install content of the vtk-wheel-sdk archive # "/" after ${extract_dir} is required so the folder content is copied to dest, # instead of the folder itself! @@ -54,6 +53,16 @@ install( WORLD_READ WORLD_EXECUTE) +# ---------------------------------------------------------------------------- +# Configure and install "cmake.module" entry point files + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake @ONLY) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config-version.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake @ONLY) + install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/vtk_sdk/cmake/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake From 4355aefcc3ef069f0b8ad860066c258cfff9b209 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 10:58:15 -0400 Subject: [PATCH 03/19] fix: install vtk-sdk files into a dedicated directory Do not rely on scikit-build-core automatic package discovery and explicitly install content of the vtk-sdk archive into a dedicated sub-directory. --- CMakeLists.txt | 6 ++++-- cmake/vtk-config-version.cmake.in | 2 +- cmake/vtk-config.cmake.in | 2 +- pyproject.toml | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad33317..b794bf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,16 +32,18 @@ FetchContent_Populate( # ---------------------------------------------------------------------------- # Install content of the vtk-wheel-sdk archive +set(VTK_SDK_INSTALL_DIR "content") + # "/" after ${extract_dir} is required so the folder content is copied to dest, # instead of the folder itself! install( DIRECTORY ${extract_dir}/ - DESTINATION vtk_sdk + DESTINATION vtk_sdk/${VTK_SDK_INSTALL_DIR} PATTERN "bin/*" EXCLUDE) install( DIRECTORY ${extract_dir}/bin/ - DESTINATION vtk_sdk/bin + DESTINATION vtk_sdk/${VTK_SDK_INSTALL_DIR}/bin PATTERN "*" PERMISSIONS diff --git a/cmake/vtk-config-version.cmake.in b/cmake/vtk-config-version.cmake.in index aa0b38b..05fd041 100644 --- a/cmake/vtk-config-version.cmake.in +++ b/cmake/vtk-config-version.cmake.in @@ -1 +1 @@ -include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@VTK_VERSION@.data/headers/cmake/vtk-config-version.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../@VTK_SDK_INSTALL_DIR@/vtk-@VTK_VERSION@.data/headers/cmake/vtk-config-version.cmake) diff --git a/cmake/vtk-config.cmake.in b/cmake/vtk-config.cmake.in index 79b77d5..d3daf73 100644 --- a/cmake/vtk-config.cmake.in +++ b/cmake/vtk-config.cmake.in @@ -1 +1 @@ -include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@VTK_VERSION@.data/headers/cmake/vtk-config.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../@VTK_SDK_INSTALL_DIR@/vtk-@VTK_VERSION@.data/headers/cmake/vtk-config.cmake) diff --git a/pyproject.toml b/pyproject.toml index 0af9b33..d931565 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,7 @@ minimum-version = "0.8.2" build-dir = "build/{wheel_tag}" metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" sdist.include = ["src/vtk_sdk/_version.py"] +wheel.packages = ["src/vtk_sdk"] [tool.setuptools_scm] From 8c6edfd74c0aa36c569cdb545e9ba85ec145bcce Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 11:28:33 -0400 Subject: [PATCH 04/19] fix: Set VTK_VERSION as regular variable Anticipating the introduction of checksum verification, the vtk-sdk archive version will be a static parameter. --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b794bf4..eb97e9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,7 @@ cmake_minimum_required(VERSION 3.21) -set(VTK_VERSION - "9.2.5" - CACHE STRING "VTK SDK version to package") +set(VTK_VERSION "9.2.5") + project( vtk-sdk VERSION ${VTK_VERSION} From d631df1d82e08c17c3ebb06fcbb9ba510b614747 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 11:34:11 -0400 Subject: [PATCH 05/19] doc: improve docstrings --- CMakeLists.txt | 4 ++-- src/vtk_sdk/cmake/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb97e9e..8f78c0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,8 @@ FetchContent_Populate( set(VTK_SDK_INSTALL_DIR "content") -# "/" after ${extract_dir} is required so the folder content is copied to dest, -# instead of the folder itself! +# Append "/" after ${extract_dir} to ensure folder content is copied to the +# destination, instead of the folder itself. install( DIRECTORY ${extract_dir}/ DESTINATION vtk_sdk/${VTK_SDK_INSTALL_DIR} diff --git a/src/vtk_sdk/cmake/__init__.py b/src/vtk_sdk/cmake/__init__.py index 7739ada..07d3077 100644 --- a/src/vtk_sdk/cmake/__init__.py +++ b/src/vtk_sdk/cmake/__init__.py @@ -1 +1,3 @@ -# This module is here because the path of the actual vtk-config.cmake file is not a valid module name +"""This module serves as `cmake-module` scikit-build-core entrypoint to +lookup the location of the `vtk-config.cmake` and `vtk-config-version.cmake` files. +""" From 96e05ca2e52d923770289a1ec98d4284468d4874 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 11:27:04 -0400 Subject: [PATCH 06/19] fix: Consolidate logic for setting download URL Use python, abi and platform tag terminology to match specification. See https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/ --- cmake/vtk-sdk-urls.cmake | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/cmake/vtk-sdk-urls.cmake b/cmake/vtk-sdk-urls.cmake index 608593a..c6c5d55 100644 --- a/cmake/vtk-sdk-urls.cmake +++ b/cmake/vtk-sdk-urls.cmake @@ -1,13 +1,35 @@ -# VTK SDK is currently stored as a tar.xz archive on a Kitware hosted server -set(python_cp "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") - -# enable any linux to download the right tar.xz -if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(VTK_SDK_BINARY_URL - "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${python_cp}-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz" - ) -else() - set(VTK_SDK_BINARY_URL - "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${Python_SOABI}.tar.xz" - ) +# ---------------------------------------------------------------------------- +# Set URLs for downloading the VTK SDK stored as a tar.xz archive on Kitware +# hosted server + +message(STATUS "Setting VTK_SDK_BINARY_URL") + +# Python and ABI tags +set(python_tag "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") +set(abi_tag "${python_tag}") +message(STATUS " python_tag: ${python_tag}") +message(STATUS " abi_tag: ${abi_tag}") + +# Platform tag +if(LINUX AND Python_SOABI MATCHES "x86_64") + set(plaform_tag "manylinux_2_17_x86_64.manylinux2014_x86_64") +elseif(APPLE) + if(Python_SOABI MATCHES "x86_64") + set(plaform_tag "macosx_10_10_x86_64") + elseif(Python_SOABI MATCHES "arm64") + set(plaform_tag "macosx_11_0_arm64") + endif() +elseif(WIN32) + set(plaform_tag "win_amd64") endif() +if(NOT DEFINED plaform_tag) + message( + FATAL_ERROR + "Failed to set plaform_tag based of Python_SOABI [${Python_SOABI}]") +endif() +message(STATUS " plaform_tag: ${plaform_tag}") + +set(VTK_SDK_BINARY_URL + "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}.tar.xz" +) +message(STATUS "Setting VTK_SDK_BINARY_URL: ${VTK_SDK_BINARY_URL}") From c96ffc78f8828facb5c206b51dc17c537292c91d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 12:38:10 -0400 Subject: [PATCH 07/19] fix: Ensure plaform_tag is set for x86_64 macOS --- cmake/vtk-sdk-urls.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmake/vtk-sdk-urls.cmake b/cmake/vtk-sdk-urls.cmake index c6c5d55..7be05ea 100644 --- a/cmake/vtk-sdk-urls.cmake +++ b/cmake/vtk-sdk-urls.cmake @@ -14,9 +14,8 @@ message(STATUS " abi_tag: ${abi_tag}") if(LINUX AND Python_SOABI MATCHES "x86_64") set(plaform_tag "manylinux_2_17_x86_64.manylinux2014_x86_64") elseif(APPLE) - if(Python_SOABI MATCHES "x86_64") - set(plaform_tag "macosx_10_10_x86_64") - elseif(Python_SOABI MATCHES "arm64") + set(plaform_tag "macosx_10_10_x86_64") + if(Python_SOABI MATCHES "arm64") set(plaform_tag "macosx_11_0_arm64") endif() elseif(WIN32) From b6e8e42a3788801947b450659ca7bb3c0cd27600 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 12:25:36 -0400 Subject: [PATCH 08/19] feat: Add support for checking expected checksum --- CMakeLists.txt | 4 +++- cmake/vtk-sdk-urls.cmake | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f78c0b..71b7a58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,9 @@ set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk) include(FetchContent) FetchContent_Populate( vtkwheelsdk - URL ${VTK_SDK_BINARY_URL} DOWNLOAD_DIR ${download_dir} + URL ${VTK_SDK_BINARY_URL} + URL_HASH SHA256=${VTK_SDK_EXPECTED_SHA256} + DOWNLOAD_DIR ${download_dir} SOURCE_DIR ${extract_dir}) # ---------------------------------------------------------------------------- diff --git a/cmake/vtk-sdk-urls.cmake b/cmake/vtk-sdk-urls.cmake index 7be05ea..82513e0 100644 --- a/cmake/vtk-sdk-urls.cmake +++ b/cmake/vtk-sdk-urls.cmake @@ -32,3 +32,53 @@ set(VTK_SDK_BINARY_URL "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}.tar.xz" ) message(STATUS "Setting VTK_SDK_BINARY_URL: ${VTK_SDK_BINARY_URL}") + +# ---------------------------------------------------------------------------- +# Set expected checksum + +message(STATUS "Setting VTK_SDK_EXPECTED_SHA256") + +set(sha256_9.2.5-cp38-cp38-macosx_10_10_x86_64 + "a97438851a029fc3e9a630261a101001f5fc2edae45710f1cb0cde2dd2899334") +set(sha256_9.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64 + "f67ab5114eeccda490bd5a7ab8e6921e0b59d51489e7f47eb0ebc7f18e7cbd93") +set(sha256_9.2.5-cp38-cp38-win_amd64 + "306360396efa3cffb03ecda75c4df84a89ededf05d0adfda4894d80adf2542ec") + +set(sha256_9.2.5-cp39-cp39-macosx_10_10_x86_64 + "6a63d28a726188194fa7858d33645f43ea9ef21e696b8da91cc0536cf4c9131a") +set(sha256_9.2.5-cp39-cp39-macosx_11_0_arm64 + "3747b3448b1ae0f511a389f82398a1ec5a883189ed01ed35c870ef746096ec6d") +set(sha256_9.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64 + "8199f0cff9a43831eadeba0e4d89421c947002c53c030c50edb50312bb0726cd") +set(sha256_9.2.5-cp39-cp39-win_amd64 + "befbbea3bfc8584c5dd3b2c04b5ce7273eeb4581a5586adf10cb35b859609026") + +set(sha256_9.2.5-cp310-cp310-macosx_10_10_x86_64 + "a0d37d8f93521753cb3bed8da3548f9f6c1f45cee493070b5dcc3801f62b33e5") +set(sha256_9.2.5-cp310-cp310-macosx_11_0_arm64 + "99120ac6448907865b1feb95be4111992d2d511954d2c381bd5299ec87c6f76c") +set(sha256_9.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64 + "79f8a8c6caf9d98aef29426637ea9eb9228682072dfa5b69bb97dc3baa2e93d7") +set(sha256_9.2.5-cp310-cp310-win_amd64 + "b85c5d48e6c36082c590276dd34458e5238cea7ae37156b5b30a2ca3e133d2b9") + +set(sha256_9.2.5-cp311-cp311-macosx_10_10_x86_64 + "f0bf60a0c740b9c92bb0f35cadb1f0c38d23b3994bdf24295ac986761dc6e59c") +set(sha256_9.2.5-cp311-cp311-macosx_11_0_arm64 + "d2948347e7c803d8e691b48d58dd057ddb2265baf603eb0d7036a71a538e037d") +set(sha256_9.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64 + "dcd452e018b3a5a7a0b5dfab8e38af2ddbd0e0e387b1a8488b4516354c4a30fb") +set(sha256_9.2.5-cp311-cp311-win_amd64 + "f70dca96484ba357fad52ce4d998b6480e5717e7e1d0f707f20c494c41d7a00e") + +if(NOT DEFINED sha256_${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}) + message( + FATAL_ERROR + "Variable sha256_${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag} is not defined" + ) +endif() + +set(VTK_SDK_EXPECTED_SHA256 + ${sha256_${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}}) +message(STATUS "Setting VTK_SDK_EXPECTED_SHA256: ${VTK_SDK_EXPECTED_SHA256}") From e8cc86d509a6cdf659f9775380ca56e80bce8a7c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 12:32:28 -0400 Subject: [PATCH 09/19] ci: Update CI & CD workflow to run against Python 3.8 to 3.11 Exclude Python 3.12 not supported with VTK 9.2.5 SDKs --- .github/workflows/cd.yml | 4 ++++ .github/workflows/ci.yml | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 21958a3..f849700 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -37,6 +37,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] + arch: ["auto"] steps: - uses: actions/checkout@v4 @@ -44,6 +45,9 @@ jobs: fetch-depth: 0 - uses: pypa/cibuildwheel@v2.17 + env: + CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-*" + CIBW_ARCHS: "${{ matrix.arch }}" - name: Upload wheels uses: actions/upload-artifact@v4 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a3d7a8..b78547a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,13 +40,9 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11"] runs-on: [ubuntu-latest, macos-latest, windows-latest] - include: - - python-version: pypy-3.10 - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 with: From 6a62e10009d1143c27ffbf7d77791995a9f68916 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 13:52:29 -0400 Subject: [PATCH 10/19] ci: Update cd.yml to publish wheel on "pypi" instead of "test-pypi" --- .github/workflows/cd.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index f849700..b9d4ef1 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -71,7 +71,3 @@ jobs: merge-multiple: true - uses: pypa/gh-action-pypi-publish@release/v1 - with: - # Remember to tell (test-)pypi about this repo before publishing - # Remove this line to publish to PyPI - repository-url: https://test.pypi.org/legacy/ From 5db843a5084d6507931861b952759d9dcc156b3d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 14:13:23 -0400 Subject: [PATCH 11/19] ci: Update "cd.yml" adding "test_sdist" and "check_dist" jobs Adapted from https://github.com/scikit-build/cmake-python-distributions --- .github/workflows/cd.yml | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b9d4ef1..4100473 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -30,6 +30,51 @@ jobs: name: cibw-sdist path: dist/*.tar.gz + test_sdist: + name: Test SDist with python ${{ matrix.python }} + needs: [make_sdist] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + name: Install Python ${{ matrix.python }} + with: + python-version: ${{ matrix.python }} + + - name: Install dependencies + run: | + pip install pytest pytest-cov + + - uses: actions/download-artifact@v4 + with: + name: cibw-sdist + path: dist + + - name: Install SDist + run: | + pip -V + pip install dist/*.tar.gz + rm -rf dist + + - name: Test installed SDist + run: pytest ./tests + + check_dist: + name: Check dist + needs: [build_wheels, make_sdist, test_sdist] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + path: all + + - run: pipx run twine check --strict all/*/* + build_wheels: name: Wheel on ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -56,7 +101,7 @@ jobs: path: wheelhouse/*.whl upload_all: - needs: [build_wheels, make_sdist] + needs: [check_dist] environment: pypi permissions: id-token: write From 4e8d25dc4a6e9bc7f856097fe18e6b98ef39cd11 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 14:05:14 -0400 Subject: [PATCH 12/19] feat: Add support for generating macOS arm64 wheels --- .github/workflows/cd.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 4100473..49ef99e 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -84,6 +84,10 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] arch: ["auto"] + include: + - os: macos-14 + arch: "arm64" + steps: - uses: actions/checkout@v4 with: From 47488c99ec59d33eac51d9bc04159b86b0855d45 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 14:30:08 -0400 Subject: [PATCH 13/19] ci: Test building of macOS arm64 wheels in CI workflow --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b78547a..854b16e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,3 +65,33 @@ jobs: uses: codecov/codecov-action@v4.1.0 with: token: ${{ secrets.CODECOV_TOKEN }} + + checks-cibw: + name: > + Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} (${{ + matrix.arch }}) + runs-on: ${{ matrix.runs-on }} + needs: [pre-commit] + strategy: + fail-fast: false + matrix: + include: + - runs-on: macos-14 + python-version: cp39 + arch: "arm64" + - runs-on: macos-14 + python-version: cp310 + arch: "arm64" + - runs-on: macos-14 + python-version: cp311 + arch: "arm64" + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: pypa/cibuildwheel@v2.17 + env: + CIBW_BUILD: "${{ matrix.python-version }}-*" + CIBW_ARCHS: "${{ matrix.arch }}" From 5c2c308c2f2d1e46added77b36640278bd6c6206 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 14:39:35 -0400 Subject: [PATCH 14/19] fix: Disable cibuildwheel repair command The vtk-sdk is expected to be distributed as-is without being modified using default repair commands. See https://cibuildwheel.pypa.io/en/1.x/options/#repair-wheel-command --- .github/workflows/cd.yml | 1 + .github/workflows/ci.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 49ef99e..85c89c2 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -97,6 +97,7 @@ jobs: env: CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-*" CIBW_ARCHS: "${{ matrix.arch }}" + CIBW_REPAIR_WHEEL_COMMAND: "" - name: Upload wheels uses: actions/upload-artifact@v4 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 854b16e..534b1c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,3 +95,4 @@ jobs: env: CIBW_BUILD: "${{ matrix.python-version }}-*" CIBW_ARCHS: "${{ matrix.arch }}" + CIBW_REPAIR_WHEEL_COMMAND: "" From b8b84853205af94baac972012b58b39995aa0094 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 27 Mar 2024 15:08:02 -0400 Subject: [PATCH 15/19] doc: Fix entrypoint references to consistently mention "cmake.prefix" --- CMakeLists.txt | 2 +- README.md | 2 +- src/vtk_sdk/__init__.py | 2 +- src/vtk_sdk/cmake/__init__.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71b7a58..f49303d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ install( WORLD_EXECUTE) # ---------------------------------------------------------------------------- -# Configure and install "cmake.module" entry point files +# Configure and install "cmake.prefix" entry point files configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake @ONLY) diff --git a/README.md b/README.md index bca51b2..5fa6fdd 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ distributed-memory parallel processing for scalability and better performance. This project is intended to distribute the content of the existing VTK wheel SDKs as first-class `vtk-sdk` wheels. -Each `vtk-sdk` Python wheel is equipped with a scikit-build-core `cmake-module` +Each `vtk-sdk` Python wheel is equipped with a scikit-build-core `cmake.prefix` [entrypoint][scikit-build-core-entrypoint], housing the official VTK SDK sourced from the corresponding [archive][wheel-sdks-link]. diff --git a/src/vtk_sdk/__init__.py b/src/vtk_sdk/__init__.py index d081a1d..d7e1c59 100644 --- a/src/vtk_sdk/__init__.py +++ b/src/vtk_sdk/__init__.py @@ -1,7 +1,7 @@ """ Copyright (c) 2024 Jean-Christophe Fillion-Robin. All rights reserved. -vtk-sdk: Distribution of the VTK wheel SDK with a convenient "cmake-module" scikit-build-core entrypoint +vtk-sdk: Distribution of the VTK wheel SDK with a convenient "cmake.prefix" scikit-build-core entrypoint """ from __future__ import annotations diff --git a/src/vtk_sdk/cmake/__init__.py b/src/vtk_sdk/cmake/__init__.py index 07d3077..e0de3db 100644 --- a/src/vtk_sdk/cmake/__init__.py +++ b/src/vtk_sdk/cmake/__init__.py @@ -1,3 +1,3 @@ -"""This module serves as `cmake-module` scikit-build-core entrypoint to +"""This module serves as `cmake.prefix` scikit-build-core entrypoint to lookup the location of the `vtk-config.cmake` and `vtk-config-version.cmake` files. """ From a9fe306b7b3b7233f8902b6c8cf79b87e9b8635c Mon Sep 17 00:00:00 2001 From: Alexy Pellegrini Date: Thu, 28 Mar 2024 15:55:01 +0100 Subject: [PATCH 16/19] feat: add test --- tests/packages/find_package/CMakeLists.txt | 10 +++ tests/packages/find_package/pyproject.toml | 12 +++ tests/packages/src/vtk_simple/__init__.py | 0 tests/test_find_package.py | 97 ++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 tests/packages/find_package/CMakeLists.txt create mode 100644 tests/packages/find_package/pyproject.toml create mode 100644 tests/packages/src/vtk_simple/__init__.py create mode 100644 tests/test_find_package.py diff --git a/tests/packages/find_package/CMakeLists.txt b/tests/packages/find_package/CMakeLists.txt new file mode 100644 index 0000000..804bfc7 --- /dev/null +++ b/tests/packages/find_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.15...3.26) + +project( + ${SKBUILD_PROJECT_NAME} + VERSION ${SKBUILD_PROJECT_VERSION}) + +find_package(Python COMPONENTS Interpreter Development.Module) + +set(expected_version "9.2.5") +find_package(VTK ${expected_version} REQUIRED) diff --git a/tests/packages/find_package/pyproject.toml b/tests/packages/find_package/pyproject.toml new file mode 100644 index 0000000..32a838c --- /dev/null +++ b/tests/packages/find_package/pyproject.toml @@ -0,0 +1,12 @@ +[build-system] +requires = ["scikit-build-core", "vtk-sdk"] +build-backend = "scikit_build_core.build" + +[project] +name = "vtk-sdk-test" +version = "1.0.0" +authors = [ + { name = "Alexy Pellegrini", email = "alexy.pellegrini@kitware.com" }, + { name = "Jean-Christophe Fillion-Robin", email = "jchris.fillionr@kitware.com" }, +] +dependencies = [] diff --git a/tests/packages/src/vtk_simple/__init__.py b/tests/packages/src/vtk_simple/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_find_package.py b/tests/test_find_package.py new file mode 100644 index 0000000..3c87cd0 --- /dev/null +++ b/tests/test_find_package.py @@ -0,0 +1,97 @@ +from __future__ import annotations + +import os +import subprocess +import sys +import virtualenv as _virtualenv +import pytest +from pathlib import Path +from typing import Literal, overload + +DIR = Path(__file__).parent.resolve() +BASE = DIR / "packages" / "find_package" + + +class VEnv: + def __init__(self, env_dir: Path, *, wheelhouse: Path | None = None) -> None: + cmd = [str(env_dir), "--no-setuptools", "--no-wheel", "--activators", ""] + result = _virtualenv.cli_run(cmd, setup_logging=False) + self.wheelhouse = wheelhouse + self.executable = Path(result.creator.exe) + self.env_dir = env_dir.resolve() + self.platlib = Path( + self.execute("import sysconfig; print(sysconfig.get_path('platlib'))") + ) + self.purelib = Path( + self.execute("import sysconfig; print(sysconfig.get_path('purelib'))") + ) + + @overload + def run(self, *args: str, capture: Literal[True]) -> str: ... + + @overload + def run(self, *args: str, capture: Literal[False] = ...) -> None: ... + + def run(self, *args: str, capture: bool = False) -> str | None: + __tracebackhide__ = True + env = os.environ.copy() + paths = {str(self.executable.parent)} + env["PATH"] = os.pathsep.join([*paths, env["PATH"]]) + env["VIRTUAL_ENV"] = str(self.env_dir) + env["PIP_DISABLE_PIP_VERSION_CHECK"] = "ON" + if self.wheelhouse is not None: + env["PIP_NO_INDEX"] = "ON" + env["PIP_FIND_LINKS"] = str(self.wheelhouse) + + str_args = [os.fspath(a) for a in args] + + # Windows does not make a python shortcut in venv + if str_args[0] in {"python", "python3"}: + str_args[0] = str(self.executable) + + if capture: + result = subprocess.run( + str_args, + check=False, + capture_output=True, + text=True, + env=env, + ) + if result.returncode != 0: + print(result.stdout, file=sys.stdout) + print(result.stderr, file=sys.stderr) + print("FAILED RUN:", *str_args, file=sys.stderr) + raise SystemExit(result.returncode) + return result.stdout.strip() + + result_bytes = subprocess.run( + str_args, + check=False, + env=env, + ) + if result_bytes.returncode != 0: + print("FAILED RUN:", *str_args, file=sys.stderr) + raise SystemExit(result_bytes.returncode) + return None + + def execute(self, command: str) -> str: + return self.run(str(self.executable), "-c", command, capture=True) + + def module(self, *args: str) -> None: + return self.run(str(self.executable), "-m", *args) + + def install(self, *args: str, isolated: bool = True) -> None: + isolated_flags = "" if isolated else ["--no-build-isolation"] + self.module("pip", "install", *isolated_flags, *args) + + +@pytest.fixture() +def virtualenv(tmp_path: Path) -> VEnv: + path = tmp_path / "venv" + return VEnv(path) + + +def test_find_package(virtualenv: VEnv): + virtualenv.run( + "python", "-m", "pip", "wheel", "--find-links", str(DIR.parent), str(BASE) + ) From 85ca0b82c97f0e9aac01ab907147eddeaa5bcde1 Mon Sep 17 00:00:00 2001 From: Alexy Pellegrini Date: Thu, 28 Mar 2024 16:06:36 +0100 Subject: [PATCH 17/19] feat: add test --- tests/packages/find_package/CMakeLists.txt | 4 +--- tests/test_find_package.py | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/packages/find_package/CMakeLists.txt b/tests/packages/find_package/CMakeLists.txt index 804bfc7..cfff955 100644 --- a/tests/packages/find_package/CMakeLists.txt +++ b/tests/packages/find_package/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.15...3.26) -project( - ${SKBUILD_PROJECT_NAME} - VERSION ${SKBUILD_PROJECT_VERSION}) +project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION}) find_package(Python COMPONENTS Interpreter Development.Module) diff --git a/tests/test_find_package.py b/tests/test_find_package.py index 3c87cd0..ff2c9a5 100644 --- a/tests/test_find_package.py +++ b/tests/test_find_package.py @@ -3,11 +3,12 @@ import os import subprocess import sys -import virtualenv as _virtualenv -import pytest from pathlib import Path from typing import Literal, overload +import pytest +import virtualenv as _virtualenv + DIR = Path(__file__).parent.resolve() BASE = DIR / "packages" / "find_package" From 9a840d6db43d85a1d6c11ddf041cba90bebc5d9b Mon Sep 17 00:00:00 2001 From: Alexy Pellegrini Date: Thu, 28 Mar 2024 11:16:19 -0400 Subject: [PATCH 18/19] fix: install vtk-sdk package before using it --- .pre-commit-config.yaml | 1 + pyproject.toml | 1 + tests/test_find_package.py | 12 +++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f277c4..d2d36c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,6 +60,7 @@ repos: args: [] additional_dependencies: - pytest + - virtualenv - repo: https://github.com/codespell-project/codespell rev: "v2.2.6" diff --git a/pyproject.toml b/pyproject.toml index d931565..851b361 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ dependencies = [] test = [ "pytest >=6", "pytest-cov >=3", + "virtualenv", ] dev = [ "pytest >=6", diff --git a/tests/test_find_package.py b/tests/test_find_package.py index ff2c9a5..6e07334 100644 --- a/tests/test_find_package.py +++ b/tests/test_find_package.py @@ -7,7 +7,7 @@ from typing import Literal, overload import pytest -import virtualenv as _virtualenv +import virtualenv as _virtualenv # type: ignore[import-untyped] DIR = Path(__file__).parent.resolve() BASE = DIR / "packages" / "find_package" @@ -92,7 +92,13 @@ def virtualenv(tmp_path: Path) -> VEnv: return VEnv(path) -def test_find_package(virtualenv: VEnv): +ROOT = DIR.parent + + +def test_find_package(virtualenv: VEnv, tmp_path: Path): + virtualenv.run( + "python", "-m", "pip", "wheel", str(ROOT), "--wheel-dir", str(tmp_path) + ) virtualenv.run( - "python", "-m", "pip", "wheel", "--find-links", str(DIR.parent), str(BASE) + "python", "-m", "pip", "install", "--find-links", str(tmp_path), str(BASE) ) From ea72d4c52c49e6d033b81e96e019670e41b10302 Mon Sep 17 00:00:00 2001 From: Alexy Pellegrini Date: Fri, 29 Mar 2024 17:15:57 +0100 Subject: [PATCH 19/19] feat: Add a script to update SDK URLs automatically --- CMakeLists.txt | 13 +-- cmake/download-vtk-sdk.cmake | 57 +++++++++++++ cmake/vtk-sdk-urls.cmake | 132 ++++++++++++------------------ scripts/update_vtk_sdk_version.py | 90 ++++++++++++++++++++ 4 files changed, 200 insertions(+), 92 deletions(-) create mode 100644 cmake/download-vtk-sdk.cmake create mode 100644 scripts/update_vtk_sdk_version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index f49303d..a82ef05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,18 +17,7 @@ find_package( # ---------------------------------------------------------------------------- # Download and extract vtk-wheel-sdk archive -include(cmake/vtk-sdk-urls.cmake) - -set(download_dir ${PROJECT_BINARY_DIR}) -set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk) - -include(FetchContent) -FetchContent_Populate( - vtkwheelsdk - URL ${VTK_SDK_BINARY_URL} - URL_HASH SHA256=${VTK_SDK_EXPECTED_SHA256} - DOWNLOAD_DIR ${download_dir} - SOURCE_DIR ${extract_dir}) +include(cmake/download-vtk-sdk.cmake) # ---------------------------------------------------------------------------- # Install content of the vtk-wheel-sdk archive diff --git a/cmake/download-vtk-sdk.cmake b/cmake/download-vtk-sdk.cmake new file mode 100644 index 0000000..d93e276 --- /dev/null +++ b/cmake/download-vtk-sdk.cmake @@ -0,0 +1,57 @@ +message(STATUS "Setting VTK_SDK_BINARY_URL") + +# Python and ABI tags +set(python_abi_name "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") +set(PYTHON_ABI_TAG "${python_abi_name}-${python_abi_name}") +include(${CMAKE_CURRENT_LIST_DIR}/vtk-sdk-urls.cmake) + +# Platform tag +if(LINUX) + if(Python_SOABI MATCHES "x86_64") + set(plaform_name "linux_x86_64") + elseif(Python_SOABI MATCHES "arm64") + set(plaform_name "linux_arm64") + else() + message(FATAL_ERROR "Unsupported SOABI [${Python_SOABI}]") + endif() +elseif(APPLE) + set(plaform_name "macosx_x86_64") + if(Python_SOABI MATCHES "arm64") + set(plaform_name "macosx_arm64") + endif() +elseif(WIN32) + set(plaform_name "win_x86_64") + if(Python_SOABI MATCHES "arm64") + set(plaform_name "win_arm64") + endif() +else() + message( + FATAL_ERROR + "Failed to set plaform_tag based of Python_SOABI [${Python_SOABI}]") +endif() + +# URL and SHA256 +set(VTK_SDK_BINARY_URL ${${plaform_name}_url}) +message(STATUS "Setting VTK_SDK_BINARY_URL: ${VTK_SDK_BINARY_URL}") + +set(VTK_SDK_EXPECTED_SHA256 ${${plaform_name}_sha256}) +message(STATUS "Setting VTK_SDK_EXPECTED_SHA256: ${VTK_SDK_EXPECTED_SHA256}") + +if(NOT DEFINED VTK_SDK_BINARY_URL OR NOT DEFINED VTK_SDK_EXPECTED_SHA256) + message(FATAL_ERROR "Unsupported platform ${plaform_name}") +endif() + +if(${VTK_SDK_BINARY_URL} STREQUAL "NOTFOUND" OR ${VTK_SDK_EXPECTED_SHA256} STREQUAL "NOTFOUND") + message(FATAL_ERROR "Unsupported platform ${plaform_name}") +endif() + +set(download_dir ${PROJECT_BINARY_DIR}) +set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk) + +include(FetchContent) +FetchContent_Populate( + vtkwheelsdk + URL ${VTK_SDK_BINARY_URL} + URL_HASH SHA256=${VTK_SDK_EXPECTED_SHA256} + DOWNLOAD_DIR ${download_dir} + SOURCE_DIR ${extract_dir}) diff --git a/cmake/vtk-sdk-urls.cmake b/cmake/vtk-sdk-urls.cmake index 82513e0..db348da 100644 --- a/cmake/vtk-sdk-urls.cmake +++ b/cmake/vtk-sdk-urls.cmake @@ -1,84 +1,56 @@ -# ---------------------------------------------------------------------------- -# Set URLs for downloading the VTK SDK stored as a tar.xz archive on Kitware -# hosted server - -message(STATUS "Setting VTK_SDK_BINARY_URL") - -# Python and ABI tags -set(python_tag "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") -set(abi_tag "${python_tag}") -message(STATUS " python_tag: ${python_tag}") -message(STATUS " abi_tag: ${abi_tag}") - -# Platform tag -if(LINUX AND Python_SOABI MATCHES "x86_64") - set(plaform_tag "manylinux_2_17_x86_64.manylinux2014_x86_64") -elseif(APPLE) - set(plaform_tag "macosx_10_10_x86_64") - if(Python_SOABI MATCHES "arm64") - set(plaform_tag "macosx_11_0_arm64") - endif() -elseif(WIN32) - set(plaform_tag "win_amd64") + +if(${PYTHON_ABI_TAG} STREQUAL "cp38-cp38") + set(linux_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz") + set(linux_x86_64_sha256 "f67ab5114eeccda490bd5a7ab8e6921e0b59d51489e7f47eb0ebc7f18e7cbd93") + + set(macosx_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp38-cp38-macosx_10_10_x86_64.tar.xz") + set(macosx_x86_64_sha256 "a97438851a029fc3e9a630261a101001f5fc2edae45710f1cb0cde2dd2899334") + + set(macosx_arm64_url "NOTFOUND") + set(macosx_arm64_sha256 "NOTFOUND") + + set(win_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp38-cp38-win_amd64.tar.xz") + set(win_x86_64_sha256 "306360396efa3cffb03ecda75c4df84a89ededf05d0adfda4894d80adf2542ec") endif() -if(NOT DEFINED plaform_tag) - message( - FATAL_ERROR - "Failed to set plaform_tag based of Python_SOABI [${Python_SOABI}]") + +if(${PYTHON_ABI_TAG} STREQUAL "cp39-cp39") + set(linux_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz") + set(linux_x86_64_sha256 "8199f0cff9a43831eadeba0e4d89421c947002c53c030c50edb50312bb0726cd") + + set(macosx_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp39-cp39-macosx_10_10_x86_64.tar.xz") + set(macosx_x86_64_sha256 "6a63d28a726188194fa7858d33645f43ea9ef21e696b8da91cc0536cf4c9131a") + + set(macosx_arm64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp39-cp39-macosx_11_0_arm64.tar.xz") + set(macosx_arm64_sha256 "3747b3448b1ae0f511a389f82398a1ec5a883189ed01ed35c870ef746096ec6d") + + set(win_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp39-cp39-win_amd64.tar.xz") + set(win_x86_64_sha256 "befbbea3bfc8584c5dd3b2c04b5ce7273eeb4581a5586adf10cb35b859609026") endif() -message(STATUS " plaform_tag: ${plaform_tag}") - -set(VTK_SDK_BINARY_URL - "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}.tar.xz" -) -message(STATUS "Setting VTK_SDK_BINARY_URL: ${VTK_SDK_BINARY_URL}") - -# ---------------------------------------------------------------------------- -# Set expected checksum - -message(STATUS "Setting VTK_SDK_EXPECTED_SHA256") - -set(sha256_9.2.5-cp38-cp38-macosx_10_10_x86_64 - "a97438851a029fc3e9a630261a101001f5fc2edae45710f1cb0cde2dd2899334") -set(sha256_9.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64 - "f67ab5114eeccda490bd5a7ab8e6921e0b59d51489e7f47eb0ebc7f18e7cbd93") -set(sha256_9.2.5-cp38-cp38-win_amd64 - "306360396efa3cffb03ecda75c4df84a89ededf05d0adfda4894d80adf2542ec") - -set(sha256_9.2.5-cp39-cp39-macosx_10_10_x86_64 - "6a63d28a726188194fa7858d33645f43ea9ef21e696b8da91cc0536cf4c9131a") -set(sha256_9.2.5-cp39-cp39-macosx_11_0_arm64 - "3747b3448b1ae0f511a389f82398a1ec5a883189ed01ed35c870ef746096ec6d") -set(sha256_9.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64 - "8199f0cff9a43831eadeba0e4d89421c947002c53c030c50edb50312bb0726cd") -set(sha256_9.2.5-cp39-cp39-win_amd64 - "befbbea3bfc8584c5dd3b2c04b5ce7273eeb4581a5586adf10cb35b859609026") - -set(sha256_9.2.5-cp310-cp310-macosx_10_10_x86_64 - "a0d37d8f93521753cb3bed8da3548f9f6c1f45cee493070b5dcc3801f62b33e5") -set(sha256_9.2.5-cp310-cp310-macosx_11_0_arm64 - "99120ac6448907865b1feb95be4111992d2d511954d2c381bd5299ec87c6f76c") -set(sha256_9.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64 - "79f8a8c6caf9d98aef29426637ea9eb9228682072dfa5b69bb97dc3baa2e93d7") -set(sha256_9.2.5-cp310-cp310-win_amd64 - "b85c5d48e6c36082c590276dd34458e5238cea7ae37156b5b30a2ca3e133d2b9") - -set(sha256_9.2.5-cp311-cp311-macosx_10_10_x86_64 - "f0bf60a0c740b9c92bb0f35cadb1f0c38d23b3994bdf24295ac986761dc6e59c") -set(sha256_9.2.5-cp311-cp311-macosx_11_0_arm64 - "d2948347e7c803d8e691b48d58dd057ddb2265baf603eb0d7036a71a538e037d") -set(sha256_9.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64 - "dcd452e018b3a5a7a0b5dfab8e38af2ddbd0e0e387b1a8488b4516354c4a30fb") -set(sha256_9.2.5-cp311-cp311-win_amd64 - "f70dca96484ba357fad52ce4d998b6480e5717e7e1d0f707f20c494c41d7a00e") - -if(NOT DEFINED sha256_${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}) - message( - FATAL_ERROR - "Variable sha256_${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag} is not defined" - ) + +if(${PYTHON_ABI_TAG} STREQUAL "cp310-cp310") + set(linux_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz") + set(linux_x86_64_sha256 "79f8a8c6caf9d98aef29426637ea9eb9228682072dfa5b69bb97dc3baa2e93d7") + + set(macosx_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp310-cp310-macosx_10_10_x86_64.tar.xz") + set(macosx_x86_64_sha256 "a0d37d8f93521753cb3bed8da3548f9f6c1f45cee493070b5dcc3801f62b33e5") + + set(macosx_arm64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp310-cp310-macosx_11_0_arm64.tar.xz") + set(macosx_arm64_sha256 "99120ac6448907865b1feb95be4111992d2d511954d2c381bd5299ec87c6f76c") + + set(win_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp310-cp310-win_amd64.tar.xz") + set(win_x86_64_sha256 "b85c5d48e6c36082c590276dd34458e5238cea7ae37156b5b30a2ca3e133d2b9") endif() -set(VTK_SDK_EXPECTED_SHA256 - ${sha256_${VTK_VERSION}-${python_tag}-${abi_tag}-${plaform_tag}}) -message(STATUS "Setting VTK_SDK_EXPECTED_SHA256: ${VTK_SDK_EXPECTED_SHA256}") +if(${PYTHON_ABI_TAG} STREQUAL "cp311-cp311") + set(linux_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz") + set(linux_x86_64_sha256 "dcd452e018b3a5a7a0b5dfab8e38af2ddbd0e0e387b1a8488b4516354c4a30fb") + + set(macosx_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp311-cp311-macosx_10_10_x86_64.tar.xz") + set(macosx_x86_64_sha256 "f0bf60a0c740b9c92bb0f35cadb1f0c38d23b3994bdf24295ac986761dc6e59c") + + set(macosx_arm64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp311-cp311-macosx_11_0_arm64.tar.xz") + set(macosx_arm64_sha256 "d2948347e7c803d8e691b48d58dd057ddb2265baf603eb0d7036a71a538e037d") + + set(win_x86_64_url "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-9.2.5-cp311-cp311-win_amd64.tar.xz") + set(win_x86_64_sha256 "f70dca96484ba357fad52ce4d998b6480e5717e7e1d0f707f20c494c41d7a00e") +endif() diff --git a/scripts/update_vtk_sdk_version.py b/scripts/update_vtk_sdk_version.py new file mode 100644 index 0000000..14597a8 --- /dev/null +++ b/scripts/update_vtk_sdk_version.py @@ -0,0 +1,90 @@ +from __future__ import annotations + +import os +import textwrap +import urllib.request + +VTK_VERSION = "9.2.5" +ABI_TAGS = ["cp38-cp38", "cp39-cp39", "cp310-cp310", "cp311-cp311"] +PLATFORMS = { + "macosx_x86_64": "macosx_10_10_x86_64", + "macosx_arm64": "macosx_11_0_arm64", + "linux_x86_64": "manylinux_2_17_x86_64.manylinux2014_x86_64", + "win_x86_64": "win_amd64", +} + + +def download_file(url: str, filename: str): + if not os.path.exists(filename) or os.stat(filename).st_size == 0: + print(f"Requesting download {filename} from {url} ...") + try: + urllib.request.urlretrieve(url, filename) + print("Download finished") + except OSError as exc: + msg = f"Failed to download {url} to {filename}: {exc}" + raise ValueError(msg) + + +def generate_cmake_variables(urls_and_sha256s: dict, abi: str): + template_inputs = {"abi": abi} + + # Get SHA256s and URLs + for var_prefix, urls_and_sha256s_values in urls_and_sha256s.items(): + template_inputs[f"{var_prefix}_url"] = urls_and_sha256s_values[0] + template_inputs[f"{var_prefix}_sha256"] = urls_and_sha256s_values[1] + + return textwrap.dedent(""" + if(${{PYTHON_ABI_TAG}} STREQUAL "{abi}") + set(linux_x86_64_url "{linux_x86_64_url}") + set(linux_x86_64_sha256 "{linux_x86_64_sha256}") + + set(macosx_x86_64_url "{macosx_x86_64_url}") + set(macosx_x86_64_sha256 "{macosx_x86_64_sha256}") + + set(macosx_arm64_url "{macosx_arm64_url}") + set(macosx_arm64_sha256 "{macosx_arm64_sha256}") + + set(win_x86_64_url "{win_x86_64_url}") + set(win_x86_64_sha256 "{win_x86_64_sha256}") + endif() + """).format(**template_inputs) + + +def get_expected_shas() -> dict: + filename = f"vtk-wheel-sdk-{VTK_VERSION}-SHA-256.txt" + url = f"https://vtk.org/files/wheel-sdks/{filename}" + download_file(url, filename) + + shas = {} + with open(filename, "rb") as content: + for line in content.readlines(): + sha256 = line.split()[0].strip().decode() + file = line.split()[1].strip().decode() + shas[file] = sha256 + + return shas + + +def main(): + shas = get_expected_shas() + cmake_code = "" + for abi in ABI_TAGS: + archives = {} + for platform_name, platform_abi in PLATFORMS.items(): + filename = f"vtk-wheel-sdk-{VTK_VERSION}-{abi}-{platform_abi}.tar.xz" + # check availability + if filename not in shas: + archives[platform_name] = ("NOTFOUND", "NOTFOUND") + continue + + url = f"https://vtk.org/files/wheel-sdks/{filename}" + archives[platform_name] = (url, shas[filename]) + + cmake_code += generate_cmake_variables(archives, abi) + + with open(f"{__file__}/../cmake/vtk-sdk-urls.cmake", "wb") as file: + file.write(cmake_code.encode()) + + +if __name__ == "__main__": + main()