Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 22 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,31 @@ jobs:
if: ${{ failure() || success() }}

tests:
name: "Test 🐍 ${{ matrix.python }} • pybind-${{ matrix.pybind11-branch }} • ${{ matrix.numpy-format }}"
name: "Test 🐍 ${{ matrix.config.python }} • pybind-${{ matrix.config.pybind11-branch }} • ${{ matrix.config.numpy-format }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pybind11-branch:
- "v2.13"
python:
- "3.13"
- "3.12"
- "3.11"
- "3.10"
- "3.9"
- "3.8"
numpy-format:
- "numpy-array-wrap-with-annotated"
include:
- python: "3.13"
pybind11-branch: "v2.9"
numpy-format: "numpy-array-wrap-with-annotated"
- python: "3.13"
pybind11-branch: "v2.11"
numpy-format: "numpy-array-wrap-with-annotated"
- python: "3.13"
pybind11-branch: "v2.12"
numpy-format: "numpy-array-wrap-with-annotated"
- python: "3.13"
pybind11-branch: "v2.13"
numpy-format: "numpy-array-use-type-var"
# # TODO: uncomment
# - python: "3.13"
# pybind11-branch: "master"
config: [
{ pybind11-branch: "v3.0", python: "3.13", numpy-format: "numpy-array-use-type-var"},
{ pybind11-branch: "v3.0", python: "3.13", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.13", python: "3.13", numpy-format: "numpy-array-use-type-var"},
{ pybind11-branch: "v2.13", python: "3.13", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.13", python: "3.12", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.13", python: "3.11", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.13", python: "3.10", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.13", python: "3.9", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.12", python: "3.13", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.11", python: "3.13", numpy-format: "numpy-array-wrap-with-annotated"},
{ pybind11-branch: "v2.9", python: "3.13", numpy-format: "numpy-array-wrap-with-annotated"},
]
steps:
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python }}
- name: Setup Python ${{ matrix.config.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
python-version: ${{ matrix.config.python }}

- name: Update CMake
uses: jwlawson/actions-setup-cmake@v2
Expand All @@ -89,31 +75,31 @@ jobs:
run: python -m pip install pytest-github-actions-annotate-failures

- name: Install requirements
run: pip install -r "./tests/stubs/python-${{ matrix.python }}/requirements.txt"
run: pip install -r "./tests/stubs/python-${{ matrix.config.python }}/requirements.txt"

- name: Install pybind11-stubgen
run: pip install .

- name: Install demo module
shell: bash
run: ./tests/install-demo-module.sh --pybind11-branch "${{ matrix.pybind11-branch }}"
run: ./tests/install-demo-module.sh --pybind11-branch "${{ matrix.config.pybind11-branch }}"

- name: Check stubs generation
shell: bash
run: ./tests/check-demo-stubs-generation.sh --stubs-sub-dir "stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}" --${{ matrix.numpy-format }}
run: ./tests/check-demo-stubs-generation.sh --stubs-sub-dir "stubs/python-${{ matrix.config.python }}/pybind11-${{ matrix.config.pybind11-branch }}/${{ matrix.config.numpy-format }}" --${{ matrix.config.numpy-format }}

- name: Archive patch
uses: actions/upload-artifact@v4
if: failure()
with:
name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}-${{ matrix.numpy-format }}.patch"
path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}.patch"
name: "python-${{ matrix.config.python }}-pybind-${{ matrix.config.pybind11-branch }}-${{ matrix.config.numpy-format }}.patch"
path: "./tests/stubs/python-${{ matrix.config.python }}/pybind11-${{ matrix.config.pybind11-branch }}/${{ matrix.config.numpy-format }}.patch"
retention-days: 30
if-no-files-found: ignore

- name: Check error generation
shell: bash
run: ./tests/check-demo-errors-generation.sh
run: ./tests/check-demo-errors-generation.sh "pybind11-${{ matrix.config.pybind11-branch }}"

test-cli-options:
name: "Runs on 🐍 ${{ matrix.python }} • ${{ matrix.test-package }}"
Expand All @@ -128,7 +114,6 @@ jobs:
- "3.11"
- "3.10"
- "3.9"
- "3.8"
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

