Skip to content

Commit

Permalink
Switch to ruff for flake8 / isort code checking (wagtail#10324)
Browse files Browse the repository at this point in the history
  • Loading branch information
ollz272 authored and gasman committed Apr 21, 2023
1 parent 5b20ae5 commit 459fbb2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 52 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
key: pipenv-v1-{{ checksum "setup.py" }}
paths:
- .venv
- run: pipenv run flake8
- run: pipenv run isort --check-only --diff .
- run: pipenv run ruff check .
- run: pipenv run black --target-version py37 --check --diff .
- run: pipenv run semgrep --config .semgrep.yml --error .
- run: git ls-files '*.html' | xargs pipenv run djhtml --check
Expand Down
21 changes: 8 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ repos:
- id: black
language_version: python3
args: ['--target-version', 'py37']
- repo: https://github.com/timothycrosley/isort
# isort config is in setup.cfg
rev: 5.6.4
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
# flake8 config is in setup.cfg
rev: 3.8.4
hooks:
- id: flake8
additional_dependencies:
- flake8-comprehensions
- flake8-assertive

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.261'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
help:
@echo "clean-pyc - remove Python file artifacts"
@echo "develop - install development dependencies"
@echo "lint - check style with black, flake8, sort python with isort, indent html, and lint frontend css/js"
@echo "format - enforce a consistent code style across the codebase, sort python files with isort and fix frontend css/js"
@echo "lint - check style with black, ruff, sort python with ruff, indent html, and lint frontend css/js"
@echo "format - enforce a consistent code style across the codebase, sort python files with ruff and fix frontend css/js"
@echo "test - run tests"
@echo "coverage - check code coverage"

Expand All @@ -19,8 +19,7 @@ develop: clean-pyc

lint-server:
black --target-version py37 --check --diff .
flake8
isort --check-only --diff .
ruff check .
semgrep --config .semgrep.yml --error .
curlylint --parse-only wagtail
git ls-files '*.html' | xargs djhtml --check
Expand All @@ -37,7 +36,7 @@ lint: lint-server lint-client lint-docs

format-server:
black --target-version py37 .
isort .
ruff check . --fix
git ls-files '*.html' | xargs djhtml -i

format-client:
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/python_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ run by `pre-commit` if that is configured.
a text editor with [EditorConfig](https://editorconfig.org/) support to avoid indentation and
whitespace issues. Python and HTML files use 4 spaces for indentation.

In addition, import lines should be sorted according to [isort](https://pycqa.github.io/isort/) 5.6.4 rules.
In addition, import lines should be sorted according to [isort](https://pycqa.github.io/isort/) rules.
If you have installed Wagtail's testing dependencies (`pip install -e '.[testing]'`), you can check your code by
running `make lint`. You can also just check python related linting by running `make lint-server`.

Expand Down
10 changes: 10 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# D100: Missing docstring in public module
# D101: Missing docstring in public class
# D102: Missing docstring in public method
# D103: Missing docstring in public function
# D105: Missing docstring in magic method
# N806: Variable in function should be lowercase
# E501: Line too long
ignore = ["D100","D101","D102","D103","D105","N806","E501"]
exclude = ["wagtail/project_template/*","node_modules","venv",".venv"]
line-length = 88
21 changes: 0 additions & 21 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
[bdist_wheel]
python-tag = py3

[flake8]
# D100: Missing docstring in public module
# D101: Missing docstring in public class
# D102: Missing docstring in public method
# D103: Missing docstring in public function
# D105: Missing docstring in magic method
# W503: line break before binary operator (superseded by W504 line break after binary operator)
# N806: Variable in function should be lowercase
# E203: Whitespace before ':'
# E501: Line too long
ignore = D100,D101,D102,D103,D105,W503,N806,E203,E501
exclude = wagtail/project_template/*,node_modules,venv,.venv
max-line-length = 88

[doc8]
ignore = D001
ignore-path = _build,docs/_build

[isort]
profile = black
skip=migrations,project_template,node_modules,.git,__pycache__,LC_MESSAGES,venv,.venv,.tox
blocked_extensions=rst,html,js,svg,txt,css,scss,png,snap,ts,tsx
known_first_party=wagtail
default_section=THIRDPARTY

[tool:pytest]
django_find_project = false
python_files=test_*.py
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@
# For coverage and PEP8 linting
"coverage>=3.7.0",
"black==22.3.0",
"flake8>=3.6.0",
"isort==5.6.4", # leave this pinned - it tends to change rules between patch releases
"flake8-blind-except==0.1.1",
"flake8-comprehensions==3.8.0",
"flake8-print==5.0.0",
"doc8==0.8.1",
"flake8-assertive==2.0.0",
"ruff==0.0.261",
# For enforcing string formatting mechanism in source files
"semgrep==1.3.0",
# For templates linting
Expand Down
4 changes: 0 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,3 @@ setenv =
mssql: DATABASE_USER=sa
mssql: DATABASE_PASSWORD=Password12!

[testenv:flake8]
basepython=python3.7
deps=flake8>=3.6.0
commands=flake8

0 comments on commit 459fbb2

Please sign in to comment.