Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Switch to ruff instead of flake8. (#14633)
Browse files Browse the repository at this point in the history
ruff is a flake8-compatible Python linter written in Rust.
It supports the flake8 plugins that we use and is significantly
faster in testing.
  • Loading branch information
clokep committed Dec 21, 2022
1 parent 5831bed commit 7010a3d
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 116 deletions.
18 changes: 0 additions & 18 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- run: scripts-dev/check_schema_delta.py --force-colors

lint:
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v2"
with:
typechecking-extras: "all"

Expand Down
1 change: 1 addition & 0 deletions changelog.d/14633.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use [ruff](https://github.com/charliermarsh/ruff/) instead of flake8.
119 changes: 29 additions & 90 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 42 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,46 @@ target-version = ['py37', 'py38', 'py39', 'py310']
# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
# Use `extend-exclude` if you want to exclude something in addition to this.

[tool.ruff]
line-length = 88

# See https://github.com/charliermarsh/ruff/#pycodestyle
# for error codes. The ones we ignore are:
# E731: do not assign a lambda expression, use a def
# E501: Line too long (black enforces this for us)
#
# See https://github.com/charliermarsh/ruff/#pyflakes
# F401: unused import
# F811: Redefinition of unused
# F821: Undefined name
#
# flake8-bugbear compatible checks. Its error codes are described at
# https://github.com/charliermarsh/ruff/#flake8-bugbear
# B019: Use of functools.lru_cache or functools.cache on methods can lead to memory leaks
# B023: Functions defined inside a loop must not use variables redefined in the loop
# B024: Abstract base class with no abstract method.
ignore = [
"B019",
"B023",
"B024",
"E501",
"E731",
"F401",
"F811",
"F821",
]
select = [
# pycodestyle checks.
"E",
"W",
# pyflakes checks.
"F",
# flake8-bugbear checks.
"B0",
# flake8-comprehensions checks.
"C4",
]

[tool.isort]
line_length = 88
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "TWISTED", "FIRSTPARTY", "TESTS", "LOCALFOLDER"]
Expand Down Expand Up @@ -274,12 +314,10 @@ all = [
]

[tool.poetry.dev-dependencies]
## We pin black so that our tests don't start failing on new releases.
# We pin black so that our tests don't start failing on new releases.
isort = ">=5.10.1"
black = ">=22.3.0"
flake8-comprehensions = "*"
flake8-bugbear = ">=21.3.2"
flake8 = "*"
ruff = "0.0.189"

# Typechecking
mypy = "*"
Expand Down
5 changes: 2 additions & 3 deletions scripts-dev/lint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
#
# Runs linting scripts over the local Synapse checkout
# isort - sorts import statements
# black - opinionated code formatter
# flake8 - lints and finds mistakes
# ruff - lints and finds mistakes

set -e

Expand Down Expand Up @@ -105,6 +104,6 @@ set -x
isort "${files[@]}"
python3 -m black "${files[@]}"
./scripts-dev/config-lint.sh
flake8 "${files[@]}"
ruff "${files[@]}"
./scripts-dev/check_pydantic_models.py lint
mypy
2 changes: 2 additions & 0 deletions stubs/frozendict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Stub for frozendict.

from __future__ import annotations

from typing import Any, Hashable, Iterable, Iterator, Mapping, Tuple, TypeVar, overload

_KT = TypeVar("_KT", bound=Hashable) # Key type.
Expand Down
2 changes: 2 additions & 0 deletions stubs/icu.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Stub for PyICU.

from __future__ import annotations

class Locale:
@staticmethod
def getDefault() -> Locale: ...
Expand Down
2 changes: 2 additions & 0 deletions stubs/sortedcontainers/sorteddict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/grantjenks/python-sortedcontainers/blob/eea42df1f7bad2792e8da77335ff888f04b9e5ae/sortedcontainers/sorteddict.pyi
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)

from __future__ import annotations

from typing import (
Any,
Callable,
Expand Down
2 changes: 2 additions & 0 deletions stubs/sortedcontainers/sortedlist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/grantjenks/python-sortedcontainers/blob/a419ffbd2b1c935b09f11f0971696e537fd0c510/sortedcontainers/sortedlist.pyi
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)

from __future__ import annotations

from typing import (
Any,
Callable,
Expand Down
2 changes: 2 additions & 0 deletions stubs/sortedcontainers/sortedset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/grantjenks/python-sortedcontainers/blob/d0a225d7fd0fb4c54532b8798af3cbeebf97e2d5/sortedcontainers/sortedset.pyi
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)

from __future__ import annotations

from typing import (
AbstractSet,
Any,
Expand Down
2 changes: 2 additions & 0 deletions synapse/config/_base.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import argparse
from typing import (
Any,
Expand Down

0 comments on commit 7010a3d

Please sign in to comment.