Skip to content

Commit 503f6e8

Browse files
authored
Release version 1.0 (#112)
⚠️ Project was rewritten from scratch for `1.x`. Changes: - Updated CLI interface, some options were removed, please see `pybind11-stubgen --help` for details - Replaced regex-based signature parsing with more robust procedure which enables to produce partially degraded signatures - Added type parsing/replacing, including deeply annotated types - Support implicit imports required for static analysis - Add introspection of pure python functions - Improved structure of test binary pybind module
1 parent 0680397 commit 503f6e8

File tree

107 files changed

+3955
-2246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3955
-2246
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
ea663c34775284590aef5cf1d087fc1840edb027
2-
abb3085624a1e982f360086b73686b8b32e47087
2+
abb3085624a1e982f360086b73686b8b32e47087

.github/workflows/ci.yml

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,35 @@ on:
44
workflow_dispatch:
55
pull_request:
66
push:
7+
branches:
8+
- master
79

810
jobs:
911

1012
format:
11-
name: Format
13+
name: Format code
1214
runs-on: ubuntu-latest
1315
steps:
1416
- name: Setup Python
1517
uses: actions/setup-python@v4
1618
with:
1719
python-version: '3.10.6'
1820
- name: Checkout
19-
uses: actions/checkout@master
21+
uses: actions/checkout@v3
2022
- name: Install requirements
2123
run: pip install -r requirements-dev.txt
24+
- name: Run isort
25+
run: isort --check --profile=black --diff ./pybind11_stubgen
26+
if: ${{ failure() || success() }}
2227
- name: Run black
23-
run: black --diff . --extend-exclude=tests/pybind11-project-example/external/
28+
run: black --diff ./pybind11_stubgen
2429
if: ${{ failure() || success() }}
25-
- name: Run isort
26-
run: isort --extend-skip=tests/pybind11-project-example/external/ --check --profile=black --diff .
30+
- name: Run flake8
31+
run: |
32+
flake8 \
33+
--max-line-length=88 \
34+
--extend-ignore=E203 \
35+
--extend-exclude=venv/,.pytest_cache/,.ipynb_checkpoints/,tests/,tmp/,build/
2736
if: ${{ failure() || success() }}
2837

2938
tests:
@@ -32,40 +41,35 @@ jobs:
3241
strategy:
3342
fail-fast: false
3443
matrix:
35-
runs-on: [ubuntu-latest, windows-2022]
44+
runs-on: [ ubuntu-latest ]
3645
python:
37-
- "3.10"
38-
46+
- "3.11"
47+
- "3.10"
48+
- "3.9"
49+
# - "3.8" # `typing.Annotated` not available
50+
include:
51+
- runs-on: "windows-2022"
52+
python: "3.10"
3953
steps:
40-
- uses: actions/checkout@v2
41-
with:
42-
submodules: 'recursive'
43-
44-
- name: Setup Python ${{ matrix.python }}
45-
uses: actions/setup-python@v2
46-
with:
47-
python-version: ${{ matrix.python }}
54+
- uses: actions/checkout@v3
4855

49-
- name: Update CMake
50-
uses: jwlawson/[email protected]
56+
- name: Setup Python ${{ matrix.python }}
57+
uses: actions/setup-python@v4
58+
with:
59+
python-version: ${{ matrix.python }}
5160

52-
- name: Setup annotations on Linux
53-
if: runner.os == 'Linux'
54-
run: python -m pip install pytest-github-actions-annotate-failures
61+
- name: Update CMake
62+
uses: jwlawson/[email protected]
5563

56-
- name: Install pybind11-stubgens
57-
run: |
58-
python -m pip install .
59-
python -m pip install black isort
64+
- name: Setup annotations on Linux
65+
if: runner.os == 'Linux'
66+
run: python -m pip install pytest-github-actions-annotate-failures
6067

61-
- name: Install pybind11-project-example
62-
run: python -m pip install tests/pybind11-project-example
68+
- name: Install requirements
69+
run: pip install -r requirements-dev.txt
6370

64-
- name: Generate stubs
65-
run: |
66-
pybind11-stubgen cpp_library_bindings '--output-dir=./tests/stubs/generated' '--root-module-suffix=' '--ignore-invalid=all' '--no-setup-py'
67-
black ./tests/stubs/generated
68-
isort --profile=black ./tests/stubs/generated
71+
- name: Install pybind11-stubgen
72+
run: pip install .
6973

70-
- name: Check stubs
71-
run: cd tests ; python compare_walker.py
74+
- name: Run tests
75+
run: ./tests/run-tests.sh

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
path: |
3434
dist/*.tar.gz
35-
dist/*.whl
35+
dist/*.whl
3636
3737
upload_pypi:
3838
needs: [build_dist]
@@ -47,4 +47,4 @@ jobs:
4747
- uses: pypa/[email protected]
4848
with:
4949
user: __token__
50-
password: ${{ secrets.PYPI_API_TOKEN }}
50+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,6 @@ cython_debug/
206206
#.idea/
207207

208208
# End of https://www.toptal.com/developers/gitignore/api/c++,cmake,python
209+
210+
211+
tmp

.gitmodules

Lines changed: 0 additions & 6 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: "v4.3.0"
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: no-commit-to-branch
9+
10+
- repo: local
11+
hooks:
12+
- id: black
13+
name: black
14+
entry: black
15+
language: python
16+
minimum_pre_commit_version: 2.9.2
17+
require_serial: true
18+
types_or: [ python, pyi ]
19+
- id: isort
20+
name: isort
21+
entry: isort
22+
args:
23+
- --profile=black
24+
language: system
25+
types: [ python ]
26+
stages: [ commit ]
27+
- id: flake8
28+
name: flake8
29+
exclude: ^(tests)/
30+
language: system
31+
entry: flake8
32+
args:
33+
# The line length in black
34+
- --max-line-length=88
35+
- --extend-ignore=E203
36+
types: [ python ]
37+
stages: [ commit ]

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Changelog
2+
=========
3+
4+
Version 1.0-dev (Aug 29, 2023)
5+
--------------------------
6+
⚠️ Project was rewritten from scratch for `1.x`. This allowed me to address some long-standing issues, but I might accidentally brake behaviour you relied on.
7+
8+
Changes:
9+
- Updated CLI interface, some options were removed, please see `pybind11-stubgen --help` for details
10+
- Replaced regex-based signature parsing with more robust procedure which enables to produce partially degraded signatures
11+
- Added type parsing/replacing, including deeply annotated types
12+
- Support implicit imports required for static analysis
13+
- Add introspection of pure python functions
14+
- Support python 3.10+ only (temporarily)
15+
- Improved structure of test binary pybind module

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ imposing a separate written license agreement for such Enhancements, then you
3434
hereby grant the following license: a non-exclusive, royalty-free perpetual
3535
license to install, use, modify, prepare derivative works, incorporate into
3636
other computer software, distribute, and sublicense such enhancements or
37-
derivative works thereof, in binary and source code form.
37+
derivative works thereof, in binary and source code form.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[![pypi](https://img.shields.io/pypi/v/pybind11-stubgen.svg?logo=PyPI&logoColor=white)](https://pypi.org/project/pybind11-stubgen/)
2+
3+
About
4+
----
5+
6+
Static analysis tools and IDE usually struggle to understand python binary extensions.
7+
`pybind11-stubgen` generates [stubs](https://peps.python.org/pep-0561/) for python extensions to make them less opaque.
8+
9+
While the CLI tool includes tweaks to target modules compiled specifically
10+
with [pybind11](https://github.com/pybind/pybind11) but it should work well with modules built with other libraries.
11+
12+
```bash
13+
# Install
14+
pip install pybind11-stubgen
15+
16+
# Generate stubs for numpy
17+
pybind11-stubgen numpy
18+
```
19+
20+
Usage
21+
-----
22+
23+
```
24+
pybind11-stubgen [-h]
25+
[-o OUTPUT_DIR]
26+
[--root-suffix ROOT_SUFFIX]
27+
[--ignore-invalid-expressions REGEX]
28+
[--ignore-invalid-identifiers REGEX]
29+
[--ignore-unresolved-names REGEX]
30+
[--ignore-all-errors]
31+
[--numpy-array-wrap-with-annotated-fixed-size| --numpy-array-remove-parameters]
32+
[--print-invalid-expressions-as-is]
33+
[--exit-code]
34+
MODULE_NAME
35+
```

README.rst

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)