Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cd8ee31
update to uv and ruff
skarndev Jan 30, 2026
6cfdaaa
add missing files
skarndev Jan 30, 2026
0c85957
install uv + introduce job depedency of build on check
skarndev Jan 30, 2026
37c4852
fix CI runs
skarndev Jan 31, 2026
d8a4d26
update uv.lock
skarndev Jan 31, 2026
a34ce6b
do not install to venv
skarndev Jan 31, 2026
781a8bf
test CI
skarndev Jan 31, 2026
5c5cb02
formatting changes
skarndev Jan 31, 2026
cc18287
create uv venv for stub action
skarndev Jan 31, 2026
107a779
swap argument order
skarndev Jan 31, 2026
5a90ba0
update CI.yml
skarndev Jan 31, 2026
9ab54ac
update ci
skarndev Jan 31, 2026
d235da4
Use uv run for running pybind11-stubgen in CI
Apr 4, 2026
9595fec
Merge remote-tracking branch 'origin/main' into feature/modernize-lin…
Apr 4, 2026
948ea34
Exclude tests/stubs from Ruff and fix formatting
Apr 4, 2026
c3ac0ba
Fix stub formatting: switch from black/isort to ruff
Apr 4, 2026
55a1fd3
Fix tox and CI for ruff-based stub formatting
Apr 4, 2026
f36dcf1
Use PYTHON_EXECUTABLE for pip install of demo module
Apr 4, 2026
d4c5c05
Use uv pip install --python for demo module installation
Apr 4, 2026
1aa157f
Update reference stubs for new pybind11-stubgen output
Apr 4, 2026
e299783
Enabled tox-paralllel runs
Apr 4, 2026
6834ee7
Merge remote-tracking branch 'origin/main' into feature/modernize-lin…
Apr 20, 2026
44e5096
Update reference stubs after merging main
Apr 20, 2026
9dad310
Update pybind11 v2.9 reference stubs and bump cmake to 3.31
Apr 20, 2026
194956b
Address review: use setup-uv action and remove requirements.txt
Apr 20, 2026
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
102 changes: 61 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,60 @@ on:
pull_request:
push:
branches:
- master
- main
tags:
- "v*"

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Setup Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: astral-sh/setup-uv@v7
- name: Checkout
uses: actions/checkout@v5
- name: Install requirements
run: |
uv lock --check
uv sync
- name: Run Ruff as isort
run: uv run ruff check --select I,RUF022 --fix --diff ./pybind11_stubgen
if: ${{ failure() || success() }}
- name: Run Ruff format
run: uv run ruff format --diff ./pybind11_stubgen
if: ${{ failure() || success() }}
- name: Run Ruff
run: |
uv run ruff check --ignore F401,F821 .
if: ${{ failure() || success() }}

build:
name: Build wheel
runs-on: ubuntu-latest
needs: [check]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install build
run: python -m pip --disable-pip-version-check install build
- uses: astral-sh/setup-uv@v7

- name: Build sdist + wheel
run: python -m build
run: |
uv lock --check
uv build

- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: dist
path: dist

format:
name: Format code
runs-on: ubuntu-latest
steps:
- name: Setup Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Checkout
uses: actions/checkout@v5
- name: Install requirements
run: pip install -r requirements-dev.txt
- name: Run isort
run: isort --check --profile=black --diff ./pybind11_stubgen
if: ${{ failure() || success() }}
- name: Run black
run: black --diff ./pybind11_stubgen
if: ${{ failure() || success() }}
- name: Run flake8
run: |
flake8 \
--max-line-length=88 \
--extend-ignore=E203 \
--extend-exclude=venv/,.pytest_cache/,.ipynb_checkpoints/,tests/,tmp/,build/
if: ${{ failure() || success() }}

tests:
name: "Test 🐍 ${{ matrix.config.python }} • pybind-${{ matrix.config.pybind11-branch }} • ${{ matrix.config.numpy-format }}"
runs-on: ubuntu-latest
Expand Down Expand Up @@ -159,31 +161,40 @@ jobs:
with:
python-version: ${{ matrix.config.python }}

- uses: astral-sh/setup-uv@v7

