Skip to content

Commit

Permalink
Switch from flake8 to ruff (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMaul authored Oct 23, 2023
1 parent 49d2875 commit d93c247
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 35 deletions.
2 changes: 1 addition & 1 deletion manage_last_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, config: ManageLastAdminConfig, api: ModuleApi):
self._config = config

self._api.register_third_party_rules_callbacks(
check_event_allowed=self.check_event_allowed,
check_event_allowed=self.check_event_allowed
)

@staticmethod
Expand Down
54 changes: 43 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ dependencies = [
[project.optional-dependencies]
dev = [
# for tests
"pydantic>=1.7.4, <2.0",
"matrix-synapse==1.84.0",
"pydantic >= 1.7.4, < 2.0",
"matrix-synapse == 1.84.0",
"tox",
"twisted",
"aiounittest",
# for type checking
"mypy == 1.6.1",
# for linting
"black == 23.10.0",
"flake8 == 6.1.0",
"isort == 5.12.0",
"ruff == 0.1.1",
]

[project.urls]
Expand All @@ -39,12 +38,45 @@ build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.isort]
profile = "black"
known_first_party = [
"manage_last_admin",
"tests"
]

[tool.mypy]
strict = true

[tool.ruff]
line-length = 88

# See https://docs.astral.sh/ruff/rules/#error-e
# for error codes. The ones we ignore are:
# E501: Line too long (black enforces this for us)
# E731: do not assign a lambda expression, use a def
#
# flake8-bugbear compatible checks. Its error codes are described at
# https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
# B023: Functions defined inside a loop must not use variables redefined in the loop
ignore = [
"B023",
"E501",
"E731",
]
select = [
# pycodestyle
"E",
"W",
# pyflakes
"F",
# flake8-bugbear
"B0",
# flake8-comprehensions
"C4",
# flake8-2020
"YTT",
# flake8-slots
"SLOT",
# flake8-debugger
"T10",
# flake8-pie
"PIE",
# flake8-executable
"EXE",
# isort
"I",
]
19 changes: 19 additions & 0 deletions scripts-dev/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Runs linting scripts and type checking
# black - opinionated code formatter
# ruff - lints, finds mistakes, and sorts import statements
# mypy - checks type annotations

set -e

files=(
"manage_last_admin"
"tests"
)

# Print out the commands being run
set -x

black "${files[@]}"
ruff --fix "${files[@]}"
mypy "${files[@]}"
7 changes: 5 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Dict
from typing import Any, Dict, Optional
from unittest import mock

from synapse.module_api import ModuleApi, UserID
Expand All @@ -22,8 +22,11 @@


def create_module(
config_override: Dict[str, Any] = {}, server_name: str = "example.com"
config_override: Optional[Dict[str, Any]] = None, server_name: str = "example.com"
) -> ManageLastAdmin:
if config_override is None:
config_override = {}

def get_qualified_user_id(localpart: str) -> str:
return UserID(localpart, server_name).to_string()

Expand Down
23 changes: 2 additions & 21 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,12 @@ commands =
extras = dev

commands =
black --check --diff manage_last_admin tests
isort --check-only --diff manage_last_admin tests
flake8 manage_last_admin tests

[testenv:fix_codestyle]

extras = dev

commands =
black manage_last_admin tests
isort manage_last_admin tests
- black --check --diff manage_last_admin tests
- ruff --diff manage_last_admin tests

[testenv:check_types]

extras = dev

commands =
mypy manage_last_admin tests

[flake8]
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are:
# W503: line break before binary operator
# W504: line break after binary operator
# E203: whitespace before ':' (which is contrary to pep8?)
# E501: Line too long (black enforces this for us)
# (this is a subset of those ignored in Synapse)
extend-ignore = W503,W504,E203,E501

0 comments on commit d93c247

Please sign in to comment.