hmr 0.0.2.1__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hmr-0.0.2.1 → hmr-0.0.3}/PKG-INFO +1 -1
- {hmr-0.0.2.1 → hmr-0.0.3}/pyproject.toml +1 -1
- {hmr-0.0.2.1 → hmr-0.0.3}/reactivity/hmr.py +34 -7
- {hmr-0.0.2.1 → hmr-0.0.3}/reactivity/__init__.py +0 -0
- {hmr-0.0.2.1 → hmr-0.0.3}/reactivity/functional.py +0 -0
- {hmr-0.0.2.1 → hmr-0.0.3}/reactivity/helpers.py +0 -0
- {hmr-0.0.2.1 → hmr-0.0.3}/reactivity/primitives.py +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import sys
|
2
|
-
from collections.abc import Iterable, Sequence
|
2
|
+
from collections.abc import Iterable, MutableMapping, Sequence
|
3
3
|
from contextlib import suppress
|
4
4
|
from functools import cached_property
|
5
5
|
from importlib.abc import Loader, MetaPathFinder
|
@@ -9,6 +9,7 @@ from inspect import currentframe
|
|
9
9
|
from pathlib import Path
|
10
10
|
from runpy import run_path
|
11
11
|
from types import ModuleType
|
12
|
+
from typing import Any
|
12
13
|
|
13
14
|
from . import Reactive, batch, create_effect, memoized_method
|
14
15
|
|
@@ -26,11 +27,29 @@ def is_called_in_this_file() -> bool:
|
|
26
27
|
return frame.f_globals.get("__file__") == __file__
|
27
28
|
|
28
29
|
|
30
|
+
class NamespaceProxy(Reactive[str, Any]):
|
31
|
+
def __init__(self, initial: MutableMapping, check_equality=True):
|
32
|
+
super().__init__(initial, check_equality)
|
33
|
+
self._original = initial
|
34
|
+
|
35
|
+
def __setitem__(self, key, value):
|
36
|
+
self._original[key] = value
|
37
|
+
return super().__setitem__(key, value)
|
38
|
+
|
39
|
+
def __delitem__(self, key):
|
40
|
+
del self._original[key]
|
41
|
+
return super().__delitem__(key)
|
42
|
+
|
43
|
+
|
29
44
|
class ReactiveModule(ModuleType):
|
30
45
|
def __init__(self, file: Path, namespace: dict, name: str, doc: str | None = None):
|
31
46
|
super().__init__(name, doc)
|
47
|
+
self.__is_initialized = False
|
48
|
+
self.__dict__.update(namespace)
|
49
|
+
self.__is_initialized = True
|
50
|
+
|
32
51
|
self.__namespace = namespace
|
33
|
-
self.__namespace_proxy =
|
52
|
+
self.__namespace_proxy = NamespaceProxy(namespace)
|
34
53
|
self.__file = file
|
35
54
|
|
36
55
|
@property
|
@@ -42,9 +61,18 @@ class ReactiveModule(ModuleType):
|
|
42
61
|
@property
|
43
62
|
def load(self):
|
44
63
|
if is_called_in_this_file():
|
45
|
-
|
64
|
+
code = compile(self.__file.read_text("utf-8"), str(self.__file), "exec", dont_inherit=True)
|
65
|
+
return lambda: exec(code, self.__namespace, self.__namespace_proxy)
|
46
66
|
raise AttributeError("load")
|
47
67
|
|
68
|
+
def __dir__(self):
|
69
|
+
return iter(self.__namespace_proxy)
|
70
|
+
|
71
|
+
def __getattribute__(self, name: str):
|
72
|
+
if name == "__dict__" and self.__is_initialized:
|
73
|
+
return self.__namespace
|
74
|
+
return super().__getattribute__(name)
|
75
|
+
|
48
76
|
def __getattr__(self, name: str):
|
49
77
|
try:
|
50
78
|
return self.__namespace_proxy[name]
|
@@ -64,11 +92,10 @@ class ReactiveModuleLoader(Loader):
|
|
64
92
|
self._is_package = is_package
|
65
93
|
|
66
94
|
def create_module(self, spec: ModuleSpec):
|
67
|
-
namespace = {}
|
95
|
+
namespace = {"__file__": str(self._file), "__spec__": spec, "__loader__": self}
|
68
96
|
if self._is_package:
|
69
97
|
assert self._file.name == "__init__.py"
|
70
98
|
namespace["__path__"] = [str(self._file.parent.parent)]
|
71
|
-
namespace["__package__"] = spec.name
|
72
99
|
return ReactiveModule(self._file, namespace, spec.name)
|
73
100
|
|
74
101
|
def exec_module(self, module: ModuleType):
|
@@ -100,7 +127,7 @@ class ReactiveModuleFinder(MetaPathFinder):
|
|
100
127
|
return spec_from_loader(fullname, ReactiveModuleLoader(file), origin=str(file))
|
101
128
|
file = directory / f"{fullname.replace('.', '/')}/__init__.py"
|
102
129
|
if file.is_file() and all(not file.is_relative_to(exclude) for exclude in self.excludes):
|
103
|
-
return spec_from_loader(fullname, ReactiveModuleLoader(file, is_package=True), origin=str(file))
|
130
|
+
return spec_from_loader(fullname, ReactiveModuleLoader(file, is_package=True), origin=str(file), is_package=True)
|
104
131
|
|
105
132
|
|
106
133
|
def patch_module(name_or_module: str | ModuleType):
|
@@ -219,4 +246,4 @@ def cli():
|
|
219
246
|
SyncReloader(entry, excludes={".venv"}).keep_watching_until_interrupt()
|
220
247
|
|
221
248
|
|
222
|
-
__version__ = "0.0.
|
249
|
+
__version__ = "0.0.3"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|