Skip to content

Commit

Permalink
Use Ruff as linter and formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ankandrew committed Mar 7, 2024
1 parent 7158146 commit bd549dd
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 407 deletions.
44 changes: 20 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
# Directories
SRC_DIRS := src/ test/ # FIXME
SRC_DIRS := project_name/ test/ # FIXME

# Tasks
.PHONY: help
help:
@echo "Available targets:"
@echo " format : Format code using Black and isort"
@echo " check_format : Check code formatting with Black and isort"
@echo " lint : Run pylint and Mypy for static code analysis"
@echo " format : Format code using Ruff format"
@echo " check_format : Check code formatting with Ruff format"
@echo " lint : Run Ruff linter and Mypy for static code analysis"
@echo " test : Run tests using pytest"
@echo " clean : Clean up caches and build artifacts"
@echo " run_local_checks : Run format, lint, and test"
@echo " help : Show this help message"

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

.PHONY: check_format
check_format:
@echo "==> Checking format..."
@poetry run black --check --diff $(SRC_DIRS)
@echo "==> Checking isort..."
@poetry run isort --check --diff $(SRC_DIRS)
@echo "=====> Checking format..."
@poetry run ruff format --check --diff $(SRC_DIRS)
@echo "=====> Checking imports are sorted..."
@poetry run ruff check --select I --exit-non-zero-on-fix $(SRC_DIRS)


.PHONY: lint
lint:
@echo "==> Running pylint..."
@poetry run pylint $(SRC_DIRS)
@echo "==> Running Mypy..."
@echo "=====> Running Ruff linter..."
@poetry run ruff check $(SRC_DIRS)
@echo "=====> Running Mypy..."
@poetry run mypy $(SRC_DIRS)

.PHONY: test
test:
@echo "==> Running tests..."
@echo "=====> Running tests..."
@poetry run pytest

.PHONY: clean
clean:
@echo "==> Cleaning caches..."
@find ./ -name '*.pyc' -exec rm -f {} \;
@find ./ -name '__pycache__' -exec rm -rf {} \;
@rm -rf .cache
@rm -rf .pytest_cache
@rm -rf .mypy_cache
@rm -rf build
@rm -rf dist
@rm -rf *.egg-info
@echo "=====> Cleaning caches..."
@poetry run ruff clean
@rm -rf .cache .pytest_cache .mypy_cache build dist *.egg-info

run_local_checks: format lint test
Loading

0 comments on commit bd549dd

Please sign in to comment.