Skip to content

Commit 5012113

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 5012113

File tree

5 files changed

+56
-77
lines changed

5 files changed

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

@@ -68,7 +112,7 @@ const Point Point::y_axis = Point(0, 1);
68112
Point::LengthUnit Point::length_unit = Point::LengthUnit::mm;
69113
Point::AngleUnit Point::angle_unit = Point::AngleUnit::radian;
70114

71-
}
115+
} // namespace: basics
72116

73117
void bind_basics(py::module& basics) {
74118

@@ -80,7 +124,6 @@ void bind_basics(py::module& basics) {
80124
basics.def("midpoint", &midpoint, py::arg("left"), py::arg("right"));
81125
basics.def("weighted_midpoint", weighted_midpoint, py::arg("left"), py::arg("right"), py::arg("alpha")=0.5);
82126

83-
84127
// Classes
85128
py::class_<Point> pyPoint(basics, "Point");
86129
py::enum_<Point::LengthUnit> pyLengthUnit(pyPoint, "LengthUnit");
@@ -103,30 +146,25 @@ void bind_basics(py::module& basics) {
103146
.def_property_static("angle_unit",
104147
[](py::object& /*cls*/){ return Point::angle_unit; },
105148
[](py::object& /*cls*/, Point::AngleUnit value){ Point::angle_unit = value; }
106-
)
107-
;
149+
);
108150

109151
pyPoint.attr("origin") = Point::origin;
110152

111153
pyLengthUnit
112154
.value("mm", Point::LengthUnit::mm)
113155
.value("pixel", Point::LengthUnit::pixel)
114-
.value("inch", Point::LengthUnit::inch)
115-
;
156+
.value("inch", Point::LengthUnit::inch);
116157

117158
pyAngleUnit
118159
.value("radian", Point::AngleUnit::radian)
119-
.value("degree", Point::AngleUnit::degree)
120-
;
160+
.value("degree", Point::AngleUnit::degree);
121161

122162
// Module-level attributes
123163
basics.attr("PI") = std::acos(-1);
124164
basics.attr("__version__") = "0.0.1";
125165
}
126166

127167
PYBIND11_MODULE(pybind11_mypy_demo, m) {
128-
129168
auto basics = m.def_submodule("basics");
130169
bind_basics(basics);
131-
132170
}

0 commit comments

Comments
 (0)