Skip to content

Commit bfe5ffd

Browse files
committed
update pybind11
2 parents 8a31e90 + 0db5119 commit bfe5ffd

File tree

249 files changed

+31677
-11119
lines changed

Some content is hidden

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

249 files changed

+31677
-11119
lines changed

examples/knxPython/pybind11/.appveyor.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 1.0.{build}
22
image:
3-
- Visual Studio 2015
3+
- Visual Studio 2017
44
test: off
55
skip_branch_with_pr: true
66
build:
@@ -9,17 +9,15 @@ platform:
99
- x86
1010
environment:
1111
matrix:
12-
- PYTHON: 36
13-
CONFIG: Debug
14-
- PYTHON: 27
12+
- PYTHON: 38
1513
CONFIG: Debug
1614
install:
1715
- ps: |
18-
$env:CMAKE_GENERATOR = "Visual Studio 14 2015"
16+
$env:CMAKE_GENERATOR = "Visual Studio 15 2017"
1917
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
2018
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
2119
python -W ignore -m pip install --upgrade pip wheel
22-
python -W ignore -m pip install pytest numpy --no-warn-script-location
20+
python -W ignore -m pip install pytest numpy --no-warn-script-location pytest-timeout
2321
- ps: |
2422
Start-FileDownload 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip'
2523
7z x eigen-3.3.7.zip -y > $null
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# See all possible options and defaults with:
3+
# clang-format --style=llvm --dump-config
4+
BasedOnStyle: LLVM
5+
AccessModifierOffset: -4
6+
AllowShortLambdasOnASingleLine: true
7+
AlwaysBreakTemplateDeclarations: Yes
8+
BinPackArguments: false
9+
BinPackParameters: false
10+
BreakBeforeBinaryOperators: All
11+
BreakConstructorInitializers: BeforeColon
12+
ColumnLimit: 99
13+
CommentPragmas: 'NOLINT:.*|^ IWYU pragma:'
14+
IncludeBlocks: Regroup
15+
IndentCaseLabels: true
16+
IndentPPDirectives: AfterHash
17+
IndentWidth: 4
18+
Language: Cpp
19+
SpaceAfterCStyleCast: true
20+
Standard: Cpp11
21+
StatementMacros: ['PyObject_HEAD']
22+
TabWidth: 4
23+
IncludeCategories:
24+
- Regex: '<pybind11/.*'
25+
Priority: -1
26+
- Regex: 'pybind11.h"$'
27+
Priority: 1
28+
- Regex: '^".*/?detail/'
29+
Priority: 1
30+
SortPriority: 2
31+
- Regex: '^"'
32+
Priority: 1
33+
SortPriority: 3
34+
- Regex: '<[[:alnum:]._]+>'
35+
Priority: 4
36+
- Regex: '.*'
37+
Priority: 5
38+
...
+73-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,77 @@
11
FormatStyle: file
22

