diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e164460dbee..4292a25c70f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,4 @@ repos: - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - args: [--append-config=tox.ini] - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.9.0.5 hooks: @@ -17,6 +12,11 @@ repos: hooks: - id: markdownlint args: [--fix] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.14 + hooks: + - id: ruff + args: [--fix] - repo: https://github.com/psf/black rev: 23.3.0 hooks: diff --git a/README.md b/README.md index 0737455cf00..f02d67b271a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ ![Node dependencies Status](https://shields.io/librariesio/github/mozilla/treeherder) [![Documentation Status](https://readthedocs.org/projects/treeherder/badge/?version=latest)](https://treeherder.readthedocs.io/?badge=latest) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) ## Description diff --git a/pyproject.toml b/pyproject.toml index fd2c90c52b6..e5262f7dcd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,3 +33,40 @@ exclude = ''' | treeherder/changelog/migrations )/ ''' + +[tool.ruff] +# Same as Black. +line-length = 100 + +# Assume Python 3.9 +target-version = "py39" + +# In addition to the standard set of exclusions, omit all tests, plus a specific file. +extend-exclude = ["*/.*/",".*/","__pycache__","node_modules"] + +select = [ + # pycodestyle + "E", + "W", + # pyflakes + "F", +] + +ignore = [ + # E203 whitespace before ':' + "E203", + # E231: missing whitespace after ',' + "E231", + # E501: line too long + "E501" +] + +[tool.ruff.per-file-ignores] +# Ignore `module-import-not-at-top-of-file` rule of `pycodestyle` +"treeherder/model/models.py" = ["E402"] + +# Ignore `not-is-test` rule of `pycodestyle` +"treeherder/perf/sheriffing_criteria/criteria_tracking.py" = ["E714"] + +# Ignore `not-in-test` rule of `pycodestyle` +"treeherder/push_health/utils.py" = ["E713"] diff --git a/setup.cfg b/setup.cfg index cd674b14ac6..60893ca09d6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,3 @@ -[flake8] -exclude = */.*/,.*/,__pycache__,node_modules -# E129: visually indented line with same indent as next logical line -# E203 whitespace before ':' -# E231: missing whitespace after ',' -# E501: line too long -extend_ignore = E129,E203,E231,E501 -max-line-length = 100 - [tool:pytest] testpaths = tests norecursedirs = __pycache__ ui diff --git a/tox.ini b/tox.ini index cfa2b756f11..94fda567703 100644 --- a/tox.ini +++ b/tox.ini @@ -54,6 +54,3 @@ whitelist_externals= docker-compose commands = docker-compose run -e TREEHERDER_DEBUG=False -e DATABASE_URL=psql://postgres:mozilla1234@postgres:5432/treeherder backend bash -c "pytest --cov --cov-report=xml tests/ --runslow -p no:unraisableexception" - -[flake8] -per-file-ignores = treeherder/model/models.py:E402