hmr 0.3.3.1__py3-none-any.whl → 0.3.3.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.3.3.1
3
+ Version: 0.3.3.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
@@ -1,13 +1,13 @@
1
- hmr-0.3.3.1.dist-info/METADATA,sha256=i7tLdHbmQlSY2AiGNO_3uqmEStVLcsD12rmmzF9O8Yw,260
2
- hmr-0.3.3.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- hmr-0.3.3.1.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
1
+ hmr-0.3.3.3.dist-info/METADATA,sha256=TWN_VystOGF0zdKckjiayJus6XK7GJ-L03xlibtXs2E,260
2
+ hmr-0.3.3.3.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ hmr-0.3.3.3.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
4
4
  reactivity/__init__.py,sha256=pX-RUzkezCC1x4eOWGxNhXbwrbvBLP_3pQuZr9eZz1Y,300
5
5
  reactivity/functional.py,sha256=U06vshcVhZ0sb218gcmHtEhfgTNAGtQ7zyvPz2w5qKM,1292
6
6
  reactivity/helpers.py,sha256=7gwsIKKrjEahSz9G9oR4s1LdYXQTCIMO0k4UGXGla9Y,3714
7
7
  reactivity/hmr/__init__.py,sha256=S5ZIHqCRpevdzWuhS0aCua_S8F0LkK0YNg6IgeTScFQ,177
8
8
  reactivity/hmr/api.py,sha256=-0-6Tn0AVkaDs7_qrCCd9TXxRTPDMDB08-UYfepTdec,1644
9
- reactivity/hmr/core.py,sha256=SCZi7vlSy4IPHQRTVpjlMn3am5L9sYN5zCE1nKw07eM,10163
9
+ reactivity/hmr/core.py,sha256=TSbL1AMiel2eKzk23z1Sb8ruCTx9s5m6blbj0L9RGD4,10252
10
10
  reactivity/hmr/hooks.py,sha256=-yLr5ktiyqPb1nDbHsgv6-c_ZkziBjNqCU-0PCfXGYU,592
11
- reactivity/hmr/utils.py,sha256=zgKjz3RhcUDYLoIqZFRVBcPtPWUJA1YphJycyrQx3tk,1464
11
+ reactivity/hmr/utils.py,sha256=zM7X5I8ywOguOt20uE55INWOGen3FuJZDAvgouu7lI8,1550
12
12
  reactivity/primitives.py,sha256=DR2waJbzhVKOioHXMliE4FIsxQUq7DZA0umPrlvchA4,4217
13
- hmr-0.3.3.1.dist-info/RECORD,,
13
+ hmr-0.3.3.3.dist-info/RECORD,,
reactivity/hmr/core.py CHANGED
@@ -9,7 +9,8 @@ from inspect import currentframe
9
9
  from pathlib import Path
10
10
  from site import getsitepackages
11
11
  from types import ModuleType, TracebackType
12
- from typing import Any
12
+ from typing import Any, Self
13
+ from weakref import WeakValueDictionary
13
14
 
14
15
  from .. import Reactive, batch, memoized_method
15
16
  from .hooks import call_post_reload_hooks, call_pre_reload_hooks
@@ -43,6 +44,8 @@ class NamespaceProxy(Reactive[str, Any]):
43
44
 
44
45
 
45
46
  class ReactiveModule(ModuleType):
47
+ instances: WeakValueDictionary[Path, Self] = WeakValueDictionary()
48
+
46
49
  def __init__(self, file: Path, namespace: dict, name: str, doc: str | None = None):
47
50
  super().__init__(name, doc)
48
51
  self.__is_initialized = False
@@ -53,6 +56,8 @@ class ReactiveModule(ModuleType):
53
56
  self.__namespace_proxy = NamespaceProxy(namespace)
54
57
  self.__file = file
55
58
 
59
+ self.instances[file.resolve()] = self
60
+
56
61
  @property
57
62
  def file(self):
58
63
  if is_called_in_this_file():
@@ -155,7 +160,7 @@ def patch_meta_path(includes: Iterable[str] = (".",), excludes: Iterable[str] =
155
160
 
156
161
 
157
162
  def get_path_module_map():
158
- return {module.file.resolve(): module for module in sys.modules.values() if isinstance(module, ReactiveModule)}
163
+ return {**ReactiveModule.instances}
159
164
 
160
165
 
161
166
  class ErrorFilter:
@@ -307,4 +312,4 @@ def cli():
307
312
  SyncReloader(entry).keep_watching_until_interrupt()
308
313
 
309
314
 
310
- __version__ = "0.3.3.1"
315
+ __version__ = "0.3.3.3"
reactivity/hmr/utils.py CHANGED
@@ -1,8 +1,8 @@
1
- import sys
2
1
  from collections import UserDict
3
2
  from collections.abc import Callable
4
3
  from functools import wraps
5
- from inspect import getsource
4
+ from inspect import getsource, getsourcefile
5
+ from pathlib import Path
6
6
  from types import FunctionType
7
7
 
8
8
  from .. import create_memo
@@ -28,9 +28,11 @@ def clear_memos():
28
28
 
29
29
 
30
30
  def cache_across_reloads[T](func: Callable[[], T]) -> Callable[[], T]:
31
- module = sys.modules[func.__module__]
31
+ file = getsourcefile(func)
32
+ assert file is not None
33
+ module = ReactiveModule.instances.get(Path(file).resolve())
32
34
 
33
- if not isinstance(module, ReactiveModule):
35
+ if module is None:
34
36
  from functools import cache
35
37
 
36
38
  return cache(func) # type: ignore
File without changes