Skip to content

Commit a38cb40

Browse files
committed
Fix Pytest config-mode version handling
Keep PytestConfigVersion.cmake for config-mode checks without hard-coding a build-time pytest version. Version discovery remains dynamic via FindPytest.cmake. PytestConfig.cmake stays a thin entry point. Wheel distribution is supported.
1 parent b561222 commit a38cb40

File tree

7 files changed

+34
-32
lines changed

7 files changed

+34
-32
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
run: |
6464
cmake -S ./test -B ./test/build
6565
cmake --build ./test/build
66+
ctest --test-dir ./test/build -VV -C Release
6667
6768
- name: Configure Example
6869
shell: bash

build_config.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
22

33
import pathlib
4-
import subprocess
54

65

76
class BuildConfig(BuildHookInterface):
87
"""Builder to create and share pytest config."""
98

109
def initialize(self, version, build_data):
1110
"""Execute builder."""
12-
import pytest
1311

1412
root = pathlib.Path(__file__).parent.resolve()
1513
build_path = (root / "build")
@@ -25,18 +23,10 @@ def initialize(self, version, build_data):
2523
"include(${CMAKE_CURRENT_LIST_DIR}/FindPytest.cmake)\n"
2624
)
2725

28-
# Generate CMake config version file for client to target a specific
29-
# version of Pytest within CMake projects.
30-
version_config_path = (build_path / "PytestConfigVersion.cmake")
31-
script_path = (build_path / "PytestConfigVersionScript.cmake")
32-
with script_path.open("w", encoding="utf-8") as stream:
26+
# Always accept; actual version checks are handled by FindPytest.cmake
27+
config_path = (build_path / "PytestConfigVersion.cmake")
28+
with config_path.open("w", encoding="utf-8") as stream:
3329
stream.write(
34-
"include(CMakePackageConfigHelpers)\n"
35-
"write_basic_package_version_file(\n"
36-
f" \"{str(version_config_path.as_posix())}\"\n"
37-
f" VERSION {pytest.__version__}\n"
38-
" COMPATIBILITY AnyNewerVersion\n"
39-
")"
30+
"set(PACKAGE_VERSION_COMPATIBLE TRUE)\n"
31+
"set(PACKAGE_VERSION_EXACT TRUE)\n"
4032
)
41-
42-
subprocess.call(["cmake", "-P", str(script_path), "-VV"])

doc/installing.rst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,3 @@ View the result in your browser at::
6161

6262
file:///path/to/sphinx-build/build/doc/html/index.html
6363

64-
.. _installing/deployment:
65-
66-
Package Deployment
67-
==================
68-
69-
This package is deployed as a source on `PyPi <https://pypi.org/project/pytest-cmake/>`_
70-
to allow dynamic adaptation of :term:`CMake` scripts based on the version of :term:`Pytest`
71-
available at installation. Packaging it as a
72-
`wheel <https://packaging.python.org/en/latest/specifications/binary-distribution-format>`_
73-
would lock the :term:`Pytest` version detected during the packaging and deployment process,
74-
reducing flexibility and compatibility with future versions.
75-
76-
If you wish to deploy the package as a source within a custom index, it is important to include
77-
the build requirements in your environment (e.g. "hatchling" and "cmake").
78-
79-
.. seealso:: `Package Formats <https://packaging.python.org/en/latest/discussions/package-formats>`_

doc/release/release_notes.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
Release Notes
55
*************
66

7+
.. release:: Upcoming
8+
9+
.. change:: changed
10+
11+
Updated :term:`CMake` packaging by simplifying
12+
`PytestConfigVersion.cmake` so that version compatibility is no longer
13+
fixed at build time. Version discovery and validation are handled
14+
dynamically by `FindPytest.cmake`, with `PytestConfig.cmake` serving
15+
only as a thin entry point for :term:`CMake` package discovery.
16+
Wheel distribution is fully supported and recommended.
17+
Thanks :github_user:`dimbleby`!
18+
719
.. release:: 1.2.0
820
:date: 2025-12-08
921

@@ -165,7 +177,7 @@ Release Notes
165177

166178
.. change:: changed
167179

168-
Added documentation for :ref:`installing/deployment`.
180+
Added documentation for deployment.
169181

170182
.. change:: changed
171183

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ classifiers = [
3131
"Programming Language :: Python :: 3.11",
3232
"Programming Language :: Python :: 3.12",
3333
"Programming Language :: Python :: 3.13",
34+
"Programming Language :: Python :: 3.14",
3435
]
3536

3637
[project.scripts]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(TestVersionFails)
4+
5+
find_package(Pytest 99.0 REQUIRED)

test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ cmake_minimum_required(VERSION 3.20)
22

33
project(Test)
44

5+
enable_testing()
56
include(ExternalProject)
67

8+
add_test(
9+
NAME TestVersionFails
10+
COMMAND ${CMAKE_COMMAND}
11+
-S ${CMAKE_CURRENT_SOURCE_DIR}/tests/00-version-fails
12+
-B ${CMAKE_BINARY_DIR}/_deps/00-version-fails
13+
)
14+
set_tests_properties(TestVersionFails PROPERTIES WILL_FAIL TRUE)
15+
716
ExternalProject_Add(
817
TestModifyName
918
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/01-modify-name

0 commit comments

Comments
 (0)