Skip to content

Commit 92675bc

Browse files
authored
Merge branch 'main' into 85-remove-initialize-and-close-from-the-client-class
2 parents fdb9926 + 8b2560a commit 92675bc

30 files changed

+217
-203
lines changed

.github/workflows/qa.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ jobs:
88
runs-on: ubuntu-latest
99
timeout-minutes: 15
1010

11+
strategy:
12+
matrix:
13+
version: [ '3.11', '3.12', '3.13' ]
14+
1115
steps:
1216
- name: Clone repository
1317
uses: actions/checkout@v4
1418
- name: Use Python
1519
uses: actions/setup-python@v5
1620
with:
17-
python-version: '3.13'
21+
python-version: ${{ matrix.version }}
1822
- name: Install dependencies
1923
run: |
2024
pip install poetry

eventsourcingdb/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(
3030
self,
3131
base_url: str,
3232
api_token: str,
33-
):
33+
) -> None:
3434
self.__http_client = HttpClient(base_url=base_url, api_token=api_token)
3535

3636
async def __aenter__(self) -> 'Client':
@@ -188,7 +188,8 @@ async def run_eventql_query(self, query: str) -> AsyncGenerator[Any]:
188188
message = parse_raw_message(raw_message)
189189

190190
if is_stream_error(message):
191-
raise ServerError(f'{message['payload']['error']}.')
191+
error_message = message.get('payload', {}).get('error', 'Unknown error')
192+
raise ServerError(f"{error_message}.")
192193
# pylint: disable=R2004
193194
if message.get('type') == 'row':
194195
payload = message['payload']
@@ -197,7 +198,7 @@ async def run_eventql_query(self, query: str) -> AsyncGenerator[Any]:
197198
continue
198199

199200
raise ServerError(
200-
f'Failed to execute EventQL query, an unexpected stream item was received: '
201+
'Failed to execute EventQL query, an unexpected stream item was received: '
201202
f'{message}.'
202203
)
203204

eventsourcingdb/container.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Container:
1313
def __init__(
1414
self,
15-
):
15+
) -> None:
1616
self._image_name: str = 'thenativeweb/eventsourcingdb'
1717
self._image_tag: str = 'latest'
1818
self._api_token: str = 'secret'
@@ -57,7 +57,7 @@ def _create_container(self) -> None:
5757
detach=True,
5858
) # type: ignore
5959

60-
def _extract_port_from_container_info(self, container_info):
60+
def _extract_port_from_container_info(self, container_info) -> int | None:
6161
port = None
6262
valid_mapping = True
6363
port_mappings = None
@@ -95,7 +95,7 @@ def _fetch_mapped_port(self) -> None:
9595
self._stop_and_remove_container()
9696
raise RuntimeError('Failed to determine mapped port')
9797

98-
def _get_container_info(self):
98+
def _get_container_info(self) -> dict | None:
9999
if self._container is None:
100100
return None
101101
return self._docker_client.api.inspect_container(self._container.id)
@@ -137,7 +137,12 @@ def start(self) -> 'Container':
137137
return self
138138

139139
def _pull_or_get_image(self) -> None:
140-
"""Pull Docker image or use local image if pulling fails."""
140+
try:
141+
self._docker_client.images.pull(self._image_name, self._image_tag)
142+
except errors.APIError as e:
143+
self._handle_image_pull_error(e)
144+
145+
def _handle_image_pull_error(self, error) -> None:
141146
image_name = f"{self._image_name}:{self._image_tag}"
142147

143148
# First check if the image is already available locally
@@ -230,7 +235,7 @@ def _check_endpoint_available(self, url: str) -> bool:
230235
return self._check_response_ok(response)
231236

232237
# pylint: disable=R6301
233-
def _check_response_ok(self, response) -> bool:
238+
def _check_response_ok(self, response: requests.Response) -> bool:
234239
return response is not None and response.status_code == HTTPStatus.OK
235240

236241
def with_api_token(self, token: str) -> 'Container':

eventsourcingdb/errors/client_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ClientError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Client error occurred: {cause}')

eventsourcingdb/errors/internal_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class InternalError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Internal error occurred: {cause}')

eventsourcingdb/errors/server_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ServerError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Server error occurred: {cause}')

eventsourcingdb/errors/validation_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ValidationError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Validation error occurred: {cause}')

eventsourcingdb/event/event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from dataclasses import dataclass
3-
from typing import TypeVar
3+
from typing import TypeVar, Any
44

55
from ..errors.internal_error import InternalError
66
from ..errors.validation_error import ValidationError
@@ -24,7 +24,7 @@ class Event():
2424
trace_state: str | None = None
2525

2626
@staticmethod
27-
def parse(unknown_object: dict) -> "Event":
27+
def parse(unknown_object: dict) -> 'Event':
2828
source = unknown_object.get('source')
2929
if not isinstance(source, str):
3030
raise ValidationError(
@@ -103,7 +103,7 @@ def parse(unknown_object: dict) -> "Event":
103103
trace_state=trace_state
104104
)
105105

106-
def to_json(self):
106+
def to_json(self) -> dict[str, Any]:
107107
json = {
108108
'specversion': self.spec_version,
109109
'id': self.event_id,

eventsourcingdb/event/event_candidate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
2+
from typing import Any
33

44
@dataclass
55
class EventCandidate:
@@ -10,7 +10,7 @@ class EventCandidate:
1010
trace_parent: str | None = None
1111
trace_state: str | None = None
1212

13-
def to_json(self):
13+
def to_json(self) -> dict[str, Any]:
1414
json = {
1515
'data': self.data,
1616
'source': self.source,

eventsourcingdb/http_client/http_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def __init__(
1313
self,
1414
base_url: str,
1515
api_token: str,
16-
):
16+
) -> None:
1717
self.__base_url = base_url
1818
self.__api_token = api_token
1919
self.__session: ClientSession | None = None
2020

21-
async def __aenter__(self):
22-
await self.__initialize()
21+
async def __aenter__(self) -> 'HttpClient':
22+
await self.initialize()
2323
return self
2424

2525
async def __aexit__(
@@ -37,7 +37,7 @@ async def __initialize(self) -> None:
3737

3838
self.__session = aiohttp.ClientSession(connector_owner=True)
3939

40-
async def __close(self):
40+
async def close(self) -> None:
4141
if self.__session is not None:
4242
await self.__session.close()
4343
self.__session = None

0 commit comments

Comments
 (0)