Skip to content

Commit d26a585

Browse files
committed
chore: add check for emscripten
1 parent bff1cbb commit d26a585

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## Version 0.5.16-0.5.23
3+
## Version 0.5.16-0.5.24
44

55
- bugfixes, dependency updates, template, CI improvements
66

src/kiara/interfaces/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323

2424
from kiara.exceptions import KiaraException
25+
from kiara.utils import is_emscripten
2526
from kiara.utils.cli import terminal_print
2627

2728
if TYPE_CHECKING:
@@ -332,9 +333,10 @@ def base_api(self) -> "BaseAPI":
332333
)
333334
os.execvp(sys.executable, (sys.executable,) + tuple(sys.argv)) # noqa
334335

335-
import fasteners
336+
if not is_emscripten():
337+
import fasteners
336338

337-
fasteners.InterProcessReaderWriterLock(self.lock_file(context))
339+
fasteners.InterProcessReaderWriterLock(self.lock_file(context))
338340

339341
api.set_active_context(context, create=True)
340342

src/kiara/registries/ids/__init__.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
#
77
# Mozilla Public License, version 2.0 (see LICENSE or https://www.mozilla.org/en-US/MPL/2.0/)
88
import uuid
9-
from typing import Any, Dict, Type, Union
9+
from typing import TYPE_CHECKING, Any, Dict, Type, Union
1010
from weakref import WeakValueDictionary
1111

1212
import structlog
13-
from fasteners import InterProcessLock
1413

1514
from kiara.defaults import KIARA_MAIN_CONTEXT_LOCKS_PATH
16-
from kiara.utils import is_debug, is_develop
15+
from kiara.utils import is_debug, is_develop, is_emscripten
16+
17+
if TYPE_CHECKING:
18+
from fasteners import InterProcessLock
1719

1820
logger = structlog.getLogger()
1921

@@ -30,26 +32,32 @@ def __init__(self) -> None:
3032
self._process_context_locks: Dict[uuid.UUID, InterProcessLock] = {}
3133

3234
def lock_context(self, context_id: uuid.UUID) -> bool:
33-
if context_id not in self._process_context_locks.keys():
34-
lock = InterProcessLock(
35-
os.path.join(
36-
KIARA_MAIN_CONTEXT_LOCKS_PATH, f"context_{context_id}.lock"
35+
if not is_emscripten():
36+
from fasteners import InterProcessLock
37+
38+
if context_id not in self._process_context_locks.keys():
39+
lock = InterProcessLock(
40+
os.path.join(
41+
KIARA_MAIN_CONTEXT_LOCKS_PATH, f"context_{context_id}.lock"
42+
)
3743
)
38-
)
39-
self._process_context_locks[context_id] = lock
40-
else:
41-
lock = self._process_context_locks[context_id]
44+
self._process_context_locks[context_id] = lock
45+
else:
46+
lock = self._process_context_locks[context_id]
4247

43-
aquired: bool = lock.acquire(blocking=False)
44-
return aquired
48+
aquired: bool = lock.acquire(blocking=False)
49+
return aquired
50+
else:
51+
return True
4552

4653
def unlock_context(self, context_id: uuid.UUID):
47-
if context_id not in self._process_context_locks.keys():
48-
return
54+
if not is_emscripten():
55+
if context_id not in self._process_context_locks.keys():
56+
return
4957

50-
lock = self._process_context_locks[context_id]
51-
if lock.acquired:
52-
lock.release()
58+
lock = self._process_context_locks[context_id]
59+
if lock.acquired:
60+
lock.release()
5361

5462
def generate(
5563
self,

src/kiara/utils/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import inspect
99
import os
1010
import re
11+
import sys
1112
from typing import TYPE_CHECKING, Dict, Iterable, List, Type, TypeVar
1213

1314
import structlog
@@ -43,6 +44,12 @@ def is_develop() -> bool:
4344
return False
4445

4546

47+
def is_emscripten() -> bool:
48+
"""Check if we're running in Emscripten / Pyodide environment."""
49+
50+
return sys.platform == "emscripten"
51+
52+
4653
def get_dev_config() -> "KiaraDevSettings":
4754
from kiara.utils.develop import KIARA_DEV_SETTINGS
4855

0 commit comments

Comments
 (0)