Skip to content

Commit 9fe8f11

Browse files
Keller Fabian Rudolf (CC-AD/EYC3)bluenote10
Keller Fabian Rudolf (CC-AD/EYC3)
authored andcommitted
minimize pybind11_mypy_demo to bare minimum
1 parent e681915 commit 9fe8f11

File tree

5 files changed

+55
-77
lines changed

5 files changed

+55
-77
lines changed

misc/test-stubgenc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
set -e
4+
set -x
45

56
cd "$(dirname $0)/.."
67

@@ -10,7 +11,7 @@ python -m pip install ./test-data/pybind11_mypy_demo
1011
python -m pip install .
1112

1213
# Remove expected stubs and generate new inplace
13-
STUBGEN_OUTPUT_FOLDER=test-data/pybind11_mypy_demo/stubgen
14+
STUBGEN_OUTPUT_FOLDER=./test-data/pybind11_mypy_demo/stubgen
1415
rm -rf $STUBGEN_OUTPUT_FOLDER/*
1516
stubgen -p pybind11_mypy_demo -o $STUBGEN_OUTPUT_FOLDER
1617

test-data/pybind11_mypy_demo/LICENSE

Lines changed: 0 additions & 36 deletions
This file was deleted.

test-data/pybind11_mypy_demo/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = [
33
"setuptools>=42",
44
"wheel",
55
# Officially supported pybind11 version. This is pinned to guarantee 100% reproducible CI.
6-
# As a results, needs to be updated deliberately at will.
6+
# As a result, needs to be updated deliberately at will.
77
"pybind11==2.9.2",
88
]
99

test-data/pybind11_mypy_demo/setup.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,18 @@
1-
import sys
2-
3-
from pybind11 import get_cmake_dir
4-
# Available at setup time due to pyproject.toml
5-
from pybind11.setup_helpers import Pybind11Extension, build_ext
1+
# pybind11 is available at setup time due to pyproject.toml
2+
from pybind11.setup_helpers import Pybind11Extension
63
from setuptools import setup
74

8-
__version__ = "0.0.1"
9-
10-
# The main interface is through Pybind11Extension.
11-
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
12-
# * You can set include_pybind11=false to add the include directory yourself,
13-
# say from a submodule.
14-
#
15-
# Note:
16-
# Sort input source files if you glob sources to ensure bit-for-bit
17-
# reproducible builds (https://github.com/pybind/python_example/pull/53)
18-
5+
# Documentation: https://pybind11.readthedocs.io/en/stable/compiling.html
196
ext_modules = [
207
Pybind11Extension(
218
"pybind11_mypy_demo",
229
["src/main.cpp"],
23-
# Example: passing in the version to the compiled code
24-
define_macros=[('VERSION_INFO', __version__)],
10+
cxx_std=17,
2511
),
2612
]
2713

2814
setup(
2915
name="pybind11-mypy-demo",
30-
version=__version__,
31-
author="Sergei Izmailov",
32-
author_email="[email protected]", # Subject to change
33-
url="https://github.com/sizmailov/pybind11-mypy-demo", # Subject to change
34-
description="A demo project using pybind11 to test mypy stubgen",
35-
long_description="",
16+
version="0.0.1",
3617
ext_modules=ext_modules,
37-
extras_require={"test": "pytest"},
38-
# Currently, build_ext only provides an optional "highest supported C++
39-
# level" feature, but in the future it may provide more features.
40-
cmdclass={"build_ext": build_ext},
41-
zip_safe=False,
4218
)

test-data/pybind11_mypy_demo/src/main.cpp

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
/**
2+
* This file was originally inspired by:
3+
*
4+
* https://github.com/sizmailov/pybind11-mypy-demo
5+
*
6+
* Copyright (c) 2016 The Pybind Development Team, All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of the copyright holder nor the names of its contributors
19+
* may be used to endorse or promote products derived from this software
20+
* without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*
33+
* You are under no obligation whatsoever to provide any bug fixes, patches, or
34+
* upgrades to the features, functionality or performance of the source code
35+
* ("Enhancements") to anyone; however, if you choose to make your Enhancements
36+
* available either publicly, or directly to the author of this software, without
37+
* imposing a separate written license agreement for such Enhancements, then you
38+
* hereby grant the following license: a non-exclusive, royalty-free perpetual
39+
* license to install, use, modify, prepare derivative works, incorporate into
40+
* other computer software, distribute, and sublicense such enhancements or
41+
* derivative works thereof, in binary and source code form.
42+
*/
43+
144
#include <cmath>
245
#include <pybind11/pybind11.h>
346

@@ -68,7 +111,7 @@ const Point Point::y_axis = Point(0, 1);
68111
Point::LengthUnit Point::length_unit = Point::LengthUnit::mm;
69112
Point::AngleUnit Point::angle_unit = Point::AngleUnit::radian;
70113

71-
}
114+
} // namespace: basics
72115

73116
void bind_basics(py::module& basics) {
74117

@@ -80,7 +123,6 @@ void bind_basics(py::module& basics) {
80123
basics.def("midpoint", &midpoint, py::arg("left"), py::arg("right"));
81124
basics.def("weighted_midpoint", weighted_midpoint, py::arg("left"), py::arg("right"), py::arg("alpha")=0.5);
82125

83-
84126
// Classes
85127
py::class_<Point> pyPoint(basics, "Point");
86128
py::enum_<Point::LengthUnit> pyLengthUnit(pyPoint, "LengthUnit");
@@ -103,30 +145,25 @@ void bind_basics(py::module& basics) {
103145
.def_property_static("angle_unit",
104146
[](py::object& /*cls*/){ return Point::angle_unit; },
105147
[](py::object& /*cls*/, Point::AngleUnit value){ Point::angle_unit = value; }
106-
)
107-
;
148+
);
108149

109150
pyPoint.attr("origin") = Point::origin;
110151

111152
pyLengthUnit
112153
.value("mm", Point::LengthUnit::mm)
113154
.value("pixel", Point::LengthUnit::pixel)
114-
.value("inch", Point::LengthUnit::inch)
115-
;
155+
.value("inch", Point::LengthUnit::inch);
116156

117157
pyAngleUnit
118158
.value("radian", Point::AngleUnit::radian)
119-
.value("degree", Point::AngleUnit::degree)
120-
;
159+
.value("degree", Point::AngleUnit::degree);
121160

122161
// Module-level attributes
123162
basics.attr("PI") = std::acos(-1);
124163
basics.attr("__version__") = "0.0.1";
125164
}
126165

127166
PYBIND11_MODULE(pybind11_mypy_demo, m) {
128-
129167
auto basics = m.def_submodule("basics");
130168
bind_basics(basics);
131-
132169
}

0 commit comments

Comments
 (0)