3-
Checks: '
4-
llvm-namespace-comment,
5-
modernize-use-override,
6-
readability-container-size-empty,
7-
modernize-use-using,
8-
modernize-use-equals-default,
9-
modernize-use-auto,
10-
modernize-use-emplace,
11-
'
3+
Checks: |
4+
*bugprone*,
5+
*performance*,
6+
clang-analyzer-optin.cplusplus.VirtualCall,
7+
clang-analyzer-optin.performance.Padding,
8+
cppcoreguidelines-init-variables,
9+
cppcoreguidelines-prefer-member-initializer,
10+
cppcoreguidelines-pro-type-static-cast-downcast,
11+
cppcoreguidelines-slicing,
12+
google-explicit-constructor,
13+
llvm-namespace-comment,
14+
misc-definitions-in-headers,
15+
misc-misplaced-const,
16+
misc-non-copyable-objects,
17+
misc-static-assert,
18+
misc-throw-by-value-catch-by-reference,
19+
misc-uniqueptr-reset-release,
20+
misc-unused-parameters,
21+
modernize-avoid-bind,
22+
modernize-loop-convert,
23+
modernize-make-shared,
24+
modernize-redundant-void-arg,
25+
modernize-replace-auto-ptr,
26+
modernize-replace-disallow-copy-and-assign-macro,
27+
modernize-replace-random-shuffle,
28+
modernize-shrink-to-fit,
29+
modernize-use-auto,
30+
modernize-use-bool-literals,
31+
modernize-use-default-member-init,
32+
modernize-use-emplace,
33+
modernize-use-equals-default,
34+
modernize-use-equals-delete,
35+
modernize-use-noexcept,
36+
modernize-use-nullptr,
37+
modernize-use-override,
38+
modernize-use-using,
39+
readability-avoid-const-params-in-decls,
40+
readability-braces-around-statements,
41+
readability-const-return-type,
42+
readability-container-size-empty,
43+
readability-delete-null-pointer,
44+
readability-else-after-return,
45+
readability-implicit-bool-conversion,
46+
readability-inconsistent-declaration-parameter-name,
47+
readability-make-member-function-const,
48+
readability-misplaced-array-index,
49+
readability-non-const-parameter,
50+
readability-qualified-auto,
51+
readability-redundant-function-ptr-dereference,
52+
readability-redundant-smartptr-get,
53+
readability-redundant-string-cstr,
54+
readability-simplify-subscript-expr,
55+
readability-static-accessed-through-instance,
56+
readability-static-definition-in-anonymous-namespace,
57+
readability-string-compare,
58+
readability-suspicious-call-argument,
59+
readability-uniqueptr-delete-release,
60+
-bugprone-easily-swappable-parameters,
61+
-bugprone-exception-escape,
62+
-bugprone-reserved-identifier,
63+
-bugprone-unused-raii,
64+
65+
CheckOptions:
66+
- key: modernize-use-equals-default.IgnoreMacros
67+
value: false
68+
- key: performance-for-range-copy.WarnOnAllAutoCopies
69+
value: true
70+
- key: performance-inefficient-string-concatenation.StrictMode
71+
value: true
72+
- key: performance-unnecessary-value-param.AllowedTypes
73+
value: 'exception_ptr$;'
74+
- key: readability-implicit-bool-conversion.AllowPointerConditions
75+
value: true
1276

