Skip to content
Open
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.21
rev: v0.16.3
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
8 changes: 4 additions & 4 deletions src/cocat/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import atexit
from collections.abc import Iterable
from collections.abc import Iterable, Sequence
from contextlib import ExitStack
from datetime import datetime
from pathlib import Path
from typing import Any, Sequence
from typing import Any
from urllib.parse import urlparse
from uuid import UUID

Expand Down Expand Up @@ -207,8 +207,8 @@ def create_catalogue(

def create_event(
*,
start: datetime | int | float | str,
stop: datetime | int | float | str,
start: datetime | float | str,
stop: datetime | float | str,
author: str,
uuid: UUID | str | bytes | bytearray | None = None,
tags: list[str] | None = None,
Expand Down
3 changes: 1 addition & 2 deletions src/cocat/app/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import AsyncGenerator, Callable
from collections.abc import AsyncGenerator, Awaitable, Callable
from dataclasses import dataclass
from typing import Awaitable

from anyio import Lock, Path
from fastapi import Depends
Expand Down
4 changes: 2 additions & 2 deletions src/cocat/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _check_deleted(self):
if self._uuid not in self._db._catalogue_maps:
raise RuntimeError("Catalogue has been deleted")

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
self._check_deleted()
if not isinstance(other, Catalogue):
return NotImplemented
Expand Down Expand Up @@ -135,7 +135,7 @@ def to_dict(self, event_as_uuid: bool = False) -> dict[str, Any]:
self._check_deleted()
dct = self._map.to_py()
assert dct is not None
dct["tags"] = list(sorted(dct["tags"].keys()))
dct["tags"] = sorted(dct["tags"].keys())
dct["events"] = [
uuid if event_as_uuid else Event._from_uuid(uuid, self._db).to_dict()
for uuid in sorted(dct["events"].keys())
Expand Down
40 changes: 15 additions & 25 deletions src/cocat/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __repr__(self) -> str:
return capture.get()

def _callback(
self, callback: Callable[..., None], origin: "DB" | None, *args: Any
self, callback: Callable[..., None], origin: DB | None, *args: Any
) -> None:
if origin is not self:
callback(*args)
Expand All @@ -79,7 +79,7 @@ def transaction(self) -> Transaction:
return self._doc.transaction(self)

@classmethod
def from_dict(cls, db_dict: dict[str, Any], doc: Doc | None = None) -> "DB":
def from_dict(cls, db_dict: dict[str, Any], doc: Doc | None = None) -> DB:
"""
Creates a database from a dictionary.

Expand All @@ -100,7 +100,7 @@ def from_dict(cls, db_dict: dict[str, Any], doc: Doc | None = None) -> "DB":
return db

@classmethod
def from_json(cls, data: str, doc: Doc | None = None) -> "DB":
def from_json(cls, data: str, doc: Doc | None = None) -> DB:
"""
Creates a database from a JSON string.

Expand Down Expand Up @@ -201,9 +201,7 @@ def _catalogues_changed(
for key, val in keys.items():
if val["action"] == "delete":
removed.add(key)
elif val["action"] == "add":
added[key] = val["newValue"]
elif val["action"] == "update":
elif val["action"] == "add" or val["action"] == "update":
added[key] = val["newValue"]
if removed:
callbacks = self._catalogue_change_callbacks[uuid][
Expand Down Expand Up @@ -261,9 +259,7 @@ def _events_changed(self, events: list[MapEvent], transaction: Transaction) -> N
for key, val in keys.items():
if val["action"] == "delete":
removed.add(key)
elif val["action"] == "add":
added[key] = val["newValue"]
elif val["action"] == "update":
elif val["action"] == "add" or val["action"] == "update":
added[key] = val["newValue"]
if removed:
callbacks = self._event_change_callbacks[uuid][f"remove_{name}"]
Expand Down Expand Up @@ -344,8 +340,8 @@ def create_catalogue(
def create_event(
self,
*,
start: datetime | int | float | str,
stop: datetime | int | float | str,
start: datetime | float | str,
stop: datetime | float | str,
author: str,
uuid: UUID | str | bytes | bytearray | None = None,
tags: list[str] | None = None,
Expand Down Expand Up @@ -444,9 +440,7 @@ def get_event(self, uuid: UUID | str) -> Event:
except KeyError:
raise RuntimeError(f"No event found with UUID: {uuid}")

def _handle_sync_message(
self, message: bytes, db: "DB", init: bool = False
) -> None:
def _handle_sync_message(self, message: bytes, db: DB, init: bool = False) -> None:
if init:
_message = create_sync_message(self._doc)
db._handle_sync_message(_message, self)
Expand All @@ -464,7 +458,7 @@ def _handle_sync_message(
): # pragma: nocover
raise

def sync(self, db: "DB") -> None:
def sync(self, db: DB) -> None:
"""
Keeps the database in sync with another database. Mostly used for tests.

Expand All @@ -487,17 +481,13 @@ def to_dict(self) -> dict[str, Any]:
The database as a dictionary.
"""
db_dict = {
"events": list(
sorted(
[event.to_dict() for event in self.events],
key=lambda event: event["uuid"],
)
"events": sorted(
[event.to_dict() for event in self.events],
key=lambda event: event["uuid"],
),
"catalogues": list(
sorted(
[catalogue.to_dict(True) for catalogue in self.catalogues],
key=lambda catalogue: catalogue["uuid"],
)
"catalogues": sorted(
[catalogue.to_dict(True) for catalogue in self.catalogues],
key=lambda catalogue: catalogue["uuid"],
),
}
events = db_dict["events"]
Expand Down
6 changes: 3 additions & 3 deletions src/cocat/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _check_deleted(self):
if self._uuid not in self._db._event_maps:
raise RuntimeError("Event has been deleted")

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
self._check_deleted()
if not isinstance(other, Event):
return NotImplemented
Expand Down Expand Up @@ -131,8 +131,8 @@ def to_dict(self) -> dict[str, Any]:
self._check_deleted()
dct = self._map.to_py()
assert dct is not None
dct["tags"] = list(sorted(dct["tags"].keys()))
dct["products"] = list(sorted(dct["products"].keys()))
dct["tags"] = sorted(dct["tags"].keys())
dct["products"] = sorted(dct["products"].keys())
dct["attributes"] = dict(sorted(dct["attributes"].items()))
return {key: dct[key] for key in EventModel.model_fields.keys()}

Expand Down
4 changes: 2 additions & 2 deletions src/cocat/votable.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ def import_votable(
"events": [],
}

has_author_field = any(f[1] == "author" for f in fields_vs_index.keys())
has_uuid_field = any(f[1] == "uuid" for f in fields_vs_index.keys())
has_author_field = any(f[1] == "author" for f in fields_vs_index)
has_uuid_field = any(f[1] == "uuid" for f in fields_vs_index)

for el in table.array:
event: dict[str, Any] = {"attributes": {}}
Expand Down
Loading