add ruff and pyright flake checks

This commit is contained in:
Abel Luck 2026-03-05 16:08:31 +01:00
parent 42cf3f75dc
commit 7c9b42fe56
8 changed files with 125 additions and 19 deletions

View file

@ -1,6 +1,6 @@
import logging
import re
from typing import Any, List, Optional, Tuple
from typing import Any, List, Optional, Tuple, cast
import attr
from fastapi import Request
@ -47,8 +47,9 @@ async def handle_event(x_gitlab_event: str, payload: Any) -> List[Tuple[str, str
nonlocal aborted
aborted = True
action_fields = cast(Any, Action)
base_args = {
**{field.key: field for field in Action if field.key.isupper()},
**{field.key: field for field in action_fields if field.key.isupper()},
**OTHER_ENUMS,
"util": TemplateUtil,
}

View file

@ -717,7 +717,7 @@ class GitlabPushEvent(SerializableAttrs, GitlabEvent):
def split_updates(
evt: Union["GitlabIssueEvent", "GitlabMergeRequestEvent"]
evt: Union["GitlabIssueEvent", "GitlabMergeRequestEvent"],
) -> List[GitlabEvent]:
if not evt.changes:
return [evt]

View file

@ -14,7 +14,6 @@ from fastapi.security import (
HTTPBasicCredentials,
HTTPBearer,
)
from prometheus_client import start_http_server
from prometheus_fastapi_instrumentator import Instrumentator
from ops_bot import alertmanager, aws, pagerduty
@ -101,8 +100,7 @@ class Authorizer(Protocol):
request: Request,
basic_credentials: Optional[HTTPBasicCredentials],
bearer_credentials: Optional[HTTPAuthorizationCredentials],
) -> bool:
...
) -> bool: ...
class ParseHandler(Protocol):
@ -111,8 +109,7 @@ class ParseHandler(Protocol):
route: RoutingKey,
payload: Any,
request: Request,
) -> List[Tuple[str, str]]:
...
) -> List[Tuple[str, str]]: ...
handlers: Dict[str, Tuple[Authorizer, ParseHandler]] = {

View file

@ -21,9 +21,11 @@ class ClientCredentials(BaseModel):
class CredentialStorage(Protocol):
def save_config(self, config: ClientCredentials) -> None:
"""Save config"""
...
def read_config(self) -> ClientCredentials:
"""Load config"""
...
class LocalCredentialStore:
@ -64,7 +66,7 @@ class MatrixClient:
self.store_path.joinpath("credentials.json")
)
self.client: AsyncClient = None
self.client: Optional[AsyncClient] = None
self.client_config = AsyncClientConfig(
max_limit_exceeded=0,
max_timeouts=0,
@ -79,15 +81,19 @@ class MatrixClient:
async def start(self) -> None:
await self.login()
if self.client is None:
raise RuntimeError("Matrix client failed to initialize")
if self.client.should_upload_keys:
await self.client.keys_upload()
client = self.client
if client.should_upload_keys:
await client.keys_upload()
for room in self.join_rooms:
await self.client.join(room)
await client.join(room)
await self.client.joined_rooms()
await self.client.sync_forever(timeout=300000, full_state=True)
await client.joined_rooms()
await client.sync_forever(timeout=300000, full_state=True)
def save_credentials(self, resp: LoginResponse, homeserver: str) -> None:
credentials = ClientCredentials(
@ -150,6 +156,9 @@ class MatrixClient:
message: str,
message_formatted: Optional[str] = None,
) -> None:
if self.client is None:
raise RuntimeError("Matrix client failed to initialize")
content = {
"msgtype": "m.text",
"body": f"{message}",
@ -168,4 +177,5 @@ class MatrixClient:
)
async def shutdown(self) -> None:
await self.client.close()
if self.client is not None:
await self.client.close()

View file

@ -123,14 +123,14 @@ class PluginTemplateLoader(BaseLoader):
self.macros = sync_read_file(base_path / "macros.html")
def get_source(
self, environment: Any, name: str
self, environment: Any, template: str
) -> Tuple[str, str, Callable[[], bool]]:
path = self.directory / f"{name}.html"
path = self.directory / f"{template}.html"
try:
tpl = sync_read_file(path)
except KeyError:
raise TemplateNotFound(name)
return self.macros + tpl, name, lambda: True
raise TemplateNotFound(template)
return self.macros + tpl, template, lambda: True
def list_templates(self) -> List[str]:
return [