From 1e1f4e71cc20cd0507ebd6f89e8d63dabcf33a62 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 2 Sep 2024 16:30:08 +0200 Subject: [PATCH 1/3] Create a proper python package with scikit-build-core Signed-off-by: Cristian Le --- pyproject.toml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6f10f94..22ae399 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,13 @@ [build-system] -requires = ["setuptools"] -build-backend = "setuptools.build_meta" +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" [project] -name = "CMake-Template-dev" -version = "0.0.0" +name = "CMake-Template" description = "Development environment for CMake Template" readme = "README.md" license = { file = "LICENSE" } - +dynamic = ["version"] [project.optional-dependencies] docs = [ @@ -22,9 +21,17 @@ docs = [ "sphinx-copybutton", "sphinx-prompt", ] -dev = [ - "pre-commit", -] -[tool.setuptools] -packages = [] +[project.entry-points."cmake.prefix"] +CMakeTemplatePrefix = "cmake_template" + +[tool.scikit-build] +wheel.install-dir = "cmake_template" + +[tool.scikit-build.metadata.version] +provider = "scikit_build_core.metadata.regex" +# Get the project version from the CMakeLists's project() +input = "CMakeLists.txt" +regex = '''(?sm) +^project\s*\(\s*Template\s+.*VERSION\s+(?P[\d\.]+).*\)$ +''' From 3db8a979f1157fb3bd152105d39341ee5e967b02 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 2 Sep 2024 17:52:45 +0200 Subject: [PATCH 2/3] Add pip packaging test Signed-off-by: Cristian Le --- test/package/pip/CMakeLists.txt | 21 +++++++++++++++++++++ test/package/pip/main.cpp | 1 + test/package/pip/pyproject.toml | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 test/package/pip/CMakeLists.txt create mode 120000 test/package/pip/main.cpp create mode 100644 test/package/pip/pyproject.toml diff --git a/test/package/pip/CMakeLists.txt b/test/package/pip/CMakeLists.txt new file mode 100644 index 0000000..877beb3 --- /dev/null +++ b/test/package/pip/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(example_spglib LANGUAGES CXX) + +find_package(Template REQUIRED CONFIG) + +add_executable(main main.cpp) +target_link_libraries(main PRIVATE Template::Template) + +enable_testing() +add_test(NAME smoke_test + COMMAND $ +) +set_tests_properties(smoke_test PROPERTIES + PASS_REGULAR_EXPRESSION "^Hello, World!" +) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) + # https://stackoverflow.com/a/77990416 + set_property(TEST smoke_test APPEND PROPERTY + ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$,\;>" + ) +endif () diff --git a/test/package/pip/main.cpp b/test/package/pip/main.cpp new file mode 120000 index 0000000..cb9fa3f --- /dev/null +++ b/test/package/pip/main.cpp @@ -0,0 +1 @@ +../main.cpp \ No newline at end of file diff --git a/test/package/pip/pyproject.toml b/test/package/pip/pyproject.toml new file mode 100644 index 0000000..da4f2b4 --- /dev/null +++ b/test/package/pip/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["scikit-build-core", "CMake-Template"] +build-backend = "scikit_build_core.build" + +[project] +name = "example-template" +version = "0.0.0" From 7039d0cd5e627bfaea58dd913c70afcd8af590a7 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 3 Sep 2024 17:32:37 +0200 Subject: [PATCH 3/3] Run the pip packaging tests in tmt Signed-off-by: Cristian Le --- .distro/plans/python.fmf | 21 +++++++++++++++++++++ test/ctest.fmf | 3 +-- test/main.fmf | 2 ++ test/package/pip/CMakeLists.txt | 17 ++++------------- test/package/pip/main.fmf | 2 ++ test/package/pip/test.sh | 26 ++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 .distro/plans/python.fmf create mode 100644 test/main.fmf create mode 100644 test/package/pip/main.fmf create mode 100755 test/package/pip/test.sh diff --git a/.distro/plans/python.fmf b/.distro/plans/python.fmf new file mode 100644 index 0000000..54efc4b --- /dev/null +++ b/.distro/plans/python.fmf @@ -0,0 +1,21 @@ +summary: Test python integration + +prepare: + - how: install + package: + - python3dist(pip) + - gcc-c++ + - cmake + - ninja-build + # Defining all python dependencies manually here + - python3dist(scikit-build-core) + - how: shell + script: | + python3 -m venv --system-site-packages $TMT_PLAN_DATA/venv + +discover+: + how: fmf + path: . + filter: "tag:python" +execute: + how: tmt diff --git a/test/ctest.fmf b/test/ctest.fmf index f3b5ff2..04c1786 100644 --- a/test/ctest.fmf +++ b/test/ctest.fmf @@ -1,3 +1,2 @@ +summary: Run the bundled ctests tag: [ cmake ] -framework: beakerlib -test: ./test.sh diff --git a/test/main.fmf b/test/main.fmf new file mode 100644 index 0000000..c894190 --- /dev/null +++ b/test/main.fmf @@ -0,0 +1,2 @@ +framework: beakerlib +test: ./test.sh diff --git a/test/package/pip/CMakeLists.txt b/test/package/pip/CMakeLists.txt index 877beb3..5c918bb 100644 --- a/test/package/pip/CMakeLists.txt +++ b/test/package/pip/CMakeLists.txt @@ -3,19 +3,10 @@ project(example_spglib LANGUAGES CXX) find_package(Template REQUIRED CONFIG) +# Make sure the executable is runnable after the pip install +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True) + add_executable(main main.cpp) target_link_libraries(main PRIVATE Template::Template) -enable_testing() -add_test(NAME smoke_test - COMMAND $ -) -set_tests_properties(smoke_test PROPERTIES - PASS_REGULAR_EXPRESSION "^Hello, World!" -) -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) - # https://stackoverflow.com/a/77990416 - set_property(TEST smoke_test APPEND PROPERTY - ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$,\;>" - ) -endif () +install(TARGETS main DESTINATION ${SKBUILD_SCRIPTS_DIR}) diff --git a/test/package/pip/main.fmf b/test/package/pip/main.fmf new file mode 100644 index 0000000..aee4ba7 --- /dev/null +++ b/test/package/pip/main.fmf @@ -0,0 +1,2 @@ +summary: Test the python installation +tag: [ python ] diff --git a/test/package/pip/test.sh b/test/package/pip/test.sh new file mode 100755 index 0000000..5eae419 --- /dev/null +++ b/test/package/pip/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# shellcheck disable=all +source /usr/share/beakerlib/beakerlib.sh || exit 1 + +rlJournalStart + rlPhaseStartSetup + rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" + rlRun "source \$TMT_PLAN_DATA/venv/bin/activate" 0 "Source the plan's virtual environment" + # Secondary venv inheriting from the main virtual environment + # keeps the plan's vnev clean + rlRun "python3 -m venv --system-site-packages \$tmp/venv" 0 "Create the test's virtual environment" + rlRun "deactivate && source \$tmp/venv/bin/activate" 0 "Source the test's virtual environment" + rlRun "set -o pipefail" + rlPhaseEnd + + rlPhaseStartTest + rlRun "pip install -v --no-build-isolation ." 0 "Install the test package" + rlRun -s "main" 0 "Run the test executable" + rlAssertGrep "Hello, World!" $rlRun_LOG + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm -r $tmp" 0 "Remove tmp directory" + rlPhaseEnd +rlJournalEnd