Skip to content

Commit bd549dd

Browse files
committed
Use Ruff as linter and formatter
1 parent 7158146 commit bd549dd

3 files changed

Lines changed: 104 additions & 407 deletions

File tree

Makefile

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
11
# Directories
2-
SRC_DIRS := src/ test/ # FIXME
2+
SRC_DIRS := project_name/ test/ # FIXME
33

44
# Tasks
55
.PHONY: help
66
help:
77
@echo "Available targets:"
8-
@echo " format : Format code using Black and isort"
9-
@echo " check_format : Check code formatting with Black and isort"
10-
@echo " lint : Run pylint and Mypy for static code analysis"
8+
@echo " format : Format code using Ruff format"
9+
@echo " check_format : Check code formatting with Ruff format"
10+
@echo " lint : Run Ruff linter and Mypy for static code analysis"
1111
@echo " test : Run tests using pytest"
1212
@echo " clean : Clean up caches and build artifacts"
1313
@echo " run_local_checks : Run format, lint, and test"
1414
@echo " help : Show this help message"
1515

1616
.PHONY: format
1717
format:
18-
@echo "==> Formatting code..."
19-
@poetry run black $(SRC_DIRS)
2018
@echo "==> Sorting imports..."
21-
@poetry run isort $(SRC_DIRS)
19+
@# Currently, the Ruff formatter does not sort imports, see https://docs.astral.sh/ruff/formatter/#sorting-imports
20+
@poetry run ruff check --select I --fix $(SRC_DIRS)
21+
@echo "=====> Formatting code..."
22+
@poetry run ruff format $(SRC_DIRS)
2223

2324
.PHONY: check_format
2425
check_format:
25-
@echo "==> Checking format..."
26-
@poetry run black --check --diff $(SRC_DIRS)
27-
@echo "==> Checking isort..."
28-
@poetry run isort --check --diff $(SRC_DIRS)
26+
@echo "=====> Checking format..."
27+
@poetry run ruff format --check --diff $(SRC_DIRS)
28+
@echo "=====> Checking imports are sorted..."
29+
@poetry run ruff check --select I --exit-non-zero-on-fix $(SRC_DIRS)
30+
2931

3032
.PHONY: lint
3133
lint:
32-
@echo "==> Running pylint..."
33-
@poetry run pylint $(SRC_DIRS)
34-
@echo "==> Running Mypy..."
34+
@echo "=====> Running Ruff linter..."
35+
@poetry run ruff check $(SRC_DIRS)
36+
@echo "=====> Running Mypy..."
3537
@poetry run mypy $(SRC_DIRS)
3638

3739
.PHONY: test
3840
test:
39-
@echo "==> Running tests..."
41+
@echo "=====> Running tests..."
4042
@poetry run pytest
4143

4244
.PHONY: clean
4345
clean:
44-
@echo "==> Cleaning caches..."
45-
@find ./ -name '*.pyc' -exec rm -f {} \;
46-
@find ./ -name '__pycache__' -exec rm -rf {} \;
47-
@rm -rf .cache
48-
@rm -rf .pytest_cache
49-
@rm -rf .mypy_cache
50-
@rm -rf build
51-
@rm -rf dist
52-
@rm -rf *.egg-info
46+
@echo "=====> Cleaning caches..."
47+
@poetry run ruff clean
48+
@rm -rf .cache .pytest_cache .mypy_cache build dist *.egg-info
5349

5450
run_local_checks: format lint test

0 commit comments

Comments
 (0)