# End of https://www.toptal.com/developers/gitignore/api/c++,cmake,python

Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "pybind11-stubgen"
description = "PEP 561 type stubs generator for pybind11 modules"
version = "2.5.5"
requires-python = "~=3.7"
authors = [
{name = "Sergei Izmailov", email = "[email protected]"},
]
license = "BSD-3-Clause"
license-files = ["LICENSE"]
dynamic = ["readme"]

[project.urls]
Repository = "https://github.com/sizmailov/pybind11-stubgen"
Issues = "https://github.com/sizmailov/pybind11-stubgen/issues"

[tool.setuptools.packages]
find = {}

[tool.setuptools.dynamic]
readme = {file = ["README.md"], content-type = "text/markdown"}

[project.entry-points.console_scripts]
pybind11-stubgen = "pybind11_stubgen.__init__:main"
19 changes: 0 additions & 19 deletions setup.py

This file was deleted.

8 changes: 7 additions & 1 deletion tests/check-demo-errors-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

set -e

if [ "$#" -ne 1 ]; then
echo "Usage: $0 pybind11-vX.Y"
exit 1
fi

TESTS_ROOT="$(readlink -m "$(dirname "$0")")"
DEMO_ERRORS_FILE="${TESTS_ROOT}/demo.errors.stderr.txt"
ERRORS_ROOT="$(readlink -m "${TESTS_ROOT}/errors/$1")"
DEMO_ERRORS_FILE="${ERRORS_ROOT}/demo.errors.stderr.txt"
STUBS_DIR="/tmp/out" # Stubs should never be actually written

remove_demo_errors() {
Expand Down
1 change: 1 addition & 0 deletions tests/errors/pybind11-v2.11
1 change: 1 addition & 0 deletions tests/errors/pybind11-v2.12
1 change: 1 addition & 0 deletions tests/errors/pybind11-v2.13
15 changes: 15 additions & 0 deletions tests/errors/pybind11-v3.0/demo.errors.stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pybind11_stubgen - [ ERROR] In demo._bindings.aliases.foreign_enum_default : Invalid expression '<ConsoleForegroundColor.Blue: 34>'
pybind11_stubgen - [ ERROR] In demo._bindings.enum.accept_defaulted_enum : Invalid expression '<ConsoleForegroundColor.None_: -1>'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_enum : Invalid expression '(anonymous namespace)::Enum'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_enum_defaulted : Invalid expression '<demo._bindings.flawed_bindings.Enum object at 0x1234abcd5678>'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_type : Invalid expression '(anonymous namespace)::Unbound'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_type_defaulted : Invalid expression '<demo._bindings.flawed_bindings.Unbound object at 0x1234abcd5678>'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.get_unbound_type : Invalid expression '(anonymous namespace)::Unbound'
pybind11_stubgen - [WARNING] Enum-like str representations were found with no matching mapping to the enum class location.
Use `--enum-class-locations` to specify full path to the following enum(s):
- ConsoleForegroundColor
pybind11_stubgen - [WARNING] Raw C++ types/values were found in signatures extracted from docstrings.
Please check the corresponding sections of pybind11 documentation to avoid common mistakes in binding code:
- https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings
- https://pybind11.readthedocs.io/en/latest/advanced/functions.html#default-arguments-revisited
pybind11_stubgen - [ INFO] Terminating due to previous errors
2 changes: 1 addition & 1 deletion tests/stubs/python-3.10
2 changes: 1 addition & 1 deletion tests/stubs/python-3.11
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __all__: list[str] = ["Base", "CppException", "Derived", "Foo", "Outer"]
class Base:
class Inner:
pass

name: str

class CppException(Exception):
Expand Down Expand Up @@ -53,5 +54,7 @@ class Outer:
def name(self) -> str: ...
@property
def value(self) -> int: ...

value: Outer.Inner.NestedEnum

inner: Outer.Inner
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ __all__: list[str] = [
def accept_matrix_int(
arg0: typing.Annotated[
numpy.ndarray, numpy.int32, pybind11_stubgen.typing_ext.FixedSize(3, 3)
]
],
) -> None: ...
def accept_vector_float64(
arg0: typing.Annotated[
numpy.ndarray, numpy.float64, pybind11_stubgen.typing_ext.FixedSize(3, 1)
]
],
) -> None: ...
def dense_matrix_c(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]: ...
def dense_matrix_r(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]: ...
Expand All @@ -52,7 +52,7 @@ def fixed_mutator_a(
numpy.float32,
pybind11_stubgen.typing_ext.FixedSize(5, 6),
numpy.ndarray.flags.writeable,
]
],
) -> None: ...
def fixed_mutator_c(
arg0: typing.Annotated[
Expand All @@ -61,7 +61,7 @@ def fixed_mutator_c(
pybind11_stubgen.typing_ext.FixedSize(5, 6),
numpy.ndarray.flags.writeable,
numpy.ndarray.flags.f_contiguous,
]
],
) -> None: ...
def fixed_mutator_r(
arg0: typing.Annotated[
Expand All @@ -70,31 +70,35 @@ def fixed_mutator_r(
pybind11_stubgen.typing_ext.FixedSize(5, 6),
numpy.ndarray.flags.writeable,
numpy.ndarray.flags.c_contiguous,
]
],
) -> None: ...
def four_col_matrix_r(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", 4)
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", 4)
]: ...
def four_row_matrix_r(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize(4, "n")
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize(4, "n")
]: ...
def get_matrix_int() -> typing.Annotated[
numpy.ndarray, numpy.int32, pybind11_stubgen.typing_ext.FixedSize(3, 3)
]: ...
def get_vector_float64() -> typing.Annotated[
numpy.ndarray, numpy.float64, pybind11_stubgen.typing_ext.FixedSize(3, 1)
]: ...
def get_matrix_int() -> (
typing.Annotated[
numpy.ndarray, numpy.int32, pybind11_stubgen.typing_ext.FixedSize(3, 3)
]
): ...
def get_vector_float64() -> (
typing.Annotated[
numpy.ndarray, numpy.float64, pybind11_stubgen.typing_ext.FixedSize(3, 1)
]
): ...
def sparse_matrix_c(
arg0: typing.Annotated[scipy.sparse.csc_matrix, numpy.float32]
arg0: typing.Annotated[scipy.sparse.csc_matrix, numpy.float32],
) -> typing.Annotated[scipy.sparse.csc_matrix, numpy.float32]: ...
def sparse_matrix_r(
arg0: typing.Annotated[scipy.sparse.csr_matrix, numpy.float32]
arg0: typing.Annotated[scipy.sparse.csr_matrix, numpy.float32],
) -> typing.Annotated[scipy.sparse.csr_matrix, numpy.float32]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ __all__: list[str] = [
]

