Skip to content

Migrate to uv & ruff, remove black and isort#290

Open
skarndev wants to merge 21 commits intomainfrom
feature/modernize-linters
Open

Migrate to uv & ruff, remove black and isort#290
skarndev wants to merge 21 commits intomainfrom
feature/modernize-linters

Conversation

@skarndev
Copy link
Copy Markdown
Contributor

@skarndev skarndev commented Jan 30, 2026

Summary

This PR migrates the project's tooling from pip/black/isort/flake8 to uv/ruff, and renames mastermain in CI.

CI changes

  • uv: replaced pip with uv for all package management in CI; uv venv + uv pip install for virtual environment setup and dependency installation
  • ruff: replaced black (formatter) + isort (import sorter) + flake8 (linter) with a single ruff invocation; added a new check job that runs ruff format --diff, ruff check --select I,RUF022 --diff (isort), and ruff check
  • Branch rename: updated CI trigger and publish step to target main instead of master

Script changes (tests/)

  • install-demo-module.sh: replaced pip install with uv pip install --python <exe> to install into the active venv without requiring pip to be present (uv venv doesn't include pip by default)
  • check-demo-stubs-generation.sh: replaced black + isort with ruff format + ruff check --select I,RUF022 --fix; added dynamic --target-version to handle PEP 695 syntax in Python 3.12+ stubs; removed --diff flag from the fix step (diffs are shown later by git diff --exit-code)
  • check-demo-errors-generation.sh: removed uv run wrapper (not compatible with tox's virtual env activation)

tox changes

  • Removed requirements-dev.txt dependency (replaced with inline deps in tox.ini)
  • Fixed parallel run: PYTHON_TAG_FILE now uses {envtmpdir} (per-env) instead of a shared path under {toxinidir}/tmp/
  • Added cmeel-eigen to deps so it's available during commands_pre (cmake build)

Reference stubs

  • Reformatted all reference stubs under tests/stubs/ with ruff (import ordering and style differ slightly from isort+black)
  • Updated requirements.txt files: removed black and isort, added ruff>=0.14.14

pyproject.toml

  • Added exclude = ["tests/stubs"] to [tool.ruff] to prevent ruff from parsing PEP 695 stub syntax (e.g. def f[T](...)) with a py310 target version

🤖 Generated with Claude Code

@ax3l ax3l mentioned this pull request Apr 3, 2026
17 tasks
Sergey Shumakov and others added 8 commits April 4, 2026 08:59
- Exclude tests/stubs/ from Ruff: generated .pyi fixtures use Python
  3.12+ PEP 695 syntax which is invalid under target-version = "py310"
- Run ruff format to fix parse.py after merging main

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace black and isort with ruff in test requirements.txt files
- Fix format_stubs() path (was ./pybind11_stubgen, should be .) and
  remove --diff flag from ruff check so fixes are actually written
- Update reference stubs with ruff's import ordering

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Drop uv run from test scripts; use tools directly from active env
  so both tox and CI work (uv run ignores VIRTUAL_ENV set by tox)
- Pass dynamic --target-version to ruff so PEP 695 stubs (py3.12+)
  are parsed correctly during isort check
- Activate .venv in CI before running stub/error check scripts
- Update tox.ini: replace requirements-dev.txt deps with cmeel +
  cmeel-eigen, install local package instead of PyPI pybind11_stubgen
- Update reference stubs to match ruff formatting (no blank lines
  after docstrings, union types without outer parens)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
uv venv does not include pip by default, so plain `pip install` falls
through to the system pip and installs demo outside the venv.
Using ${PYTHON_EXECUTABLE} -m pip ensures the venv's Python is used.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
uv venv creates environments without pip, so neither `pip install`
nor `python -m pip` work. Use `uv pip install --python PYTHON_EXECUTABLE`
which explicitly targets the correct interpreter in both CI and tox.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove blank lines after docstrings (ruff formatting)
- Remove accept_annotated_callable from pybind11-v2.11 stubs
  (function not present in that version)
- Update iterator/container type stubs for older pybind11 versions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@skarndev skarndev marked this pull request as ready for review April 4, 2026 08:00
@skarndev skarndev requested review from ax3l and virtuald April 4, 2026 08:01
Comment on lines +21 to +24
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
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

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.

Probably requirements.txt should not survive migration to uv

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Those are dependencies for test stubs, should we consider supplying a pyproject.toml there instead? Or an optional dependency group in the main one?

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.

I don't have a strong opinion on that one. Fine either way with me.

In general keeping number of formats/conventions/required tools makes maintenance simpler.
Sounds aligned with the goal of this PR: reducing friction in devs processes.

(Feel free to dismiss my sporadic comments. As I no longer use the project my perception of right/wrong might be quite a bit off.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants