Skip to content

Commit 746b660

Browse files
author
Tim Ohliger
committed
Merge branch 'master' into stubgen-testing
2 parents c97609e + 8d503e3 commit 746b660

24 files changed

+4305
-4274
lines changed

.github/CONTRIBUTING.md

Lines changed: 42 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ the following rules to make the process as smooth as possible:
2525
* Make a new branch for every feature you're working on.
2626
* Make small and clean pull requests that are easy to review but make sure they
2727
do add value by themselves.
28-
* Add tests for any new functionality and run the test suite (`cmake --build
29-
build --target pytest`) to ensure that no existing features break.
28+
* Add tests for any new functionality and run the test suite (`cmake --workflow
29+
venv`) to ensure that no existing features break.
3030
* Please run [`pre-commit`][pre-commit] to check your code matches the
3131
project style. (Note that `gawk` is required.) Use `pre-commit run
3232
--all-files` before committing (or use installed-mode, check pre-commit docs)
@@ -84,8 +84,8 @@ To setup an ideal development environment, run the following commands on a
8484
system with CMake 3.15+:
8585

8686
```bash
87-
python3 -m venv venv
88-
source venv/bin/activate
87+
python3 -m venv .venv
88+
source .venv/bin/activate
8989
pip install -r tests/requirements.txt
9090
cmake -S . -B build -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON
9191
cmake --build build -j4
@@ -98,11 +98,42 @@ Tips:
9898
will be ignored by git.
9999
* If you don't have CMake 3.15+, just add "cmake" to the pip install command.
100100
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython.
101-
* In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
102-
FindPython uses `-DPython_ROOT_DIR=/path/to` or
101+
* For a specific Python, you can use `-DPython_ROOT_DIR=/path/to` or
103102
`-DPython_EXECUTABLE=/path/to/python`.
104103

105-
### Configuration options
104+
## CMake presets
105+
106+
We also support CMake presets. If you have [uv](https://docs.astral.sh/uv/),
107+
you can use:
108+
109+
```bash
110+
cmake --workflow venv
111+
```
112+
113+
to setup a venv and run all tests. You can break this up into components
114+
if you want to use a specific version of Python (or any other config option) or
115+
build only one of the valid targets (listed below).
116+
117+
```bash
118+
cmake --preset venv -DPYBIND11_CREATE_WITH_UV=3.13t
119+
cmake --build --preset venv
120+
cmake --build --preset venv -t cpptest
121+
```
122+
123+
The `default` preset will use an existing venv or Python install. If you'd like
124+
to run pytest yourself, say to easily control the options:
125+
126+
```bash
127+
cd build
128+
source .venv/bin/activate
129+
cd tests
130+
python -m pytest
131+
```
132+
133+
The `.so` file is not installed into the venv, so you need to run from this
134+
directory, the local directory is included with `python -m`.
135+
136+
## Configuration options
106137

107138
In CMake, configuration options are given with "-D". Options are stored in the
108139
build directory, in the `CMakeCache.txt` file, so they are remembered for each
@@ -299,85 +330,15 @@ files inside the package, that you get access to via functions in the package,
299330
and a `pybind11-global` package that can be included via `pybind11[global]` if
300331
you want the more invasive but discoverable file locations.
301332

302-
If you want to install or package the GitHub source, it is best to have Pip 10
303-
or newer on Windows, macOS, or Linux (manylinux1 compatible, includes most
304-
distributions). You can then build the SDists, or run any procedure that makes
305-
SDists internally, like making wheels or installing.
306-
307-
308-
```bash
309-
# Editable development install example
310-
python3 -m pip install -e .
311-
```
312-
313-
Since Pip itself does not have an `sdist` command (it does have `wheel` and
314-
`install`), you may want to use the upcoming `build` package:
315-
316-
```bash
317-
python3 -m pip install build
318-
319-
# Normal package
320-
python3 -m build -s .
321-
322-
# Global extra
323-
PYBIND11_GLOBAL_SDIST=1 python3 -m build -s .
324-
```
333+
If you want to package the GitHub source for the "global" package, you need
334+
to use nox. Normal packaging will only make the normal package.
325335

326-
If you want to use the classic "direct" usage of `python setup.py`, you will
327-
need CMake 3.15+ and either `make` or `ninja` preinstalled (possibly via `pip
328-
install cmake ninja`), since directly running Python on `setup.py` cannot pick
329-
up and install `pyproject.toml` requirements. As long as you have those two
330-
things, though, everything works the way you would expect:
331336

332337
```bash
333-
# Normal package
334-
python3 setup.py sdist
335-
336-
# Global extra
337-
PYBIND11_GLOBAL_SDIST=1 python3 setup.py sdist
338+
nox -s build
339+
nox -s build_global
338340
```
339341

340-
A detailed explanation of the build procedure design for developers wanting to
341-
work on or maintain the packaging system is as follows:
342-
343-
#### 1. Building from the source directory
344-
345-
When you invoke any `setup.py` command from the source directory, including
346-
`pip wheel .` and `pip install .`, you will activate a full source build. This
347-
is made of the following steps:
348-
349-
1. If the tool is PEP 518 compliant, like Pip 10+, it will create a temporary
350-
virtual environment and install the build requirements (mostly CMake) into
351-
it. (if you are not on Windows, macOS, or a manylinux compliant system, you
352-
can disable this with `--no-build-isolation` as long as you have CMake 3.15+
353-
installed)
354-
2. The environment variable `PYBIND11_GLOBAL_SDIST` is checked - if it is set
355-
and truthy, this will be make the accessory `pybind11-global` package,
356-
instead of the normal `pybind11` package. This package is used for
357-
installing the files directly to your environment root directory, using
358-
`pybind11[global]`.
359-
2. `setup.py` reads the version from `pybind11/_version.py` and verifies it
360-
matches `includes/pybind11/detail/common.h`.
361-
3. CMake is run with `-DCMAKE_INSTALL_PREIFX=pybind11`. Since the CMake install
362-
procedure uses only relative paths and is identical on all platforms, these
363-
files are valid as long as they stay in the correct relative position to the
364-
includes. `pybind11/share/cmake/pybind11` has the CMake files, and
365-
`pybind11/include` has the includes. The build directory is discarded.
366-
4. Simpler files are placed in the SDist: `tools/setup_*.py.in`,
367-
`tools/pyproject.toml` (`main` or `global`)
368-
5. The package is created by running the setup function in the
369-
`tools/setup_*.py`. `setup_main.py` fills in Python packages, and
370-
`setup_global.py` fills in only the data/header slots.
371-
6. A context manager cleans up the temporary CMake install directory (even if
372-
an error is thrown).
373-
374-
### 2. Building from SDist
375-
376-
Since the SDist has the rendered template files in `tools` along with the
377-
includes and CMake files in the correct locations, the builds are completely
378-
trivial and simple. No extra requirements are required. You can even use Pip 9
379-
if you really want to.
380-
381342

382343
[pre-commit]: https://pre-commit.com
383344
[clang-format]: https://clang.llvm.org/docs/ClangFormat.html

.github/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ docs:
22
all:
33
- changed-files:
44
- all-globs-to-all-files:
5-
- '!docs/changelog.rst'
5+
- '!docs/changelog.md'
66
- '!docs/upgrade.rst'
77
- base-branch: "^(?!dependabot).*"
88
- base-branch: "^(?!pre-commit-ci).*"

.github/labeler_merged.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
needs changelog:
44
- all:
55
- changed-files:
6-
- all-globs-to-all-files: "!docs/changelog.rst"
6+
- all-globs-to-all-files: "!docs/changelog.md"
77
- base-branch: "^(?!dependabot).*"
88
- base-branch: "^(?!pre-commit-ci).*"

.github/pull_request_template.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ It is recommended to use conventional commit format, see conventionalcommits.org
99

1010
## Suggested changelog entry:
1111

12-
<!-- Fill in the below block with the expected RestructuredText entry. Delete if no entry needed;
13-
but do not delete header or rst block if an entry is needed! Will be collected via a script. -->
12+
<!-- Fill in the block below with the expected entry. Delete if no entry needed;
13+
but do not delete the header if an entry is needed! Will be collected via a script. -->
1414

15-
```rst
16-
17-
```
18-
19-
<!-- If the upgrade guide needs updating, note that here too -->
15+
* Placeholder.

.github/workflows/format.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ jobs:
5555
5656
- name: Build
5757
run: cmake --build build -j 2 -- --keep-going
58+
59+
- name: Embedded
60+
run: cmake --build build -t cpptest -j 2 -- --keep-going

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ if(PYBIND11_MASTER_PROJECT)
179179
endif()
180180
endif()
181181

182-
# NB: when adding a header don't forget to also add it to setup.py
183182
set(PYBIND11_HEADERS
184183
include/pybind11/detail/class.h
185184
include/pybind11/detail/common.h
@@ -223,6 +222,7 @@ set(PYBIND11_HEADERS
223222
include/pybind11/operators.h
224223
include/pybind11/pybind11.h
225224
include/pybind11/pytypes.h
225+
include/pybind11/subinterpreter.h
226226
include/pybind11/stl.h
227227
include/pybind11/stl_bind.h
228228
include/pybind11/stl/filesystem.h

0 commit comments

Comments
 (0)