Skip to content

Commit 24fc897

Browse files
authored
Merge pull request #177 from ProfFan/fan/update_pybind11
Update pybind11 to 3.0.1
2 parents 6608770 + 580f53a commit 24fc897

File tree

257 files changed

+21328
-6844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+21328
-6844
lines changed

pybind11/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Checks: |
6363
-bugprone-reserved-identifier,
6464
-bugprone-unused-raii,
6565
-performance-enum-size,
66+
-performance-inefficient-string-concatenation,
6667
6768
CheckOptions:
6869
- key: modernize-use-equals-default.IgnoreMacros

pybind11/.codespell-ignore-lines

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ template <op_id id, op_type ot, typename L, typename R>
1212
template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra>
1313
class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
1414
class_ &def_cast(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
15+
int valu;
16+
explicit movable_int(int v) : valu{v} {}
17+
movable_int(movable_int &&other) noexcept : valu(other.valu) { other.valu = 91; }
18+
explicit indestructible_int(int v) : valu{v} {}
19+
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);
20+
REQUIRE(othr.valu == 19);
21+
REQUIRE(orig.valu == 91);
22+
(m.pass_valu, "Valu", "pass_valu:Valu(_MvCtor)*_CpCtor"),
23+
atyp_valu rtrn_valu() { atyp_valu obj{"Valu"}; return obj; }
24+
assert m.atyp_valu().get_mtxt() == "Valu"
25+
// valu(e), ref(erence), ptr or p (pointer), r = rvalue, m = mutable, c = const,
1526
@pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"])
1627
struct IntStruct {
1728
explicit IntStruct(int v) : value(v){};

pybind11/.github/CONTRIBUTING.md

Lines changed: 55 additions & 94 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)
@@ -81,11 +81,11 @@ nox -s build
8181
### Full setup
8282

8383
To setup an ideal development environment, run the following commands on a
84-
system with CMake 3.14+:
84+
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
@@ -96,13 +96,44 @@ Tips:
9696
* You can use `virtualenv` (faster, from PyPI) instead of `venv`.
9797
* You can select any name for your environment folder; if it contains "env" it
9898
will be ignored by git.
99-
* If you don't have CMake 3.14+, just add "cmake" to the pip install command.
100-
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython on CMake 3.12+
101-
* In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
102-
FindPython uses `-DPython_ROOT_DIR=/path/to` or
99+
* If you don't have CMake 3.15+, just add "cmake" to the pip install command.
100+
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython.
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
@@ -149,8 +180,8 @@ To run the tests, you can "build" the check target:
149180
cmake --build build --target check
150181
```
151182

152-
`--target` can be spelled `-t` in CMake 3.15+. You can also run individual
153-
tests with these targets:
183+
`--target` can be spelled `-t`. You can also run individual tests with these
184+
targets:
154185

155186
* `pytest`: Python tests only, using the
156187
[pytest](https://docs.pytest.org/en/stable/) framework
@@ -231,17 +262,17 @@ of the pybind11 repo.
231262
more complex to run, compared to `clang-format`, but support for `clang-tidy`
232263
is built into the pybind11 CMake configuration. To run `clang-tidy`, the
233264
following recipe should work. Run the `docker` command from the top-level
234-
directory inside your pybind11 git clone. Files will be modified in place,
235-
so you can use git to monitor the changes.
265+
directory inside your pybind11 git clone.
236266

237267
```bash
238-
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
239-
apt-get update && apt-get install -y git python3-dev python3-pytest
240-
cmake -S /mounted_pybind11/ -B build -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color" -DDOWNLOAD_EIGEN=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=17
241-
cmake --build build -j 2
268+
docker run --rm -v $PWD:/pybind11 -w /pybind11 -it silkeh/clang:20
269+
apt-get update && apt-get install -y git python3-dev python3-pytest ninja-build
270+
cmake --preset tidy
271+
cmake --build --preset tidy
242272
```
243273

244-
You can add `--fix` to the options list if you want.
274+
You can add `--fix` to the options list in the preset if you want to apply fixes
275+
(remember `-j1` to run only one thread).
245276

246277
### Include what you use
247278

@@ -250,7 +281,7 @@ macOS), then run:
250281

251282
```bash
252283
cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=$(which include-what-you-use)
253-
cmake --build build
284+
cmake --build build-iwyu
254285
```
255286

256287
The report is sent to stderr; you can pipe it into a file if you wish.
@@ -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

pybind11/.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).*"

pybind11/.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).*"

pybind11/.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.

0 commit comments

Comments
 (0)