Skip to content

Commit 850f8eb

Browse files
authored
Merge pull request #62 from mxstack/feature/ruff-check-fix-61
Add optional ruff check --fix support to ruff-format target
2 parents 29e6950 + f07d054 commit 850f8eb

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 2.2.0
44

5+
- Feature: Add optional `ruff check --fix` support to ruff-format target
6+
[jensens, 2025-11-11]
57
- Feature: Add `qa.ty` domain for Astral's ty type checker.
68
ty is an extremely fast Python type checker (10-100x faster than mypy).
79
Registers with both CHECK_TARGETS and TYPECHECK_TARGETS for fast feedback.

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ MXMAKE?=-e .
109109
# Default: src
110110
RUFF_SRC?=src
111111

112+
# Enable ruff check --fix when running ruff-format.
113+
# Set to `true` to enable automatic fixes.
114+
# Default: false
115+
RUFF_FIXES?=false
116+
117+
# Enable unsafe fixes when RUFF_FIXES is enabled.
118+
# Set to `true` to enable unsafe fixes.
119+
# Default: false
120+
RUFF_UNSAFE_FIXES?=false
121+
122+
## qa.isort
123+
124+
# Source folder to scan for Python files to run isort on.
125+
# Default: src
126+
ISORT_SRC?=src
127+
112128
## docs.sphinx
113129

114130
# Documentation source folder.
@@ -338,6 +354,15 @@ ifeq ($(RUFF_SRC),src)
338354
RUFF_SRC:=$(PYTHON_PROJECT_PREFIX)src
339355
endif
340356

357+
# Build ruff check flags based on settings
358+
ifeq ("$(RUFF_FIXES)","true")
359+
ifeq ("$(RUFF_UNSAFE_FIXES)","true")
360+
RUFF_FIX_FLAGS=--fix --unsafe-fixes
361+
else
362+
RUFF_FIX_FLAGS=--fix
363+
endif
364+
endif
365+
341366
RUFF_TARGET:=$(SENTINEL_FOLDER)/ruff.sentinel
342367
$(RUFF_TARGET): $(MXENV_TARGET)
343368
@echo "Install Ruff"
@@ -353,6 +378,10 @@ ruff-check: $(RUFF_TARGET)
353378
ruff-format: $(RUFF_TARGET)
354379
@echo "Run ruff format"
355380
@ruff format $(RUFF_SRC)
381+
ifeq ("$(RUFF_FIXES)","true")
382+
@echo "Run ruff check $(RUFF_FIX_FLAGS)"
383+
@ruff check $(RUFF_FIX_FLAGS) $(RUFF_SRC)
384+
endif
356385

357386
.PHONY: ruff-dirty
358387
ruff-dirty:

src/mxmake/tests/test_topics.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ def test_get_domain(self):
9090
domain = topics.get_domain("core.mxenv")
9191
self.assertEqual(domain.fqn, "core.mxenv")
9292

93+
def test_ruff_domain_settings(self):
94+
"""Test ruff domain has correct settings for check --fix feature."""
95+
domain = topics.get_domain("qa.ruff")
96+
self.assertEqual(domain.fqn, "qa.ruff")
97+
98+
settings = {s.name: s for s in domain.settings}
99+
100+
# Verify RUFF_FIXES setting
101+
self.assertIn("RUFF_FIXES", settings)
102+
ruff_fixes = settings["RUFF_FIXES"]
103+
self.assertEqual(ruff_fixes.default, "false")
104+
self.assertIn("ruff check --fix", ruff_fixes.description)
105+
106+
# Verify RUFF_UNSAFE_FIXES setting
107+
self.assertIn("RUFF_UNSAFE_FIXES", settings)
108+
ruff_unsafe = settings["RUFF_UNSAFE_FIXES"]
109+
self.assertEqual(ruff_unsafe.default, "false")
110+
self.assertIn("unsafe fixes", ruff_unsafe.description)
111+
112+
# Verify RUFF_SRC setting still exists
113+
self.assertIn("RUFF_SRC", settings)
114+
93115
@testing.temp_directory
94116
def test_Domain(self, tmpdir):
95117
domain_path = tmpdir / "domain.mk"

src/mxmake/topics/qa/ruff.mk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@
66
#:[target.ruff]
77
#:description = Run ruff.
88
#:
9+
#:[target.ruff-format]
10+
#:description = Run ruff format. Optionally apply fixes with RUFF_FIXES=true.
11+
#:
912
#:[setting.RUFF_SRC]
1013
#:description = Source folder to scan for Python files to run ruff on.
1114
#:default = src
1215
#:
16+
#:[setting.RUFF_FIXES]
17+
#:description = Enable ruff check --fix when running ruff-format.
18+
#: Set to `true` to enable automatic fixes.
19+
#:default = false
20+
#:
21+
#:[setting.RUFF_UNSAFE_FIXES]
22+
#:description = Enable unsafe fixes when RUFF_FIXES is enabled.
23+
#: Set to `true` to enable unsafe fixes.
24+
#:default = false
25+
#:
1326
#:[target.ruff-dirty]
1427
#:description = Marks ruff dirty
1528
#:
@@ -25,6 +38,15 @@ ifeq ($(RUFF_SRC),src)
2538
RUFF_SRC:=$(PYTHON_PROJECT_PREFIX)src
2639
endif
2740

41+
# Build ruff check flags based on settings
42+
ifeq ("$(RUFF_FIXES)","true")
43+
ifeq ("$(RUFF_UNSAFE_FIXES)","true")
44+
RUFF_FIX_FLAGS=--fix --unsafe-fixes
45+
else
46+
RUFF_FIX_FLAGS=--fix
47+
endif
48+
endif
49+
2850
RUFF_TARGET:=$(SENTINEL_FOLDER)/ruff.sentinel
2951
$(RUFF_TARGET): $(MXENV_TARGET)
3052
@echo "Install Ruff"
@@ -40,6 +62,10 @@ ruff-check: $(RUFF_TARGET)
4062
ruff-format: $(RUFF_TARGET)
4163
@echo "Run ruff format"
4264
@ruff format $(RUFF_SRC)
65+
ifeq ("$(RUFF_FIXES)","true")
66+
@echo "Run ruff check $(RUFF_FIX_FLAGS)"
67+
@ruff check $(RUFF_FIX_FLAGS) $(RUFF_SRC)
68+
endif
4369

4470
.PHONY: ruff-dirty
4571
ruff-dirty:

0 commit comments

Comments
 (0)