Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ jobs:

- uses: astral-sh/setup-uv@v5

- name: Import order (isort)
run: uv run isort --check --diff .
- name: Lint (ruff)
run: uv run ruff check sydent/ tests/ stubs/ integration-tests/

- name: Code style (black)
run: uv run black --check --diff .

- name: Semantic checks (ruff)
# --quiet suppresses the update check.
run: uv run ruff --quiet .
- name: Format (ruff)
run: uv run ruff format --check sydent/ tests/ stubs/ integration-tests/

- name: Restore/persist mypy's cache
uses: actions/cache@v5
Expand Down
1 change: 1 addition & 0 deletions changelog.d/623.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace black and isort with ruff.
31 changes: 13 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Repository = "https://github.com/element-hq/sydent"

[dependency-groups]
dev = [
"black>=23.1.0",
"ruff==0.0.189",
"isort==5.8.0",
"ruff>=0.14.0",
"matrix-is-tester",
"mypy>=0.902",
"mypy-zope>=0.3.1",
Expand Down Expand Up @@ -103,13 +101,6 @@ directory = "misc"
name = "Internal Changes"
showcontent = true

[tool.isort]
profile = "black"
known_local_folder = ["tests", "matrix_is_tester"]

[tool.black]
target-version = ['py310']

[tool.mypy]
plugins = "mypy_zope:plugin"
show_error_codes = true
Expand All @@ -133,16 +124,20 @@ ignore_missing_imports = true
[tool.ruff]
line-length = 88

ignore = [
"E501",
"F401",
"F821",
]
[tool.ruff.lint]
select = [
"E",
"W",
"F",
"E", "W", # pycodestyle
"F", # pyflakes
"I", # isort (replaces standalone isort)
]
ignore = [
"E501", # line too long (formatter handles what it can)
]

[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ["sydent"]
known-local-folder = ["tests", "matrix_is_tester"]

[build-system]
requires = ["uv_build>=0.11.3,<1"]
Expand Down
10 changes: 2 additions & 8 deletions scripts-dev/lint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#! /usr/bin/env bash
set -ex

# We don't list explicit directories here. Instead, rely on the tools' default behaviour
# (or explicit configuration in setup.cfg/pyproject.toml). This helps to keep this script
# consistent with CI.

black .
# --quiet suppresses the update check.
ruff --quiet .
isort .
ruff check --fix sydent/ tests/ stubs/
ruff format sydent/ tests/ stubs/
mypy
7 changes: 4 additions & 3 deletions sydent/config/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ def parse_config(self, cfg: "ConfigParser") -> bool:
)
if homeserver_allow_list and self.enable_v1_access:
raise RuntimeError(
"""The V1 api must be disabled for the `homeserver_allow_list` to function, if you have
specified a `homeserver_allow_list` in the config file please ensure that the config
option `enable_v1_access` is set to 'false'."""
"The V1 api must be disabled for the `homeserver_allow_list` to"
" function, if you have specified a `homeserver_allow_list` in"
" the config file please ensure that the config option"
" `enable_v1_access` is set to 'false'."
)
self.homeserver_allow_list = homeserver_allow_list

Expand Down
3 changes: 1 addition & 2 deletions sydent/db/hashing_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def store_lookup_pepper(

# Create or update lookup_pepper
sql = (
"INSERT OR REPLACE INTO hashing_metadata (id, lookup_pepper) "
"VALUES (0, ?)"
"INSERT OR REPLACE INTO hashing_metadata (id, lookup_pepper) VALUES (0, ?)"
)
cur.execute(sql, (pepper,))

Expand Down
2 changes: 1 addition & 1 deletion sydent/db/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def getAgreedUrls(self, user_id: str) -> List[str]:
"""
cur = self.sydent.db.cursor()
res = cur.execute(
"select url from accepted_terms_urls " "where user_id = ?",
"select url from accepted_terms_urls where user_id = ?",
(user_id,),
)

Expand Down
9 changes: 3 additions & 6 deletions sydent/db/threepid_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ def removeAssociation(self, medium: str, normalised_address: str) -> None:

cur = self.sydent.db.cursor()
cur.execute(
"DELETE FROM global_threepid_associations WHERE "
"medium = ? AND address = ?",
"DELETE FROM global_threepid_associations WHERE medium = ? AND address = ?",
(medium, normalised_address),
)
logger.info(
Expand All @@ -404,8 +403,7 @@ def retrieveMxidsForHashes(self, addresses: List[str]) -> Dict[str, str]:
cur = self.sydent.db.cursor()

cur.execute(
"CREATE TEMPORARY TABLE tmp_retrieve_mxids_for_hashes "
"(lookup_hash VARCHAR)"
"CREATE TEMPORARY TABLE tmp_retrieve_mxids_for_hashes (lookup_hash VARCHAR)"
)
cur.execute(
"CREATE INDEX tmp_retrieve_mxids_for_hashes_lookup_hash ON "
Expand All @@ -420,8 +418,7 @@ def retrieveMxidsForHashes(self, addresses: List[str]) -> Dict[str, str]:
inserted_cap = 0
while inserted_cap < len(tuplized_addresses):
cur.executemany(
"INSERT INTO tmp_retrieve_mxids_for_hashes(lookup_hash) "
"VALUES (?)",
"INSERT INTO tmp_retrieve_mxids_for_hashes(lookup_hash) VALUES (?)",
tuplized_addresses[inserted_cap : inserted_cap + 500],
)
inserted_cap += 500
Expand Down
1 change: 0 additions & 1 deletion sydent/hs_federation/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ async def verifyServerSignedJson(
server_keys = await self._getKeysForServer(server_name)
for key_name, sig in sigs.items():
if key_name in server_keys:

key_bytes = decode_base64(server_keys[key_name]["key"])
verify_key = signedjson.key.decode_verify_key_bytes(
key_name, key_bytes
Expand Down
8 changes: 5 additions & 3 deletions sydent/http/blacklisting_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# <http://www.apache.org/licenses/LICENSE-2.0>.

import logging
from typing import Any, List, Optional
from typing import Any, Optional

from netaddr import IPAddress, IPSet
from twisted.internet.address import IPv4Address, IPv6Address
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(
def resolveHostName(
self, recv: IResolutionReceiver, hostname: str, portNumber: int = 0
) -> IResolutionReceiver:
addresses = [] # type: List[IAddress]
addresses: list[IAddress] = []

def _callback() -> None:
has_bad_ip = False
Expand Down Expand Up @@ -112,7 +112,9 @@ def resolutionComplete() -> None:
_callback()

self._reactor.nameResolver.resolveHostName(
EndpointReceiver, hostname, portNumber=portNumber # type: ignore[arg-type]
EndpointReceiver, # type: ignore[arg-type]
hostname,
portNumber=portNumber,
)

return recv
Expand Down
2 changes: 1 addition & 1 deletion sydent/http/servlets/lookupv2servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def render_POST(self, request: Request) -> JsonDict:
request.setResponseCode(400)
return {
"errcode": "M_TOO_LARGE",
"error": "More than the maximum amount of " "addresses provided",
"error": "More than the maximum amount of addresses provided",
}

pepper = str(args["pepper"])
Expand Down
2 changes: 1 addition & 1 deletion sydent/sydent.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def setup_logging(config: SydentConfig) -> None:
log_path = config.general.log_path
log_level = config.general.log_level

log_format = "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s" " - %(message)s"
log_format = "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s"
formatter = logging.Formatter(log_format)

handler: logging.Handler
Expand Down
3 changes: 1 addition & 2 deletions sydent/util/emailutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ def check_valid_email_address(address: str, allow_description: bool) -> None:
raise EmailAddressException(f"Couldn't parse email address {address}.")
if not allow_description and address != parsed_address:
raise EmailAddressException(
f"Parsing address ({address} yielded a different address"
f"({parsed_address})"
f"Parsing address ({address} yielded a different address({parsed_address})"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
("@bob:localhost", 101010101, "asd"),
)
cur.execute(
"INSERT INTO tokens (user_id, token)" "VALUES (?, ?)",
"INSERT INTO tokens (user_id, token)VALUES (?, ?)",
("@bob:localhost", self.test_token),
)

Expand Down
1 change: 0 additions & 1 deletion tests/test_msisdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def _make_request(self, url: str, body: Optional[JsonDict] = None) -> Mock:
"sydent.sms.openmarket.OpenMarketSMS.sendTextSMS",
new_callable=AsyncMock,
) as sendTextSMS:

request, channel = make_request(
self.sydent.reactor,
self.sydent.clientApiHttpServer.factory,
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
from io import BytesIO
from typing import Dict, Optional
from typing import Optional
from unittest.mock import MagicMock

import attr
Expand Down Expand Up @@ -283,7 +283,7 @@ def setup_logging():
"""
root_logger = logging.getLogger()

log_format = "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s" " - %(message)s"
log_format = "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s"

handler = ToTwistedHandler()
formatter = logging.Formatter(log_format)
Expand Down
Loading
Loading