def accept_ndarray_float64(
arg0: typing.Annotated[numpy.ndarray, numpy.float64]
arg0: typing.Annotated[numpy.ndarray, numpy.float64],
) -> None: ...
def accept_ndarray_int(arg0: typing.Annotated[numpy.ndarray, numpy.int32]) -> None: ...
def get_ndarray_float64() -> typing.Annotated[numpy.ndarray, numpy.float64]: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class WithGetterSetterDoc:
"""
getter doc token
"""

@def_property.setter
def def_property(self, arg1: int) -> None:
"""
setter doc token
"""

@property
def def_property_readonly(self) -> int:
"""
Expand All @@ -44,6 +46,7 @@ class WithPropAndGetterSetterDoc:
"""
prop doc token
"""

@def_property.setter
def def_property(self, arg1: int) -> None: ...
@property
Expand All @@ -64,23 +67,27 @@ class WithPropDoc:
"""
prop doc token
"""

@def_property.setter
def def_property(self, arg1: int) -> None: ...
@property
def def_property_readonly(self) -> int:
"""
prop doc token
"""

@property
def def_readonly(self) -> int:
"""
prop doc token
"""

@property
def def_readwrite(self) -> int:
"""
prop doc token
"""

@def_readwrite.setter
def def_readwrite(self, arg0: int) -> None: ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ __all__: list[str] = [
]

def std_array(
arg0: typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)]
arg0: typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)],
) -> typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)]: ...
def std_map() -> dict[int, complex]: ...
def std_optional(arg0: int | None) -> None: ...
Expand Down
Loading