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/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\.]+).*\)$ +''' 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 new file mode 100644 index 0000000..5c918bb --- /dev/null +++ b/test/package/pip/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.25...3.29) +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) + +install(TARGETS main DESTINATION ${SKBUILD_SCRIPTS_DIR}) 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/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/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" 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