Skip to content

Commit 25f5ebb

Browse files
Merge pull request #131 from nucleic/install
Install kiwi in a proper package to include the type hints
2 parents 3afb093 + ca31814 commit 25f5ebb

19 files changed

+69
-21
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ jobs:
5151
flake8 py
5252
- name: Run Mypy
5353
if: always()
54+
# We test twice to ensure the type annotations are properly installed
5455
run: |
5556
mypy py
57+
cd py/tests
58+
mypy .
5659
benchmark:
5760
name: C++ Benchmark
5861
runs-on: ${{ matrix.os }}
@@ -101,7 +104,7 @@ jobs:
101104
- name: Test with pytest
102105
run: |
103106
pip install pytest
104-
python -X dev -m pytest py/tests
107+
python -X dev -m pytest py
105108
- name: Generate C++ coverage reports
106109
if: (github.event_name != 'schedule' && matrix.os != 'windows-latest')
107110
run: |

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include README.rst
44
include releasenotes.rst
55
recursive-include kiwi *.h
66
recursive-include py *.cpp *.h *.py *.pyi
7-
include py/py.typed
7+
include py/kiwisolver/py.typed
88
recursive-include docs/source *.rst
99
recursive-include docs/source *.png
1010
recursive-include docs/source *.py

lint_requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
black
22
flake8
33
isort
4-
mypy
4+
mypy
5+
# Allow to lint tests using mypy
6+
pytest

py/kiwisolver/__init__.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# --------------------------------------------------------------------------------------
2+
# Copyright (c) 2013-2022, Nucleic Development Team.
3+
#
4+
# Distributed under the terms of the Modified BSD License.
5+
#
6+
# The full license is in the file LICENSE, distributed with this software.
7+
# --------------------------------------------------------------------------------------
8+
from ._cext import (
9+
BadRequiredStrength,
10+
Constraint,
11+
DuplicateConstraint,
12+
DuplicateEditVariable,
13+
Expression,
14+
Solver,
15+
Term,
16+
UnknownConstraint,
17+
UnknownEditVariable,
18+
UnsatisfiableConstraint,
19+
Variable,
20+
__kiwi_version__,
21+
__version__,
22+
strength,
23+
)
24+
25+
__all__ = [
26+
"BadRequiredStrength",
27+
"DuplicateConstraint",
28+
"DuplicateEditVariable",
29+
"UnknownConstraint",
30+
"UnknownEditVariable",
31+
"UnsatisfiableConstraint",
32+
"strength",
33+
"Variable",
34+
"Term",
35+
"Expression",
36+
"Constraint",
37+
"Solver",
38+
"__version__",
39+
"__kiwi_version__",
40+
]

py/kiwisolver.pyi renamed to py/kiwisolver/_cext.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ try:
1313
except ImportError:
1414
from typing_extensions import Literal # type: ignore
1515

16+
__version__: str
17+
__kiwi_version__: str
18+
1619
# --- Exceptions
1720

1821
class BadRequiredStrength(Exception): ...
File renamed without changes.
File renamed without changes.
File renamed without changes.

py/kiwisolver.cpp renamed to py/src/kiwisolver.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bool add_objects( PyObject* mod )
134134

135135

136136
int
137-
catom_modexec( PyObject *mod )
137+
kiwi_modexec( PyObject *mod )
138138
{
139139
if( !ready_types() )
140140
{
@@ -161,14 +161,14 @@ kiwisolver_methods[] = {
161161

162162

163163
PyModuleDef_Slot kiwisolver_slots[] = {
164-
{Py_mod_exec, reinterpret_cast<void*>( catom_modexec ) },
164+
{Py_mod_exec, reinterpret_cast<void*>( kiwi_modexec ) },
165165
{0, NULL}
166166
};
167167

168168

169169
struct PyModuleDef moduledef = {
170170
PyModuleDef_HEAD_INIT,
171-
"kiwisolver",
171+
"_cext",
172172
"kiwisolver extension module",
173173
0,
174174
kiwisolver_methods,
@@ -181,7 +181,7 @@ struct PyModuleDef moduledef = {
181181
} // namespace
182182

183183

184-
PyMODINIT_FUNC PyInit_kiwisolver( void )
184+
PyMODINIT_FUNC PyInit__cext( void )
185185
{
186186
return PyModuleDef_Init( &moduledef );
187187
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

py/util.h renamed to py/src/util.h

File renamed without changes.
File renamed without changes.

pyproject.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4.3", "cppy>=1.2
4343
build-backend = "setuptools.build_meta"
4444

4545
[tool.setuptools_scm]
46-
write_to = "py/version.h"
46+
write_to = "py/src/version.h"
4747
write_to_template = """
4848
/* ----------------------------------------------------------------------------
4949
| Copyright (c) 2013-2021, Nucleic Development Team.
@@ -70,10 +70,6 @@ minversion = "6.0"
7070
follow_imports = "normal"
7171
strict_optional = true
7272

73-
[[tool.mypy.overrides]]
74-
module="pytest.*"
75-
ignore_missing_imports = true
76-
7773
[tool.isort]
7874
multi_line_output = 3
7975
include_trailing_comma = true

releasenotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Kiwi Release Notes
44
Wrappers 1.4.1 | Solver 1.4.1 | unreleased
55
------------------------------------------
66
- add missing include PR #129
7+
- re-organize the Python binding sources to properly ship type hints PR #131
78

89
Wrappers 1.4.0 | Solver 1.4.0 | 14/03/2021
910
------------------------------------------

setup.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727

2828
ext_modules = [
2929
Extension(
30-
"kiwisolver",
30+
"kiwisolver._cext",
3131
[
32-
"py/kiwisolver.cpp",
33-
"py/constraint.cpp",
34-
"py/expression.cpp",
35-
"py/solver.cpp",
36-
"py/strength.cpp",
37-
"py/term.cpp",
38-
"py/variable.cpp",
32+
"py/src/kiwisolver.cpp",
33+
"py/src/constraint.cpp",
34+
"py/src/expression.cpp",
35+
"py/src/solver.cpp",
36+
"py/src/strength.cpp",
37+
"py/src/term.cpp",
38+
"py/src/variable.cpp",
3939
],
4040
include_dirs=["."],
4141
language="c++",
@@ -72,8 +72,11 @@
7272
"setuptools_scm[toml]>=3.4.3",
7373
"cppy>=1.2.0",
7474
],
75+
package_dir={"": "py"},
76+
packages=["kiwisolver"],
7577
install_requires=["typing_extensions;python_version<'3.8'"],
7678
ext_modules=ext_modules,
7779
cmdclass={"build_ext": CppyBuildExt},
78-
package_data={"py": ["py.typed", "*.pyi"]},
80+
include_package_data=False,
81+
package_data={"kiwisolver": ["py.typed", "*.pyi"]},
7982
)

0 commit comments

Comments
 (0)