Skip to content

Commit

Permalink
👷(backend) use astral-sh/ruff to make linting faster and simpler
Browse files Browse the repository at this point in the history
Introduce ruff and use it to replace isort, flake8, pycodestyle and
bandit by configuring it through pyproject.toml

This change might not be iso but should be close and brings a
considerable speed improvement to the make lint command

Not all checks have been activated in the config file so we can still
make ruff stricter.

The fix flag is set to true and ruff will (apparently aggressively) fix
the violations. This behavior can be tamed via the unfixable config
entry
  • Loading branch information
lebrunthibault committed Jun 21, 2023
1 parent 275aea8 commit aa9c2a4
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 550 deletions.
21 changes: 2 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,14 @@ jobs:
- restore_cache:
keys:
- v1-dependencies-python:3.11-{{ .Revision }}
- run:
name: Lint code with flake8
command: ~/.local/bin/flake8 --toml-config core/pyproject.toml core plugins
working_directory: src/backend
- run:
name: Lint code with isort
command: ~/.local/bin/isort --recursive --check-only --settings-file core/pyproject.toml core plugins
working_directory: src/backend
- run:
name: Lint code with black
command: ~/.local/bin/black --check --config core/pyproject.toml core plugins
working_directory: src/backend
- run:
name: Lint code with pylint
command: ~/.local/bin/pylint core plugins
name: Lint code with ruff
command: ~/.local/bin/ruff --config core/pyproject.toml core plugins
working_directory: src/backend
- run:
name: Lint code with bandit
command: ~/.local/bin/bandit -c core/pyproject.toml -qr core/warren plugins
working_directory: src/backend
- run:
name: Lint code with pydocstyle
command: ~/.local/bin/pydocstyle --config core/pyproject.toml core plugins
working_directory: src/backend

test-backend:
parameters:
python-image:
Expand Down
41 changes: 10 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,10 @@ fixtures: \


# -- Linters
#
# Nota bene: Black should come after isort just in case they don't agree...
lint: ## lint backend python sources
lint: \
lint-isort \
lint-black \
lint-flake8 \
lint-pylint \
lint-bandit \
lint-pydocstyle \
lint-ruff \
lint-frontend
.PHONY: lint

Expand All @@ -195,30 +189,15 @@ lint-black: ## lint backend python sources with black
@$(COMPOSE_RUN_BACKEND) black --config core/pyproject.toml core plugins
.PHONY: lint-black

lint-flake8: ## lint backend python sources with flake8
@echo 'lint:flake8 started…'
@$(COMPOSE_RUN_BACKEND) flake8 --toml-config core/pyproject.toml core plugins
.PHONY: lint-flake8

lint-isort: ## automatically re-arrange python imports in backend code base
@echo 'lint:isort started…'
@$(COMPOSE_RUN_BACKEND) isort --settings-file core/pyproject.toml --atomic core plugins
.PHONY: lint-isort

lint-pylint: ## lint backend python sources with pylint
@echo 'lint:pylint started…'
@$(COMPOSE_RUN_BACKEND) pylint core plugins
.PHONY: lint-pylint

lint-bandit: ## lint backend python sources with bandit
@echo 'lint:bandit started…'
@$(COMPOSE_RUN_BACKEND) bandit -c core/pyproject.toml -qr core/warren plugins
.PHONY: lint-bandit

lint-pydocstyle: ## lint Python docstrings with pydocstyle
@echo 'lint:pydocstyle started…'
@$(COMPOSE_RUN_BACKEND) pydocstyle --config core/pyproject.toml core plugins
.PHONY: lint-pydocstyle
lint-ruff: ## lint backend python sources with ruff
@echo 'lint:ruff started…'
@$(COMPOSE_RUN_BACKEND) ruff --config core/pyproject.toml core plugins
.PHONY: lint-ruff

lint-ruff-fix: ## lint and fix backend python sources with ruff
@echo 'lint:ruff-fix started…'
@$(COMPOSE_RUN_BACKEND) ruff --config core/pyproject.toml core plugins --fix
.PHONY: lint-ruff-fix

### Frontend ###

Expand Down
Loading

0 comments on commit aa9c2a4

Please sign in to comment.