Skip to content
Draft
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
102 changes: 64 additions & 38 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
- 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,23 +167,31 @@ 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" --system

- 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
Expand Down Expand Up @@ -219,28 +235,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 +275,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
1 change: 0 additions & 1 deletion pybind11_stubgen/parser/mixins/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@


class RemoveSelfAnnotation(IParser):

__any_t_name = QualifiedName.from_str("Any")
__typing_any_t_name = QualifiedName.from_str("typing.Any")

Expand Down
25 changes: 25 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,17 @@ 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

[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.

8 changes: 3 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 \
uv run pybind11_stubgen \
demo \
--output-dir=${STUBS_DIR} \
${NUMPY_FORMAT} \
Expand All @@ -68,8 +66,8 @@ run_stubgen() {
format_stubs() {
(
cd "${STUBS_DIR}" ;
black . ;
isort --profile=black . ;
uv run ruff format ./pybind11_stubgen
uv run ruff check --select I,RUF022 --fix . --diff
)
}

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 --force-reinstall "${TESTS_ROOT}/py-demo"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,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 @@ -86,16 +86,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 @@ -60,13 +60,11 @@ def four_col_matrix_r(
def four_row_matrix_r(
arg0: numpy.ndarray[tuple[typing.Literal[4], N], numpy.dtype[numpy.float32]],
) -> numpy.ndarray[tuple[typing.Literal[4], N], numpy.dtype[numpy.float32]]: ...
def get_matrix_int() -> (
numpy.ndarray[tuple[typing.Literal[3], typing.Literal[3]], numpy.dtype[numpy.int32]]
): ...
def get_vector_float64() -> (
numpy.ndarray[
tuple[typing.Literal[3], typing.Literal[1]], numpy.dtype[numpy.float64]
]
): ...
def get_matrix_int() -> numpy.ndarray[
tuple[typing.Literal[3], typing.Literal[3]], numpy.dtype[numpy.int32]
]: ...
def get_vector_float64() -> numpy.ndarray[
tuple[typing.Literal[3], typing.Literal[1]], numpy.dtype[numpy.float64]
]: ...
def sparse_matrix_c(arg0: scipy.sparse.csc_matrix) -> scipy.sparse.csc_matrix: ...
def sparse_matrix_r(arg0: scipy.sparse.csr_matrix) -> scipy.sparse.csr_matrix: ...
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,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
Loading
Loading