From 865ce1127b99e31cac4d57d1372eb190c56d8715 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 3 Aug 2023 06:50:47 +1000 Subject: [PATCH] feat(ci): add the ruff tool to the pre-commit checks --- .pre-commit-config.yaml | 8 ++++++++ Makefile | 8 +++++--- pyproject.toml | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 56ba7946..53835973 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,6 +53,14 @@ repos: files: ^src/package/|^tests/ args: [--py310-plus] +# Ruff is a fast superset of pylint and selection of various flake8 plugins. +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.286 + hooks: + - id: ruff + name: Check ruff issues + args: [--config, pyproject.toml, --fix, --exit-non-zero-on-fix] + # Similar to pylint, with a few more/different checks. For more available # extensions: https://github.com/DmytroLitvinov/awesome-flake8-extensions - repo: https://github.com/pycqa/flake8 diff --git a/Makefile b/Makefile index e5ca2180..3faf4b81 100644 --- a/Makefile +++ b/Makefile @@ -150,8 +150,10 @@ audit: python -m pip_audit --skip-editable --desc on --fix --dry-run # Run some or all checks over the package code base. -.PHONY: check check-code check-bandit check-flake8 check-lint check-mypy -check-code: check-bandit check-flake8 check-lint check-mypy check-actionlint +.PHONY: check check-code check-ruff check-bandit check-flake8 check-lint check-mypy +check-code: check-ruff check-bandit check-flake8 check-lint check-mypy check-actionlint +check-ruff: + pre-commit run ruff --all-files check-bandit: pre-commit run bandit --all-files check-flake8: @@ -228,7 +230,7 @@ dist-clean: rm -fr dist/* rm -f requirements.txt clean: dist-clean - rm -fr .coverage .hypothesis/ .mypy_cache/ .pytest_cache/ + rm -fr .coverage .hypothesis/ .mypy_cache/ .pytest_cache/ .ruff_cache/ rm -fr docs/_build/ # Remove code caches, or the entire virtual environment. diff --git a/pyproject.toml b/pyproject.toml index 0eb50fd0..bfce65df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -216,3 +216,20 @@ filterwarnings = [ "error::pytest.PytestUnraisableExceptionWarning", "error::pytest.PytestUnhandledThreadExceptionWarning", ] + + +# https://beta.ruff.rs/docs/configuration/ +# https://beta.ruff.rs/docs/rules/ +# https://beta.ruff.rs/docs/settings/ +[tool.ruff] +src = ["src/package/", "tests/"] +extend-exclude = ["docs/"] +select = ["B", "B9", "D", "E", "F", "W"] +ignore = ["D105", "E501"] +line-length = 120 +target-version = "py310" + +[tool.ruff.pydocstyle] +convention = "numpy" + +[tool.ruff.per-file-ignores]