Repository navigation
Replace black, isort, flake8 and pyupgrade with ruff - #278
Draft
zigpy-review-bot wants to merge 2 commits into
Draft
zigpy-review-bot wants to merge 2 commits into
zigpy-review-bot wants to merge 2 commits into
Conversation
Autofixes: ruff format output (lowercase hex escapes, joined implicit string concatenations, blank line after module docstrings), C416, B011 and single-line merges of nested `with` statements. By hand: exception chaining for re-raised errors, SIM103 in is_usb_serial_port, SIM114 merging two identical branches in DeconzAddressEndpoint.serialize, and dropping the dead Python < 3.8 branch in tests/async_mock.py (UP036). SIM117 is ignored in tests where merging the `with` statements needs parenthesized context managers, which requires-python >= 3.8 does not allow.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #278 +/- ##
==========================================
- Coverage 99.14% 99.13% -0.01%
==========================================
Files 7 7
Lines 933 929 -4
==========================================
- Hits 925 921 -4
Misses 8 8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pre-commit runfails on Python 3.14. The pinnedpyupgradev3.3.1 crashes on import withAttributeError: module 'ast' has no attribute 'Str': 3.14 removed the long-deprecatedast.Stralias, and the first unaffected pyupgrade is v3.4.0. This is the same problem zigpy/bellows#759 fixed in bellows. CI does not catch it because the shared pre-commit job runs on Python 3.11.Changes
Rather than bumping
pyupgradealone, this replaces the black / isort / flake8 / autoflake / pyupgrade stack with ruff.ruff-check+ruff-format(ruff-pre-commit v0.16.9).codespellgoes from v2.3.0 to v2.4.3.[tool.isort]and[tool.flake8]become[tool.ruff]. The rules areB, C, E, F, I, SIM, UP, W, the set zigpy-znp uses, plusDwith thepep257convention and the same docstring ignores thatflake8-docstringshad.E501stays ignored and thetests/*per-file ignores carry over.target-version = "py38"matchesrequires-python = ">=3.8". That floor meansSIM117has to be ignored intests/*: merging those nestedwithstatements needs parenthesized context managers, which are not Python 3.8 syntax.requirements_test.txt: dropisort,black,flake8andFlake8-pyproject, and bumpruff==0.0.261toruff==0.16.9to match the hook.python.json.is_usb_serial_port, merging two identical branches inDeconzAddressEndpoint.serialize(SIM114), and dropping the dead Python < 3.8 branch intests/async_mock.py.Not changed here
requires-python = ">=3.8"andzigpy>=0.80.0look stale. zigpy 0.80.0 itself requires Python 3.9, and the CI matrix is 3.11 to 3.14. Raising the floor would let ruff apply the 3.11 rewrites and drop theSIM117exception, but it is a packaging change, so it is left for a separate decision.Verification
pre-commit run --all-filespasses on Python 3.14. Ondevthe pyupgrade hook crashes.dev.Context
This is one of a set of draft PRs that align the pre-commit setup of the zigpy libraries on ruff (
ruff check+ruff format), which zigpy, zha, zha-device-handlers, zigpy-znp, zigpy-ota and zigpy-ziggurat already use. The same change is proposed for bellows, zigpy-deconz, zigpy-xbee, zigpy-zigate and zigpy-cli, plus small ruff config fixes in zigpy and zigpy-ziggurat.The commits are kept separate so parts can be dropped or moved into their own PR. Maintainers can ask the bot for that, or for any other change, by commenting
@zigpy-review-bot <request>on this PR.