Skip to content

Commit 99c73b7

Browse files
authored
Merge pull request dvd-dev#216 from dvd-dev/issue457
Fix attempt pour issue 457
2 parents 3549f3a + db609c6 commit 99c73b7

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ repos:
5252
- types-aiofiles==23.2.0
5353

5454
- repo: https://github.com/pre-commit/pre-commit-hooks
55-
rev: v2.4.0
55+
rev: v5.0.0
5656
hooks:
5757
- id: check-json
5858
- id: no-commit-to-branch

pyhilo/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ async def post_devicehub_negociate(self) -> tuple[str, str]:
367367
resp = await self.async_request("post", url)
368368
ws_url = resp.get("url")
369369
ws_token = resp.get("accessToken")
370+
LOG.debug("Calling set_state")
370371
await set_state(
371372
self._state_yaml,
372373
"websocket",
@@ -398,6 +399,7 @@ async def get_websocket_params(self) -> None:
398399
"available_transports": transport_dict,
399400
"full_ws_url": self.full_ws_url,
400401
}
402+
LOG.debug("Calling set_state")
401403
await set_state(self._state_yaml, "websocket", websocket_dict)
402404

403405
async def fb_install(self, fb_id: str) -> None:
@@ -423,6 +425,7 @@ async def fb_install(self, fb_id: str) -> None:
423425
raise RequestError(err) from err
424426
LOG.debug(f"FB Install data: {resp}")
425427
auth_token = resp.get("authToken", {})
428+
LOG.debug("Calling set_state")
426429
await set_state(
427430
self._state_yaml,
428431
"firebase",
@@ -464,6 +467,7 @@ async def android_register(self) -> None:
464467
LOG.error(f"Android registration error: {msg}")
465468
raise RequestError
466469
token = msg.split("=")[-1]
470+
LOG.debug("Calling set_state")
467471
await set_state(
468472
self._state_yaml,
469473
"android",

pyhilo/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
LOG: Final = logging.getLogger(__package__)
99
DEFAULT_STATE_FILE: Final = "hilo_state.yaml"
1010
REQUEST_RETRY: Final = 9
11-
PYHILO_VERSION: Final = "2024.06.01"
11+
PYHILO_VERSION: Final = "2024.10.02"
1212
# TODO: Find a way to keep previous line in sync with pyproject.toml automatically
1313

1414
CONTENT_TYPE_FORM: Final = "application/x-www-form-urlencoded"

pyhilo/util/state.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
from datetime import datetime
23
from os.path import isfile
34
from typing import Any, Optional, Type, TypedDict, TypeVar, Union
@@ -7,6 +8,8 @@
78

89
from pyhilo.const import LOG
910

11+
lock = asyncio.Lock()
12+
1013

1114
class TokenDict(TypedDict):
1215
access: Optional[str]
@@ -103,10 +106,11 @@ async def set_state(
103106
:type state: ``StateDict``
104107
:rtype: ``StateDict``
105108
"""
106-
current_state = await get_state(state_yaml) or {}
107-
merged_state: dict[str, Any] = {key: {**current_state.get(key, {}), **state}} # type: ignore
108-
new_state: dict[str, Any] = {**current_state, **merged_state}
109-
async with aiofiles.open(state_yaml, mode="w") as yaml_file:
110-
LOG.debug("Saving state to yaml file")
111-
content = yaml.dump(new_state)
112-
await yaml_file.write(content)
109+
async with lock: # note ic-dev21: on lock le fichier pour être sûr de finir la job
110+
current_state = await get_state(state_yaml) or {}
111+
merged_state: dict[str, Any] = {key: {**current_state.get(key, {}), **state}} # type: ignore
112+
new_state: dict[str, Any] = {**current_state, **merged_state}
113+
async with aiofiles.open(state_yaml, mode="w") as yaml_file:
114+
LOG.debug("Saving state to yaml file")
115+
content = yaml.dump(new_state)
116+
await yaml_file.write(content)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exclude = ".venv/.*"
4040

4141
[tool.poetry]
4242
name = "python-hilo"
43-
version = "2024.10.1"
43+
version = "2024.10.2"
4444
description = "A Python3, async interface to the Hilo API"
4545
readme = "README.md"
4646
authors = ["David Vallee Delisle <[email protected]>"]

0 commit comments

Comments
 (0)