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
114 changes: 73 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,66 @@ 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"
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
Comment on lines +21 to +24
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any reason to not use a gh action?

      - name: Install uv
        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
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- 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 +167,43 @@ jobs:
with:
python-version: ${{ matrix.config.python }}

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- 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

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

- 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 +216,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 +241,38 @@ jobs:
with:
python-version: ${{ matrix.python }}

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- 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 +281,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
4 changes: 1 addition & 3 deletions pybind11_stubgen/parser/mixins/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,7 @@ def parse_function_docstring(
# This syntax is not supported before Python 3.12.
return []
type_vars: list[str] = list(
filter(
bool, map(str.strip, (type_vars_group or "").split(","))
)
filter(bool, map(str.strip, (type_vars_group or "").split(",")))
)
args = self.call_with_local_types(
type_vars, lambda: self.parse_args_str(match.group("args"))
Expand Down
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ dynamic = ["readme"]
Repository = "https://github.com/pybind/pybind11-stubgen"
Issues = "https://github.com/pybind/pybind11-stubgen/issues"

[dependency-groups]
dev = [
"cmeel==0.59.0",
"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 +37,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 @@ -68,8 +66,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 @@ -3,9 +3,10 @@ from __future__ import annotations
import typing

import numpy
import pybind11_stubgen.typing_ext
import scipy.sparse

import pybind11_stubgen.typing_ext

__all__: list[str] = [
"accept_matrix_int",
"accept_vector_float64",
Expand Down Expand Up @@ -86,16 +87,12 @@ def four_row_matrix_r(
) -> 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],
) -> 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 @@ -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
Loading
Loading