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

Commit 7010a3d

Browse files
authored
Switch to ruff instead of flake8. (#14633)
ruff is a flake8-compatible Python linter written in Rust. It supports the flake8 plugins that we use and is significantly faster in testing.
1 parent 5831bed commit 7010a3d

File tree

12 files changed

+87
-116
lines changed

12 files changed

+87
-116
lines changed

.flake8

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- run: scripts-dev/check_schema_delta.py --force-colors
5454

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

changelog.d/14633.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use [ruff](https://github.com/charliermarsh/ruff/) instead of flake8.

poetry.lock

Lines changed: 29 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

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

43+
[tool.ruff]
44+
line-length = 88
45+
46+
# See https://github.com/charliermarsh/ruff/#pycodestyle
47+
# for error codes. The ones we ignore are:
48+
# E731: do not assign a lambda expression, use a def
49+
# E501: Line too long (black enforces this for us)
50+
#
51+
# See https://github.com/charliermarsh/ruff/#pyflakes
52+
# F401: unused import
53+
# F811: Redefinition of unused
54+
# F821: Undefined name
55+
#
56+
# flake8-bugbear compatible checks. Its error codes are described at
57+
# https://github.com/charliermarsh/ruff/#flake8-bugbear
58+
# B019: Use of functools.lru_cache or functools.cache on methods can lead to memory leaks
59+
# B023: Functions defined inside a loop must not use variables redefined in the loop
60+
# B024: Abstract base class with no abstract method.
61+
ignore = [
62+
"B019",
63+
"B023",
64+
"B024",
65+
"E501",
66+
"E731",
67+
"F401",
68+
"F811",
69+
"F821",
70+
]
71+
select = [
72+
# pycodestyle checks.
73+
"E",
74+
"W",
75+
# pyflakes checks.
76+
"F",
77+
# flake8-bugbear checks.
78+
"B0",
79+
# flake8-comprehensions checks.
80+
"C4",
81+
]
82+
4383
[tool.isort]
4484
line_length = 88
4585
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "TWISTED", "FIRSTPARTY", "TESTS", "LOCALFOLDER"]
@@ -274,12 +314,10 @@ all = [
274314
]
275315

276316
[tool.poetry.dev-dependencies]
277-
## We pin black so that our tests don't start failing on new releases.
317+
# We pin black so that our tests don't start failing on new releases.
278318
isort = ">=5.10.1"
279319
black = ">=22.3.0"
280-
flake8-comprehensions = "*"
281-
flake8-bugbear = ">=21.3.2"
282-
flake8 = "*"
320+
ruff = "0.0.189"
283321

284322
# Typechecking
285323
mypy = "*"

scripts-dev/lint.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env bash
22
#
33
# Runs linting scripts over the local Synapse checkout
4-
# isort - sorts import statements
54
# black - opinionated code formatter
6-
# flake8 - lints and finds mistakes
5+
# ruff - lints and finds mistakes
76

87
set -e
98

@@ -105,6 +104,6 @@ set -x
105104
isort "${files[@]}"
106105
python3 -m black "${files[@]}"
107106
./scripts-dev/config-lint.sh
108-
flake8 "${files[@]}"
107+
ruff "${files[@]}"
109108
./scripts-dev/check_pydantic_models.py lint
110109
mypy

stubs/frozendict.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
# Stub for frozendict.
1616

17+
from __future__ import annotations
18+
1719
from typing import Any, Hashable, Iterable, Iterator, Mapping, Tuple, TypeVar, overload
1820

1921
_KT = TypeVar("_KT", bound=Hashable) # Key type.

stubs/icu.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
# Stub for PyICU.
1616

17+
from __future__ import annotations
18+
1719
class Locale:
1820
@staticmethod
1921
def getDefault() -> Locale: ...

stubs/sortedcontainers/sorteddict.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# https://github.com/grantjenks/python-sortedcontainers/blob/eea42df1f7bad2792e8da77335ff888f04b9e5ae/sortedcontainers/sorteddict.pyi
33
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)
44

5+
from __future__ import annotations
6+
57
from typing import (
68
Any,
79
Callable,

stubs/sortedcontainers/sortedlist.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# https://github.com/grantjenks/python-sortedcontainers/blob/a419ffbd2b1c935b09f11f0971696e537fd0c510/sortedcontainers/sortedlist.pyi
33
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)
44

5+
from __future__ import annotations
6+
57
from typing import (
68
Any,
79
Callable,

0 commit comments

Comments
 (0)