-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add use_ruff option to replace isort, black, flake8, pyupgrade #333
Copy link
Copy link
Open
Description
Summary
Add a [meta] use_ruff = true toggle in .meta.toml that switches from the current tool stack (isort + black + flake8 + pyupgrade) to ruff. Default keeps old tools; switch on = modern ruff setup.
Ruff replaces: isort, black, flake8, pyupgrade
Ruff does NOT replace: zpretty, codespell, check-manifest, pyroma, check-python-versions, i18ndude
The shared CI workflow (backend-lint.yml) already uses ruff, so this aligns generated packages with CI.
Implementation plan
Files to modify
1. src/plone/meta/config_package.py — Core logic
- Add
use_ruffcached_property reading[meta] use_ruff(defaultFalse) - Add
_warn_ruff_incompatible_options()— warn ifblack_extra_lines,isort_extra_lines,flake8_extra_lines, or[flake8] extra_linesare set when ruff is active pre_commit_config()— passuse_ruffto template contextpyproject_toml()— addruff_extra_linesto options list, passuse_rufftox()— passuse_ruffto template contextflake8()— skip generation (returnNone) whenuse_ruff=True;git rm .flake8if it exists from a prior runwarn_on_setup_cfg()— only warn about[flake8]section when not using ruffconfigure()— call_warn_ruff_incompatible_options()early
2. src/plone/meta/default/pre-commit-config.yaml.j2 — Pre-commit hooks
Wrap in {% if use_ruff %} / {% else %}:
- ruff path: single
ruff-pre-commitrepo withruff-format+ruff(args:[--fix]) hooks - old path: pyupgrade, isort, black (unchanged)
- zpretty stays unconditional
- flake8 block wrapped in
{% if not use_ruff %} - codespell, check-manifest, pyroma, check-python-versions, i18ndude stay unconditional
3. src/plone/meta/default/pyproject.toml.j2 — Tool config
Wrap in {% if use_ruff %} / {% else %}:
- ruff path:
[tool.ruff],[tool.ruff.lint](select F/E/W/UP/I, ignore E501/E203),[tool.ruff.lint.isort]with Plone-style settings, plus%(ruff_extra_lines)s - old path:
[tool.isort]+[tool.black](unchanged) [tool.check-manifest] ignore— make.flake8entry conditional on{% if not use_ruff %}
4. src/plone/meta/default/tox-qa.j2 — Tox format env
Wrap format commands in {% if use_ruff %} / {% else %}:
- ruff path:
pre-commit run -a ruff-format,pre-commit run -a ruff - old path:
pre-commit run -a pyupgrade,pre-commit run -a isort,pre-commit run -a black pre-commit run -a zprettystays unconditional
5. Documentation updates
docs/sources/reference/meta-toml.md— Documentuse_ruffin[meta]section +ruff_extra_linesin[pyproject]sectiondocs/sources/reference/generated-files.md— Note.flake8is conditional; update.pre-commit-config.yamlandpyproject.tomldescriptionsdocs/sources/reference/tox-environments.md— Update format env description
Ruff config defaults
When use_ruff = true, pyproject.toml will include:
[tool.ruff]
target-version = "py310"
[tool.ruff.lint]
select = [
# pyflakes
"F",
# pycodestyle
"E",
"W",
# pyupgrade
"UP",
# isort
"I",
]
ignore = [
# line too long (formatter handles this)
"E501",
# whitespace before ':' (formatter handles slicing)
"E203",
]
[tool.ruff.lint.isort]
force-single-line = true
from-first = true
lines-after-imports = 2
lines-between-types = 1
no-sections = true
order-by-type = falseRationale for lint rules
F+E+W= flake8 core (pyflakes + pycodestyle) — matches current flake8 setupUP= pyupgrade — replaces the standalone pyupgrade pre-commit hookI= isort — replaces standalone isortE501ignored: ruff format handles line length (same as current flake8 config)E203ignored: ruff format handles whitespace in slicing (same as current flake8)W503does not exist in ruff, omittedE231handled by ruff format, omitted from ignore
Rationale for isort settings (matching Plone conventions)
force-single-line = true— one import per line (from isort plone profile)from-first = true—fromimports before regularimportstatementslines-after-imports = 2— two blank lines after import blocklines-between-types = 1— one blank line betweenimportandfromtypesno-sections = true— no section separation, results in pure alphabetical sort (replaces isort'sforce_alphabetical_sort)order-by-type = false— don't group by CONSTANT/Class/variable type
These settings are user-configurable via ruff_extra_lines in [pyproject].
Verification
- Run
config-packageon a test repo withoutuse_ruff— confirm no changes to existing behavior - Run
config-packageon a test repo with[meta] use_ruff = true— verify:.pre-commit-config.yamlhas ruff hooks, no pyupgrade/isort/black/flake8pyproject.tomlhas[tool.ruff], no[tool.isort]/[tool.black].flake8is not generated (removed if existed)tox.iniformat env uses ruff commands
- Run
tox -e formatandtox -e lintin the test repo to confirm ruff works
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels