Skip to content
Merged
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
16 changes: 4 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@ jobs:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- 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() }}
- name: Run pre-commit
run: uv run pre-commit run --all-files

build:
name: Build wheel
Expand Down
39 changes: 12 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
ci:
autoupdate_schedule: quarterly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.3.0"
rev: "v6.0.0"
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: no-commit-to-branch

- repo: local
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.11
hooks:
- id: black
name: black
entry: black
language: python
minimum_pre_commit_version: 2.9.2
require_serial: true
types_or: [ python, pyi ]
- id: isort
name: isort
entry: isort
args:
- --profile=black
language: system
types: [ python ]
stages: [ commit ]
- id: flake8
name: flake8
exclude: ^(tests)/
language: system
entry: flake8
- id: ruff-check
args:
# The line length in black
- --max-line-length=88
- --extend-ignore=E203
types: [ python ]
stages: [ commit ]
- --fix
- --ignore=F401,F821
types_or: [ python, pyi ]
- id: ruff-format
types_or: [ python, pyi ]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ During development, you may need to update the reference stubs in tests/stubs. T
```shell
uv python install 3.10 3.11 3.12 3.13
```
To enable the repository hooks locally:
```shell
uv sync
uv run pre-commit install
```
To regenerate the reference stubs run:
```shell
uv venv
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ dev = [
"cmeel-eigen==3.4.0.2",
"numpy~=1.20",
"pip",
"pre-commit>=4,<5",
"scipy~=1.0",
"typing_extensions>=4,<5",
"mypy>=1.19.1",
"ruff>=0.14.14",
]

[tool.setuptools.packages]
Expand Down
23 changes: 21 additions & 2 deletions tests/check-demo-stubs-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ remove_stubs() {
rm -rf "${STUBS_DIR}/*" ;
}

get_ruff_version() {
awk '
$1 == "-" && $2 == "repo:" && $3 == "https://github.com/astral-sh/ruff-pre-commit" {
found = 1
next
}
found && $1 == "rev:" {
sub(/^v/, "", $2)
print $2
exit
}
' "${TESTS_ROOT}/../.pre-commit-config.yaml"
}

run_stubgen() {
pybind11-stubgen \
demo \
Expand All @@ -68,8 +82,13 @@ format_stubs() {
(
cd "${STUBS_DIR}" ;
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}" .
RUFF_VERSION=$(get_ruff_version)
if [ -z "${RUFF_VERSION}" ]; then
echo "Failed to resolve Ruff version from .pre-commit-config.yaml"
exit 1
fi
uvx --from "ruff==${RUFF_VERSION}" ruff format --target-version "${PYTHON_TARGET}" .
uvx --from "ruff==${RUFF_VERSION}" ruff check --select I,RUF022 --fix --target-version "${PYTHON_TARGET}" .
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/py-demo/bindings/src/modules/methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Dummy {

void bind_methods_module(py::module&& m) {
using namespace methods_detail;

auto &&pyDummy = py::class_<Dummy>(m, "Dummy");

pyDummy.def_static("static_method", &Dummy::static_method);
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ deps =
numpy~=1.20
scipy~=1.0
typing_extensions>=4,<5
ruff>=0.14.14
pb29: cmake==3.31.*
pb211: cmake==3.28.3
pb212: cmake==3.28.3
Expand Down
183 changes: 160 additions & 23 deletions uv.lock

Large diffs are not rendered by default.

Loading