Skip to content

Commit 0da67c0

Browse files
committed
Modernize pre-commit: replace black with ruff, use isort with plone profile
- Replace black with ruff for linting and formatting - Keep isort for import sorting with plone profile and alphabetical rules - Configure ruff with line-length=120, target Python 3.10+ - Add ruff configuration with appropriate rule selections and ignores - Ignore F841 (unused variables) in tests directory - Fix compatibility issues: - Fix undefined s() function in svn.py (use stderr.decode()) - Fix undefined b() function in test_mercurial.py (use b":" literal) - Update pyproject.toml with ruff and isort configurations - Update Makefile (mxmake auto-updated qa.black -> qa.ruff) - Apply ruff-format and isort to all files This modernizes the tooling stack while keeping the project's code style consistent. Ruff provides faster linting/formatting and better Python 3.10+ support.
1 parent e6c086b commit 0da67c0

32 files changed

+785
-495
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
---
22
repos:
3-
- repo: https://github.com/psf/black.git
4-
rev: 24.2.0
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.8.4
55
hooks:
6-
- id: black
7-
language_version: python3
8-
exclude: ^(tests\/hooks-abort-render\/hooks|docs\/HelloCookieCutter1)
6+
# Run the linter
7+
- id: ruff
8+
args: [--fix]
9+
# Run the formatter
10+
- id: ruff-format
11+
12+
- repo: https://github.com/pycqa/isort
13+
rev: 5.13.2
14+
hooks:
15+
- id: isort
16+
args: [--profile, plone, --force-alphabetical-sort, --force-single-line, --lines-after-imports, "2"]
17+
additional_dependencies: [setuptools]
918

1019
- repo: https://github.com/pre-commit/mirrors-mypy
1120
rev: 'v1.9.0' # Use the sha / tag you want to point at

Makefile

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#: core.mxenv
77
#: core.mxfiles
88
#: core.packages
9-
#: qa.black
109
#: qa.isort
1110
#: qa.mypy
11+
#: qa.ruff
1212
#: qa.test
1313
#
1414
# SETTINGS (ALL CHANGES MADE BELOW SETTINGS WILL BE LOST)
@@ -94,17 +94,17 @@ MXDEV?=mxdev
9494
# Default: mxmake
9595
MXMAKE?=mxmake
9696

97-
## qa.isort
97+
## qa.ruff
9898

99-
# Source folder to scan for Python files to run isort on.
99+
# Source folder to scan for Python files to run ruff on.
100100
# Default: src
101-
ISORT_SRC?=src
101+
RUFF_SRC?=src
102102

103-
## qa.black
103+
## qa.isort
104104

105-
# Source folder to scan for Python files to run black on.
105+
# Source folder to scan for Python files to run isort on.
106106
# Default: src
107-
BLACK_SRC?=src
107+
ISORT_SRC?=src
108108

109109
## core.mxfiles
110110

@@ -263,6 +263,41 @@ INSTALL_TARGETS+=mxenv
263263
DIRTY_TARGETS+=mxenv-dirty
264264
CLEAN_TARGETS+=mxenv-clean
265265

266+
##############################################################################
267+
# ruff
268+
##############################################################################
269+
270+
RUFF_TARGET:=$(SENTINEL_FOLDER)/ruff.sentinel
271+
$(RUFF_TARGET): $(MXENV_TARGET)
272+
@echo "Install Ruff"
273+
@$(PYTHON_PACKAGE_COMMAND) install ruff
274+
@touch $(RUFF_TARGET)
275+
276+
.PHONY: ruff-check
277+
ruff-check: $(RUFF_TARGET)
278+
@echo "Run ruff check"
279+
@ruff check $(RUFF_SRC)
280+
281+
.PHONY: ruff-format
282+
ruff-format: $(RUFF_TARGET)
283+
@echo "Run ruff format"
284+
@ruff format $(RUFF_SRC)
285+
286+
.PHONY: ruff-dirty
287+
ruff-dirty:
288+
@rm -f $(RUFF_TARGET)
289+
290+
.PHONY: ruff-clean
291+
ruff-clean: ruff-dirty
292+
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y ruff || :
293+
@rm -rf .ruff_cache
294+
295+
INSTALL_TARGETS+=$(RUFF_TARGET)
296+
CHECK_TARGETS+=ruff-check
297+
FORMAT_TARGETS+=ruff-format
298+
DIRTY_TARGETS+=ruff-dirty
299+
CLEAN_TARGETS+=ruff-clean
300+
266301
##############################################################################
267302
# isort
268303
##############################################################################
@@ -297,40 +332,6 @@ FORMAT_TARGETS+=isort-format
297332
DIRTY_TARGETS+=isort-dirty
298333
CLEAN_TARGETS+=isort-clean
299334

300-
##############################################################################
301-
# black
302-
##############################################################################
303-
304-
BLACK_TARGET:=$(SENTINEL_FOLDER)/black.sentinel
305-
$(BLACK_TARGET): $(MXENV_TARGET)
306-
@echo "Install Black"
307-
@$(PYTHON_PACKAGE_COMMAND) install black
308-
@touch $(BLACK_TARGET)
309-
310-
.PHONY: black-check
311-
black-check: $(BLACK_TARGET)
312-
@echo "Run black checks"
313-
@black --check $(BLACK_SRC)
314-
315-
.PHONY: black-format
316-
black-format: $(BLACK_TARGET)
317-
@echo "Run black format"
318-
@black $(BLACK_SRC)
319-
320-
.PHONY: black-dirty
321-
black-dirty:
322-
@rm -f $(BLACK_TARGET)
323-
324-
.PHONY: black-clean
325-
black-clean: black-dirty
326-
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y black || :
327-
328-
INSTALL_TARGETS+=$(BLACK_TARGET)
329-
CHECK_TARGETS+=black-check
330-
FORMAT_TARGETS+=black-format
331-
DIRTY_TARGETS+=black-dirty
332-
CLEAN_TARGETS+=black-clean
333-
334335
##############################################################################
335336
# mxfiles
336337
##############################################################################

0 commit comments

Comments
 (0)