Skip to content

Replace black/isort/flake8 with ruff, migrate to uv/pyproject.toml#927

Merged
ic-dev21 merged 8 commits intodvd-dev:mainfrom
halfguru:chore/uv-ruff-migration
Apr 10, 2026
Merged

Replace black/isort/flake8 with ruff, migrate to uv/pyproject.toml#927
ic-dev21 merged 8 commits intodvd-dev:mainfrom
halfguru:chore/uv-ruff-migration

Conversation

@halfguru
Copy link
Copy Markdown
Contributor

@halfguru halfguru commented Apr 6, 2026

Motivation

Why ruff?

  • Replaces 3 tools (black, isort, flake8) + their plugins (flake8-docstrings, pydocstyle) with a single, fast Rust-based tool
  • 10-100x faster than the Python-based tools it replaces
  • Actively maintained with a large community and growing ecosystem

Why uv?

  • Replaces pip + requirements.txt with a modern, fast Python package manager
  • pyproject.toml is the modern standard (PEP 621), consolidates setup.cfg, requirements.txt, requirements_test.txt into one file
  • Deterministic installs with uv.lock

Summary

  • Replace black, isort, and flake8 with ruff (formatter + linter) via ruff-pre-commit in .pre-commit-config.yaml
  • Add pyproject.toml with full PEP 621 metadata, replacing setup.cfg, requirements.txt, and requirements_test.txt
  • Update devcontainer and CI to use uv for dependency management (Python 3.14)
  • Update dev scripts (scripts/setup, scripts/setup_commit_hook.sh) to use uv sync --group test
  • Fix stale test mocks for python-hilo>=2026.3.5 API changes (get_devicesget_device_cache/wait_for_device_cache/get_location_ids/get_gateway)

Removed files

  • setup.cfg: migrated to pyproject.toml
  • .flake8.yml: migrated to pyproject.toml
  • requirements.txt: replaced by [project.dependencies] in pyproject.toml
  • requirements_test.txt : replaced by [project.optional-dependencies] in pyproject.toml

halfguru added 2 commits April 6, 2026 17:00
- Replace black, isort, and flake8 with ruff (formatter + linter) in
  pre-commit config
- Add pyproject.toml with full PEP 621 metadata (replaces setup.cfg)
- Delete requirements.txt, requirements_test.txt, setup.cfg
- Update Dockerfile.dev for Python 3.14 and uv
- Update CI workflow to use uv setup action
- Update dev scripts to use uv sync
- Update README and CONTRIBUTING docs (black -> ruff references)
- Fix stale test mocks for python-hilo>=2026.3.5 API changes
- Update snapshot for newer HA entity registry schema
@ic-dev21
Copy link
Copy Markdown
Collaborator

ic-dev21 commented Apr 6, 2026

Thank you for your contribution. I think pre-commit fails from not being explicitely installed?

@halfguru halfguru force-pushed the chore/uv-ruff-migration branch from 57bd4ce to 1a5bf12 Compare April 6, 2026 21:33
@halfguru
Copy link
Copy Markdown
Contributor Author

halfguru commented Apr 6, 2026

Thank you for your contribution. I think pre-commit fails from not being explicitely installed?

Yeah, sorry for that, didn't test this locally. It should work now with uv command

@ic-dev21
Copy link
Copy Markdown
Collaborator

ic-dev21 commented Apr 6, 2026

Thank you for your contribution. I think pre-commit fails from not being explicitely installed?

Yeah, sorry for that, didn't test this locally. It should work now with uv command

Will test this locally, I'm not a dev at all and I'm still learning as I go. I do know we had a ruff dependency but I'm pretty sure the way it is currently setup it wasn't being used at all.

@halfguru
Copy link
Copy Markdown
Contributor Author

halfguru commented Apr 7, 2026

Thank you for your contribution. I think pre-commit fails from not being explicitely installed?

Yeah, sorry for that, didn't test this locally. It should work now with uv command

Will test this locally, I'm not a dev at all and I'm still learning as I go. I do know we had a ruff dependency but I'm pretty sure the way it is currently setup it wasn't being used at all.

To give you more context, ruff has become the industry standard for Python linting and formatting. It replaces black, isort and flake8. It's used by major projects like FastAPI, Pandas, Django, etc. Same for uv, modern replacement for pip which is much faster. See the links below that explains how they achieve their higher performance:

Home Assistant itself also is migrating to both their dev guidelines I believe:

Another Quebec-based HA integration, https://github.com/hydroqc/hydroqc-ha, also uses ruff and uv if you'd like to see a similar setup in practice. Let me know if you have more questions!

@ic-dev21
Copy link
Copy Markdown
Collaborator

ic-dev21 commented Apr 7, 2026

Thank you for your contribution. I think pre-commit fails from not being explicitely installed?

Yeah, sorry for that, didn't test this locally. It should work now with uv command

Will test this locally, I'm not a dev at all and I'm still learning as I go. I do know we had a ruff dependency but I'm pretty sure the way it is currently setup it wasn't being used at all.

To give you more context, ruff has become the industry standard for Python linting and formatting. It replaces black, isort and flake8. It's used by major projects like FastAPI, Pandas, Django, etc. Same for uv, modern replacement for pip which is much faster. See the links below that explains how they achieve their higher performance:

Home Assistant itself also is migrating to both their dev guidelines I believe:

Another Quebec-based HA integration, https://github.com/hydroqc/hydroqc-ha, also uses ruff and uv if you'd like to see a similar setup in practice. Let me know if you have more questions!

I genuinely appreciate you taking the time to explain (I'm fine with either french or english by the way, if you have any preferences). We do also have the python-hilo library that does the API stuff in the background that probably would benefit from a similar treatment. Time is somewhat tight this week but I'm very interested in learning more about all of this. I'm guessing I will also need to modify dependabot and maybe others?

- Delete requirements.txt and requirements_test.txt (restored by mistake)
- Update dependabot.yml: pip -> uv ecosystem
- Remove stale pip pin from constraints.txt
- Update CONTRIBUTING.md: pip install -> uv pip install
- Update .vscode/tasks.json: use uv run for pytest and pre-commit
@halfguru
Copy link
Copy Markdown
Contributor Author

halfguru commented Apr 7, 2026

Thank you for your contribution. I think pre-commit fails from not being explicitely installed?

Yeah, sorry for that, didn't test this locally. It should work now with uv command

Will test this locally, I'm not a dev at all and I'm still learning as I go. I do know we had a ruff dependency but I'm pretty sure the way it is currently setup it wasn't being used at all.

To give you more context, ruff has become the industry standard for Python linting and formatting. It replaces black, isort and flake8. It's used by major projects like FastAPI, Pandas, Django, etc. Same for uv, modern replacement for pip which is much faster. See the links below that explains how they achieve their higher performance:

Home Assistant itself also is migrating to both their dev guidelines I believe:

Another Quebec-based HA integration, https://github.com/hydroqc/hydroqc-ha, also uses ruff and uv if you'd like to see a similar setup in practice. Let me know if you have more questions!

I genuinely appreciate you taking the time to explain (I'm fine with either french or english by the way, if you have any preferences). We do also have the python-hilo library that does the API stuff in the background that probably would benefit from a similar treatment. Time is somewhat tight this week but I'm very interested in learning more about all of this. I'm guessing I will also need to modify dependabot and maybe others?

Pas de problème! Je peux jeter un coup d'oeil à python-hilo. Je viens de re-faire un tour dans ma PR pour d'autres éléments manquants pour la migration et j'ai commit d'autres changements incluant dependabot.

ic-dev21 added 2 commits April 8, 2026 18:52
Going back to python 3.12 to maintain some backward compatibility to about 2 years. This will make sure users on older HA versions can still run the component.
Il m'en manquait 1.
@ic-dev21
Copy link
Copy Markdown
Collaborator

ic-dev21 commented Apr 8, 2026

@halfguru salut, j'ai joué un peu dans tes plates-bandes. Tu en penses quoi?

Add the correct classifiers
@halfguru
Copy link
Copy Markdown
Contributor Author

halfguru commented Apr 9, 2026

@halfguru salut, j'ai joué un peu dans tes plates-bandes. Tu en penses quoi?

LGTM

Copy link
Copy Markdown
Collaborator

@ic-dev21 ic-dev21 left a comment

Choose a reason for hiding this comment

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

#YOLO

@ic-dev21 ic-dev21 merged commit 5a4bb98 into dvd-dev:main Apr 10, 2026
3 checks passed
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