- name: Update CMake
uses: jwlawson/actions-setup-cmake@v2
with:
# https://github.com/pybind/pybind11/blob/914c06fb252b6cc3727d0eedab6736e88a3fcb01/CMakeLists.txt#L13C34-L13C38
cmake-version: ${{ matrix.config.cmake-version }}

- name: Create UV venv
run: |
uv venv .venv

- name: Setup annotations on Linux
if: runner.os == 'Linux'
run: python -m pip install pytest-github-actions-annotate-failures
run: uv pip install pytest-github-actions-annotate-failures
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex spotted this:
This now installs pytest-github-actions-annotate-failures before uv sync. uv sync is exact by default, so it can remove packages that are not part of the synced dependency set, which makes that install step effectively redundant unless the package is moved after sync or added to the dev group.

In the current workflow that doesn’t change behavior, because these jobs never run pytest, so nothing consumes that plugin.


- name: Install requirements
run: pip install -r "./tests/stubs/python-${{ matrix.config.python }}/requirements.txt"
run: uv sync --group dev --no-install-project

- name: Install
shell: bash
working-directory: dist
run: python -m pip --disable-pip-version-check install *.whl
run: uv pip install --disable-pip-version-check *.whl

- name: Install demo module
shell: bash
run: ./tests/install-demo-module.sh --pybind11-branch "${{ matrix.config.pybind11-branch }}"
run: |
source .venv/bin/activate
./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.config.python }}/pybind11-${{ matrix.config.pybind11-branch }}/${{ matrix.config.numpy-format }}" --${{ matrix.config.numpy-format }}
run: |
source .venv/bin/activate
./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@v6
Expand All @@ -196,7 +207,9 @@ jobs:

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

test-cli-options:
name: "Runs on 🐍 ${{ matrix.python }} • ${{ matrix.test-package }}"
Expand All @@ -219,28 +232,35 @@ jobs:
with:
python-version: ${{ matrix.python }}

- uses: astral-sh/setup-uv@v7

- name: Download build artifacts
uses: actions/download-artifact@v6
with:
name: dist
path: dist

- name: Create UV venv
run: |
uv venv .venv

- name: Setup annotations on Linux
if: runner.os == 'Linux'
run: python -m pip install pytest-github-actions-annotate-failures
run: uv pip install pytest-github-actions-annotate-failures

- name: Install
shell: bash
working-directory: dist
run: python -m pip --disable-pip-version-check install *.whl
run: uv pip install --disable-pip-version-check *.whl

- name: "Install ${{ matrix.test-package }}"
shell: bash
run: pip install "${{ matrix.test-package }}"
run: uv pip install "${{ matrix.test-package }}"

- name: Generate stubs
shell: bash
run: |
source .venv/bin/activate
pybind11-stubgen "${{ matrix.test-package }}" -o flavour-1 --numpy-array-wrap-with-annotated
pybind11-stubgen "${{ matrix.test-package }}" -o flavour-2 --numpy-array-remove-parameters
pybind11-stubgen "${{ matrix.test-package }}" -o flavour-3 --print-invalid-expressions-as-is
Expand All @@ -249,7 +269,7 @@ jobs:

publish:
name: Publish distribution
needs: [build, format, tests, test-cli-options]
needs: [check, build, tests, test-cli-options]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
permissions:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ cython_debug/
# VS Code
.vscode/

# Zed
.zed/

tmp
*.patch
*.zip
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ dynamic = ["readme"]
Repository = "https://github.com/pybind/pybind11-stubgen"
Issues = "https://github.com/pybind/pybind11-stubgen/issues"

[dependency-groups]
dev = [
"cmeel==0.59.0",
"cmeel-eigen==3.4.0.2",
"numpy~=1.20",
"pip",
"scipy~=1.0",
"typing_extensions>=4,<5",
"mypy>=1.19.1",
"ruff>=0.14.14",
]

[tool.setuptools.packages]
find = {}

Expand All @@ -26,3 +38,18 @@ readme = {file = ["README.md"], content-type = "text/markdown"}

[project.entry-points.console_scripts]
pybind11-stubgen = "pybind11_stubgen.__init__:main"

[tool.ruff]
target-version = "py310"
line-length = 88
exclude = ["tests/stubs"]

[tool.ruff.lint]
ignore = ["F403"] # undefined names imported (triggered by native extensions)

[tool.ruff.format]
quote-style = "double"
indent-style = "space"

[tool.ruff.lint.pycodestyle]
max-line-length = 88
8 changes: 0 additions & 8 deletions requirements-dev.txt

This file was deleted.

9 changes: 4 additions & 5 deletions tests/check-demo-stubs-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -e

PYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')

resolve_path() {
local path="$1"

Expand Down Expand Up @@ -55,7 +53,7 @@ remove_stubs() {
}

run_stubgen() {
${PYTHON_EXECUTABLE} -m pybind11_stubgen \
pybind11-stubgen \
demo \
--output-dir=${STUBS_DIR} \
${NUMPY_FORMAT} \
Expand All @@ -69,8 +67,9 @@ run_stubgen() {
format_stubs() {
(
cd "${STUBS_DIR}" ;
black . ;
isort --profile=black . ;
PYTHON_TARGET=$(python -c "import sys; print(f'py{sys.version_info.major}{sys.version_info.minor}')")
ruff format --target-version "${PYTHON_TARGET}" .
ruff check --select I,RUF022 --fix --target-version "${PYTHON_TARGET}" .
)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/install-demo-module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ resolve_path() {
fi
}


function parse_args() {

CLEAR='\033[0m'
Expand Down Expand Up @@ -84,7 +85,7 @@ install_pydemo() {
(
export CMAKE_PREFIX_PATH="$(resolve_path "${INSTALL_PREFIX}"):$(cmeel cmake)";
rm -rf ${TESTS_ROOT}/py-demo/build
${PYTHON_EXECUTABLE} -m pip install --force-reinstall "${TESTS_ROOT}/py-demo"
uv pip install --python "${PYTHON_EXECUTABLE}" --force-reinstall "${TESTS_ROOT}/py-demo"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ from __future__ import annotations

import typing

import numpy
from numpy import random

import demo._bindings.enum
import numpy
from demo._bindings.aliases.foreign_method_arg import Bar2 as foreign_type_alias
from demo._bindings.aliases.foreign_return import get_foo as foreign_class_alias
from numpy import random

from . import (
foreign_arg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def four_col_matrix_r(
def four_row_matrix_r(
arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[4, n]"],
) -> typing.Annotated[numpy.typing.NDArray[numpy.float32], "[4, n]"]: ...
def get_matrix_int() -> (
typing.Annotated[numpy.typing.NDArray[numpy.int32], "[3, 3]"]
): ...
def get_vector_float64() -> (
typing.Annotated[numpy.typing.NDArray[numpy.float64], "[3, 1]"]
): ...
def get_matrix_int() -> typing.Annotated[
numpy.typing.NDArray[numpy.int32], "[3, 3]"
]: ...
def get_vector_float64() -> typing.Annotated[
numpy.typing.NDArray[numpy.float64], "[3, 1]"
]: ...
def sparse_matrix_c(
arg0: typing.Annotated[scipy.sparse.csc_matrix, numpy.float32],
) -> typing.Annotated[scipy.sparse.csc_matrix, numpy.float32]: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import typing

__all__: list[str] = [
"backslashes_should_be_escaped",
"issue_274_docstring_leading_newline",
"issue_51_catastrophic_regex",
"issue_73_utf8_doc_chars",
"issue_274_docstring_leading_newline",
]

def backslashes_should_be_escaped() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,23 @@ class WithPropDoc:
"""
prop doc token
"""

@def_property.setter
def def_property(self, arg1: typing.SupportsInt | typing.SupportsIndex) -> 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: typing.SupportsInt | typing.SupportsIndex
Expand All @@ -81,13 +77,11 @@ class WithGetterSetterDoc:
"""
getter doc token
"""

@def_property.setter
def def_property(self, arg1: typing.SupportsInt | typing.SupportsIndex) -> None:
"""
setter doc token
"""

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

@def_property.setter
def def_property(self, arg1: typing.SupportsInt | typing.SupportsIndex) -> None: ...
@property
Expand Down
Loading
Loading