hmr 0.0.2.1__tar.gz → 0.0.2.2__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.1
3
+ Version: 0.0.2.2
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.1"
9
+ version = "0.0.2.2"
10
10
 
11
11
  [project.scripts]
12
12
  hmr = "reactivity.hmr:cli"
@@ -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
@@ -26,11 +26,25 @@ def is_called_in_this_file() -> bool:
26
26
  return frame.f_globals.get("__file__") == __file__
27
27
 
28
28
 
29
+ class NamespaceProxy(Reactive):
30
+ def __init__(self, initial: MutableMapping, check_equality=True):
31
+ super().__init__(initial, check_equality)
32
+ self._original = initial
33
+
34
+ def __setitem__(self, key, value):
35
+ self._original[key] = value
36
+ return super().__setitem__(key, value)
37
+
38
+ def __delitem__(self, key):
39
+ del self._original[key]
40
+ return super().__delitem__(key)
41
+
42
+
29
43
  class ReactiveModule(ModuleType):
30
44
  def __init__(self, file: Path, namespace: dict, name: str, doc: str | None = None):
31
45
  super().__init__(name, doc)
32
46
  self.__namespace = namespace
33
- self.__namespace_proxy = Reactive(namespace)
47
+ self.__namespace_proxy = NamespaceProxy(namespace)
34
48
  self.__file = file
35
49
 
36
50
  @property
@@ -68,7 +82,6 @@ class ReactiveModuleLoader(Loader):
68
82
  if self._is_package:
69
83
  assert self._file.name == "__init__.py"
70
84
  namespace["__path__"] = [str(self._file.parent.parent)]
71
- namespace["__package__"] = spec.name
72
85
  return ReactiveModule(self._file, namespace, spec.name)
73
86
 
74
87
  def exec_module(self, module: ModuleType):
@@ -100,7 +113,7 @@ class ReactiveModuleFinder(MetaPathFinder):
100
113
  return spec_from_loader(fullname, ReactiveModuleLoader(file), origin=str(file))
101
114
  file = directory / f"{fullname.replace('.', '/')}/__init__.py"
102
115
  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))
116
+ return spec_from_loader(fullname, ReactiveModuleLoader(file, is_package=True), origin=str(file), is_package=True)
104
117
 
105
118
 
106
119
  def patch_module(name_or_module: str | ModuleType):
@@ -219,4 +232,4 @@ def cli():
219
232
  SyncReloader(entry, excludes={".venv"}).keep_watching_until_interrupt()
220
233
 
221
234
 
222
- __version__ = "0.0.2.1"
235
+ __version__ = "0.0.2.2"
File without changes
File without changes
File without changes
File without changes