1377
HeaderFilterRegex: 'pybind11/.*h'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t>
2+
template <typename ThisT>
3+
auto &this_ = static_cast<ThisT &>(*this);
4+
if (load_impl<ThisT>(temp, false)) {
5+
ssize_t nd = 0;
6+
auto trivial = broadcast(buffers, nd, shape);
7+
auto ndim = (size_t) nd;
8+
int nd;
9+
ssize_t ndim() const { return detail::array_proxy(m_ptr)->nd; }
10+
using op = op_impl<id, ot, Base, L_type, R_type>;
11+
template <op_id id, op_type ot, typename L, typename R>
12+
template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra>
13+
class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
14+
class_ &def_cast(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
15+
@pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"])
16+
struct IntStruct {
17+
explicit IntStruct(int v) : value(v){};
18+
~IntStruct() { value = -value; }
19+
IntStruct(const IntStruct &) = default;
20+
IntStruct &operator=(const IntStruct &) = default;
21+
py::class_<IntStruct>(m, "IntStruct").def(py::init([](const int i) { return IntStruct(i); }));
22+
py::implicitly_convertible<int, IntStruct>();
23+
m.def("test", [](int expected, const IntStruct &in) {
24+
[](int expected, const IntStruct &in) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/*.svg binary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.cmake @henryiii
2+
CMakeLists.txt @henryiii
3+
*.yml @henryiii
4+
*.yaml @henryiii
5+
/tools/ @henryiii
6+
/pybind11/ @henryiii
7+
noxfile.py @henryiii
8+
.clang-format @henryiii
9+
.clang-tidy @henryiii

examples/knxPython/pybind11/.github/CONTRIBUTING.md

+87-18
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ derivative works thereof, in binary and source code form.
5353

5454
## Development of pybind11
5555

56+
### Quick setup
57+
58+
To setup a quick development environment, use [`nox`](https://nox.thea.codes).
59+
This will allow you to do some common tasks with minimal setup effort, but will
60+
take more time to run and be less flexible than a full development environment.
61+
If you use [`pipx run nox`](https://pipx.pypa.io), you don't even need to
62+
install `nox`. Examples:
63+
64+
```bash
65+
# List all available sessions
66+
nox -l
67+
68+
# Run linters
69+
nox -s lint
70+
71+
# Run tests on Python 3.9
72+
nox -s tests-3.9
73+
74+
# Build and preview docs
75+
nox -s docs -- serve
76+
77+
# Build SDists and wheels
78+
nox -s build
79+
```
80+
81+
### Full setup
82+
5683
To setup an ideal development environment, run the following commands on a
5784
system with CMake 3.14+:
5885

@@ -66,19 +93,18 @@ cmake --build build -j4
6693

6794
Tips:
6895

69-
* You can use `virtualenv` (from PyPI) instead of `venv` (which is Python 3
70-
only).
96+
* You can use `virtualenv` (faster, from PyPI) instead of `venv`.
7197
* You can select any name for your environment folder; if it contains "env" it
7298
will be ignored by git.
73-
* If you dont have CMake 3.14+, just add cmake to the pip install command.
99+
* If you don't have CMake 3.14+, just add "cmake" to the pip install command.
74100
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython on CMake 3.12+
75101
* In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
76102
FindPython uses `-DPython_ROOT_DIR=/path/to` or
77103
`-DPython_EXECUTABLE=/path/to/python`.
78104

79105
### Configuration options
80106

81-
In CMake, configuration options are given with “-D”. Options are stored in the
107+
In CMake, configuration options are given with "-D". Options are stored in the
82108
build directory, in the `CMakeCache.txt` file, so they are remembered for each
83109
build directory. Two selections are special - the generator, given with `-G`,
84110
and the compiler, which is selected based on environment variables `CXX` and
@@ -88,12 +114,12 @@ after the initial run.
88114
The valid options are:
89115

90116
* `-DCMAKE_BUILD_TYPE`: Release, Debug, MinSizeRel, RelWithDebInfo
91-
* `-DPYBIND11_FINDPYTHON=ON`: Use CMake 3.12+s FindPython instead of the
117+
* `-DPYBIND11_FINDPYTHON=ON`: Use CMake 3.12+'s FindPython instead of the
92118
classic, deprecated, custom FindPythonLibs
93119
* `-DPYBIND11_NOPYTHON=ON`: Disable all Python searching (disables tests)
94120
* `-DBUILD_TESTING=ON`: Enable the tests
95121
* `-DDOWNLOAD_CATCH=ON`: Download catch to build the C++ tests
96-
* `-DOWNLOAD_EIGEN=ON`: Download Eigen for the NumPy tests
122+
* `-DDOWNLOAD_EIGEN=ON`: Download Eigen for the NumPy tests
97123
* `-DPYBIND11_INSTALL=ON/OFF`: Enable the install target (on by default for the
98124
master project)
99125
* `-DUSE_PYTHON_INSTALL_DIR=ON`: Try to install into the python dir
@@ -109,7 +135,7 @@ The valid options are:
109135
* Use `-G` and the name of a generator to use something different. `cmake
110136
--help` lists the generators available.
111137
- On Unix, setting `CMAKE_GENERATER=Ninja` in your environment will give
112-
you automatic mulithreading on all your CMake projects!
138+
you automatic multithreading on all your CMake projects!
113139
* Open the `CMakeLists.txt` with QtCreator to generate for that IDE.
114140
* You can use `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to generate the `.json` file
115141
that some tools expect.
@@ -126,13 +152,26 @@ cmake --build build --target check
126152
`--target` can be spelled `-t` in CMake 3.15+. You can also run individual
127153
tests with these targets:
128154

129-
* `pytest`: Python tests only
155+
* `pytest`: Python tests only, using the
156+
[pytest](https://docs.pytest.org/en/stable/) framework
130157
* `cpptest`: C++ tests only
131158
* `test_cmake_build`: Install / subdirectory tests
132159

133160
If you want to build just a subset of tests, use
134-
`-DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp"`. If this is
135-
empty, all tests will be built.
161+
`-DPYBIND11_TEST_OVERRIDE="test_callbacks;test_pickling"`. If this is
162+
empty, all tests will be built. Tests are specified without an extension if they need both a .py and
163+
.cpp file.
164+
165+
You may also pass flags to the `pytest` target by editing `tests/pytest.ini` or
166+
by using the `PYTEST_ADDOPTS` environment variable
167+
(see [`pytest` docs](https://docs.pytest.org/en/2.7.3/customize.html#adding-default-options)). As an example:
168+
169+
```bash
170+
env PYTEST_ADDOPTS="--capture=no --exitfirst" \
171+
cmake --build build --target pytest
172+
# Or using abbreviated flags
173+
env PYTEST_ADDOPTS="-s -x" cmake --build build --target pytest
174+
```
136175

137176
### Formatting
138177

@@ -164,18 +203,46 @@ name, pre-commit):
164203
pre-commit install
165204
```
166205

206+
### Clang-Format
207+
208+
As of v2.6.2, pybind11 ships with a [`clang-format`][clang-format]
209+
configuration file at the top level of the repo (the filename is
210+
`.clang-format`). Currently, formatting is NOT applied automatically, but
211+
manually using `clang-format` for newly developed files is highly encouraged.
212+
To check if a file needs formatting:
213+
214+
```bash
215+
clang-format -style=file --dry-run some.cpp
216+
```
217+
218+
The output will show things to be fixed, if any. To actually format the file:
219+
220+
```bash
221+
clang-format -style=file -i some.cpp
222+
```
223+
224+
Note that the `-style-file` option searches the parent directories for the
225+
`.clang-format` file, i.e. the commands above can be run in any subdirectory
226+
of the pybind11 repo.
227+
167228
### Clang-Tidy
168229

169-
To run Clang tidy, the following recipe should work. Files will be modified in
170-
place, so you can use git to monitor the changes.
230+
[`clang-tidy`][clang-tidy] performs deeper static code analyses and is
231+
more complex to run, compared to `clang-format`, but support for `clang-tidy`
232+
is built into the pybind11 CMake configuration. To run `clang-tidy`, the
233+
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.
171236

172237
```bash
173-
docker run --rm -v $PWD:/pybind11 -it silkeh/clang:10
174-
apt-get update && apt-get install python3-dev python3-pytest
175-
cmake -S pybind11/ -B build -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);-fix"
176-
cmake --build build
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
177242
```
178243

244+
You can add `--fix` to the options list if you want.
245+
179246
### Include what you use
180247

181248
To run include what you use, install (`brew install include-what-you-use` on
@@ -186,12 +253,12 @@ cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=$(which include-what-y
186253
cmake --build build
187254
```
188255

189-
The report is sent to stderr; you can pip it into a file if you wish.
256+
The report is sent to stderr; you can pipe it into a file if you wish.
190257

191258
### Build recipes
192259

193260
This builds with the Intel compiler (assuming it is in your path, along with a
194-
recent CMake and Python 3):
261+
recent CMake and Python):
195262

196263
```bash
197264
python3 -m venv venv
@@ -313,6 +380,8 @@ if you really want to.
313380

314381

315382
[pre-commit]: https://pre-commit.com
383+
[clang-format]: https://clang.llvm.org/docs/ClangFormat.html
384+
[clang-tidy]: https://clang.llvm.org/extra/clang-tidy/
316385
[pybind11.readthedocs.org]: http://pybind11.readthedocs.org/en/latest
317386
[issue tracker]: https://github.com/pybind/pybind11/issues
318387
[gitter]: https://gitter.im/pybind/Lobby

0 commit comments

Comments
 (0)