hmr 0.0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hmr
3
- Version: 0.0.2.2
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
@@ -6,7 +6,7 @@ description = "Hot Module Reload for Python"
6
6
  dependencies = [
7
7
  "watchfiles>=0.21,<2",
8
8
  ]
9
- version = "0.0.2.2"
9
+ version = "0.0.3"
10
10
 
11
11
  [project.scripts]
12
12
  hmr = "reactivity.hmr:cli"
@@ -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,7 +27,7 @@ def is_called_in_this_file() -> bool:
26
27
  return frame.f_globals.get("__file__") == __file__
27
28
 
28
29
 
29
- class NamespaceProxy(Reactive):
30
+ class NamespaceProxy(Reactive[str, Any]):
30
31
  def __init__(self, initial: MutableMapping, check_equality=True):
31
32
  super().__init__(initial, check_equality)
32
33
  self._original = initial
@@ -43,6 +44,10 @@ class NamespaceProxy(Reactive):
43
44
  class ReactiveModule(ModuleType):
44
45
  def __init__(self, file: Path, namespace: dict, name: str, doc: str | None = None):
45
46
  super().__init__(name, doc)
47
+ self.__is_initialized = False
48
+ self.__dict__.update(namespace)
49
+ self.__is_initialized = True
50
+
46
51
  self.__namespace = namespace
47
52
  self.__namespace_proxy = NamespaceProxy(namespace)
48
53
  self.__file = file
@@ -56,9 +61,18 @@ class ReactiveModule(ModuleType):
56
61
  @property
57
62
  def load(self):
58
63
  if is_called_in_this_file():
59
- 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)
60
66
  raise AttributeError("load")
61
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
+
62
76
  def __getattr__(self, name: str):
63
77
  try:
64
78
  return self.__namespace_proxy[name]
@@ -78,7 +92,7 @@ class ReactiveModuleLoader(Loader):
78
92
  self._is_package = is_package
79
93
 
80
94
  def create_module(self, spec: ModuleSpec):
81
- namespace = {}
95
+ namespace = {"__file__": str(self._file), "__spec__": spec, "__loader__": self}
82
96
  if self._is_package:
83
97
  assert self._file.name == "__init__.py"
84
98
  namespace["__path__"] = [str(self._file.parent.parent)]
@@ -232,4 +246,4 @@ def cli():
232
246
  SyncReloader(entry, excludes={".venv"}).keep_watching_until_interrupt()
233
247
 
234
248
 
235
- __version__ = "0.0.2.2"
249
+ __version__ = "0.0.3"
File without changes
File without changes
File without changes
File without changes