hmr 0.0.2.1__py3-none-any.whl → 0.0.3__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hmr
3
- Version: 0.0.2.1
3
+ Version: 0.0.3
4
4
  Summary: Hot Module Reload for Python
5
5
  Project-URL: repository, https://github.com/promplate/pyth-on-line/tree/reactivity
6
6
  Requires-Python: >=3.12
@@ -0,0 +1,9 @@
1
+ hmr-0.0.3.dist-info/METADATA,sha256=p98mCIdhqoduIMYRW_Lme7IlbZsfmzQ-czinyxdTzmo,228
2
+ hmr-0.0.3.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ hmr-0.0.3.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
4
+ reactivity/__init__.py,sha256=Stl2BBvqzutjcmF-O-olFTbSzJxzAl1xNMbu8mAVjlo,320
5
+ reactivity/functional.py,sha256=KAsqgPQsxIGuqO4BAtH6VF78MigLSBQ2k3aL4o_Vffg,1290
6
+ reactivity/helpers.py,sha256=auLTDFjfFc-cU9kVfm356GALW9lJIQ_UV7LGRZ2fWIw,3434
7
+ reactivity/hmr.py,sha256=VmFpw9OZV4yiO0LuNu2wRfN4q-QoDvhPSDdjjixR1e8,8543
8
+ reactivity/primitives.py,sha256=EIa_-5XOhffKw_lJ13EoAmFD3l0u_LFG1pJbODZSpMw,3351
9
+ hmr-0.0.3.dist-info/RECORD,,
reactivity/hmr.py CHANGED
@@ -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 = Reactive(namespace)
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
- return lambda: exec(self.__file.read_text("utf-8"), self.__namespace, self.__namespace_proxy)
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.2.1"
249
+ __version__ = "0.0.3"
@@ -1,9 +0,0 @@
1
- hmr-0.0.2.1.dist-info/METADATA,sha256=MylYN2Fwl4ZgrR9tCWyIEaBb5Lnz90iwgPE-hdVowc0,230
2
- hmr-0.0.2.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- hmr-0.0.2.1.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
4
- reactivity/__init__.py,sha256=Stl2BBvqzutjcmF-O-olFTbSzJxzAl1xNMbu8mAVjlo,320
5
- reactivity/functional.py,sha256=KAsqgPQsxIGuqO4BAtH6VF78MigLSBQ2k3aL4o_Vffg,1290
6
- reactivity/helpers.py,sha256=auLTDFjfFc-cU9kVfm356GALW9lJIQ_UV7LGRZ2fWIw,3434
7
- reactivity/hmr.py,sha256=E8RwUl_kggFU8nWoUVxEDA7NYMf5gy_RQG5S7O6MB8o,7597
8
- reactivity/primitives.py,sha256=EIa_-5XOhffKw_lJ13EoAmFD3l0u_LFG1pJbODZSpMw,3351
9
- hmr-0.0.2.1.dist-info/RECORD,,
File without changes