Skip to content

Commit 4d0f3a6

Browse files
committed
Add pytest-cmake CLI and remove deprecated CMake module integration docs
- Added pytest-cmake command-line tool with --cmake-dir to print the CMake config path, simplifying integration for virtualenvs, non-standard installs, and --user installs. - Updated documentation to recommend using the CLI instead of manually setting CMAKE_PREFIX_PATH. - Removed documentation for integrating the CMake module directly from the Git repository, as this unsustainable method was already discouraged. - Updated packaging configuration to include CLI entry point and adjust included files.
1 parent d978d74 commit 4d0f3a6

File tree

5 files changed

+56
-44
lines changed

5 files changed

+56
-44
lines changed

doc/integration.rst

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,12 @@ able to discover the newly installed configuration automatically using its
4242
<https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH.html>`_
4343
option should not be set to False.
4444

45-
When using a Python virtual environment, or if Python is installed in a
46-
non-standard location, the :envvar:`CMAKE_PREFIX_PATH` environment variable
47-
(or :term:`CMake` option) can be used to guide the discovery process::
45+
When using a Python virtual environment, installing Python in a non-standard location, or
46+
installing ``pytest-cmake`` in the `Python user directory
47+
<https://pip.pypa.io/en/stable/cli/pip_install/#install-user>`_, specify the ``Pytest_ROOT``
48+
path via the CLI::
4849

49-
cmake -S . -B ./build -D "CMAKE_PREFIX_PATH=/path/to/python/prefix"
50-
51-
This is also necessary when installing the configuration in the
52-
`Python user directory
53-
<https://pip.pypa.io/en/stable/cli/pip_install/#install-user>`_::
54-
55-
pip install pytest-cmake --user
50+
cmake -S . -B ./build -D "Pytest_ROOT=$(python -m pytest_cmake --cmake-dir)"
5651

5752
.. _integration/config/example:
5853

@@ -65,41 +60,10 @@ Ensure that :term:`nanobind` is available, and install :term:`Pytest` with its
6560
:term:`CMake` configuration as described in the :ref:`previous section <installing>`.
6661
Then build the example::
6762

68-
export nanobind_ROOT=$(python -m nanobind --cmake_dir)
69-
cmake -S ./example -B ./build
63+
cmake -S ./example -B ./build -D "nanobind_ROOT=$(python -m nanobind --cmake-dir)"
7064
cmake --build ./build
7165

7266
Finally, run the tests as follows::
7367

7468
ctest --test-dir ./build -VV
7569

76-
.. _integration/module:
77-
78-
Finding Module
79-
==============
80-
81-
The package integration within a :term:`CMake` project can also be done using
82-
the :file:`FindPytest.cmake` module. The CMake files can be copied into a
83-
new project, or the following code can be added before invoking the
84-
:term:`find_package` function:
85-
86-
.. code-block:: cmake
87-
88-
set(pytest_url https://github.com/python-cmake/pytest-cmake/archive/main.zip)
89-
90-
# Fetch CMake files from the main branch of the Github repository
91-
file(DOWNLOAD ${pytest_url} ${CMAKE_BINARY_DIR}/pytest.zip)
92-
file(
93-
ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/pytest.zip
94-
DESTINATION ${CMAKE_BINARY_DIR}
95-
PATTERNS "*.cmake"
96-
)
97-
98-
# Expand the module path variable to discover the `FindPytest.cmake` module.
99-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR}/pytest-cmake-main/cmake)
100-
101-
.. warning::
102-
103-
It is strongly recommended to use the :term:`Pip` installation over
104-
this method.
105-

doc/release/release_notes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
Release Notes
55
*************
66

7+
.. release:: Upcoming
8+
9+
.. change:: new
10+
11+
Added ``pytest-cmake`` CLI with ``--cmake-dir`` to print the
12+
:term:`CMake` config path, simplifying integration with virtualenvs,
13+
non-standard installs, or `--user
14+
<https://pip.pypa.io/en/stable/cli/pip_install/#install-user>`_ installs.
15+
16+
.. change:: changed
17+
18+
Removed documentation for integrating the :term:`CMake` module directly
19+
from the Git repository, as this unsustainable method was already
20+
discouraged.
21+
722
.. release:: 1.0.0
823
:date: 2025-08-13
924

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ classifiers = [
3333
"Programming Language :: Python :: 3.13",
3434
]
3535

36+
[project.scripts]
37+
pytest-cmake = "pytest_cmake.__main__:main"
38+
3639
[project.urls]
3740
Documentation = "https://python-cmake.github.io/pytest-cmake"
3841
Repository = "https://github.com/python-cmake/pytest-cmake"
@@ -50,7 +53,8 @@ path = "build_config.py"
5053
"cmake/PytestAddTests.cmake" = "share/Pytest/cmake/PytestAddTests.cmake"
5154

5255
[tool.hatch.build.targets.wheel]
53-
only-include = ["*.cmake"]
56+
packages = ["src/pytest_cmake"]
57+
only-include = ["src/pytest_cmake", "*.cmake"]
5458

5559
[tool.hatch.build.targets.sdist]
56-
only-include = ["cmake", "build_config.py"]
60+
only-include = ["src/pytest_cmake", "cmake", "build_config.py"]

src/pytest_cmake/__init__.py

Whitespace-only changes.

src/pytest_cmake/__main__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import argparse
2+
from pathlib import Path
3+
import sys
4+
import sysconfig
5+
6+
7+
def main(argv=None) -> int:
8+
parser = argparse.ArgumentParser(
9+
prog="pytest-cmake",
10+
description="Utility commands for pytest-cmake packaging.",
11+
)
12+
parser.add_argument(
13+
"--cmake_dir", "--cmake-dir",
14+
action="store_true",
15+
help="Print the CMake config directory path and exit.",
16+
)
17+
args = parser.parse_args(argv)
18+
19+
if args.cmake_dir:
20+
data_root = Path(sysconfig.get_path("data"))
21+
print(data_root / "share" / "Pytest" / "cmake")
22+
return 0
23+
24+
parser.print_help()
25+
return 0
26+
27+
28+
if __name__ == "__main__":
29+
sys.exit(main())

0 commit comments

Comments
 (0)