hmr 0.6.1.3__tar.gz → 0.6.2.1__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.6.1.3
3
+ Version: 0.6.2.1
4
4
  Summary: Hot Module Reload for Python
5
5
  Keywords: reactive-programming,reload,signals,hmr
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -8,7 +8,7 @@ Classifier: Intended Audience :: Developers
8
8
  Classifier: Operating System :: OS Independent
9
9
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
10
10
  Classifier: Typing :: Typed
11
- Project-URL: repository, https://github.com/promplate/pyth-on-line/tree/reactivity
11
+ Project-URL: repository, https://github.com/promplate/pyth-on-line/tree/main/packages/hmr
12
12
  Requires-Python: >=3.12
13
13
  Requires-Dist: watchfiles<2,>=0.21; sys_platform != "emscripten"
14
14
  Description-Content-Type: text/markdown
@@ -28,7 +28,7 @@ Description-Content-Type: text/markdown
28
28
  HMR means Hot Module Reload / [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/). It is a feature that allows part of your app to be updated at runtime without a full rerun.
29
29
 
30
30
  - The module whose source file **you changed** will rerun
31
- - The module / function that **depend on** the changed module will rerun
31
+ - The module / function that **depends on** the changed module will rerun
32
32
  - Other modules that are unaffected (like third-party libraries) will not rerun
33
33
 
34
34
  Thus, in contrast to the traditional way of **cold-reloading** Python applications (like [watchfiles CLI](https://watchfiles.helpmanual.io/cli/)), HMR is just more efficient.
@@ -13,7 +13,7 @@
13
13
  HMR means Hot Module Reload / [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/). It is a feature that allows part of your app to be updated at runtime without a full rerun.
14
14
 
15
15
  - The module whose source file **you changed** will rerun
16
- - The module / function that **depend on** the changed module will rerun
16
+ - The module / function that **depends on** the changed module will rerun
17
17
  - Other modules that are unaffected (like third-party libraries) will not rerun
18
18
 
19
19
  Thus, in contrast to the traditional way of **cold-reloading** Python applications (like [watchfiles CLI](https://watchfiles.helpmanual.io/cli/)), HMR is just more efficient.
@@ -20,13 +20,13 @@ description = "Hot Module Reload for Python"
20
20
  dependencies = [
21
21
  "watchfiles>=0.21,<2 ; sys_platform != 'emscripten'",
22
22
  ]
23
- version = "0.6.1.3"
23
+ version = "0.6.2.1"
24
24
 
25
25
  [project.scripts]
26
26
  hmr = "reactivity.hmr:cli"
27
27
 
28
28
  [project.urls]
29
- repository = "https://github.com/promplate/pyth-on-line/tree/reactivity"
29
+ repository = "https://github.com/promplate/pyth-on-line/tree/main/packages/hmr"
30
30
 
31
31
  [build-system]
32
32
  requires = [
@@ -9,14 +9,14 @@ from inspect import currentframe, ismethod
9
9
  from pathlib import Path
10
10
  from site import getsitepackages
11
11
  from types import ModuleType, TracebackType
12
- from typing import Any, Self
12
+ from typing import Self
13
13
  from weakref import WeakValueDictionary
14
14
 
15
- from .. import Reactive
16
- from ..context import new_context
15
+ from ..context import Context, new_context
17
16
  from ..helpers import DerivedMethod
18
17
  from ..primitives import BaseDerived, Derived, Signal
19
18
  from .hooks import call_post_reload_hooks, call_pre_reload_hooks
19
+ from .proxy import Proxy
20
20
 
21
21
 
22
22
  def is_called_internally(*, extra_depth=0) -> bool:
@@ -39,10 +39,9 @@ class Name(Signal, BaseDerived):
39
39
  HMR_CONTEXT = new_context()
40
40
 
41
41
 
42
- class NamespaceProxy(Reactive[str, Any]):
43
- def __init__(self, initial: MutableMapping, module: "ReactiveModule", check_equality=True):
44
- super().__init__(initial, check_equality, context=HMR_CONTEXT)
45
- self._original = initial
42
+ class NamespaceProxy(Proxy):
43
+ def __init__(self, initial: MutableMapping, module: "ReactiveModule", check_equality=True, *, context: Context | None = None):
44
+ super().__init__(initial, check_equality, context=context)
46
45
  self.module = module
47
46
 
48
47
  def _null(self):
@@ -50,7 +49,7 @@ class NamespaceProxy(Reactive[str, Any]):
50
49
  signal.dependencies.add(self.module.load)
51
50
  return signal
52
51
 
53
- def __getitem__(self, key: str):
52
+ def __getitem__(self, key):
54
53
  try:
55
54
  return super().__getitem__(key)
56
55
  finally:
@@ -60,14 +59,6 @@ class NamespaceProxy(Reactive[str, Any]):
60
59
  signal.subscribers.remove(self.module.load)
61
60
  self.module.load.dependencies.remove(signal)
62
61
 
63
- def __setitem__(self, key, value):
64
- self._original[key] = value
65
- return super().__setitem__(key, value)
66
-
67
- def __delitem__(self, key):
68
- del self._original[key]
69
- return super().__delitem__(key)
70
-
71
62
 
72
63
  class ReactiveModule(ModuleType):
73
64
  instances: WeakValueDictionary[Path, Self] = WeakValueDictionary()
@@ -79,7 +70,7 @@ class ReactiveModule(ModuleType):
79
70
  self.__is_initialized = True
80
71
 
81
72
  self.__namespace = namespace
82
- self.__namespace_proxy = NamespaceProxy(namespace, self)
73
+ self.__namespace_proxy = NamespaceProxy(namespace, self, context=HMR_CONTEXT)
83
74
  self.__file = file
84
75
 
85
76
  __class__.instances[file.resolve()] = self
@@ -97,7 +88,7 @@ class ReactiveModule(ModuleType):
97
88
  except SyntaxError as e:
98
89
  sys.excepthook(type(e), e, e.__traceback__)
99
90
  else:
100
- exec(code, self.__namespace, self.__namespace_proxy)
91
+ exec(code, self.__namespace, self.__namespace_proxy) # https://github.com/python/cpython/issues/121306
101
92
  finally:
102
93
  load = self.__load
103
94
  assert ismethod(load.fn) # for type narrowing
@@ -344,4 +335,4 @@ def cli():
344
335
  reloader.keep_watching_until_interrupt()
345
336
 
346
337
 
347
- __version__ = "0.6.1.3"
338
+ __version__ = "0.6.2.1"
@@ -0,0 +1,19 @@
1
+ from collections.abc import MutableMapping
2
+ from typing import Any
3
+
4
+ from ..context import Context
5
+ from ..helpers import Reactive
6
+
7
+
8
+ class Proxy[T: MutableMapping](Reactive[str, Any]):
9
+ def __init__(self, initial: T, check_equality=True, *, context: Context | None = None):
10
+ super().__init__(initial, check_equality, context=context)
11
+ self.raw: T = initial
12
+
13
+ def __setitem__(self, key, value):
14
+ self.raw[key] = value
15
+ super().__setitem__(key, value)
16
+
17
+ def __delitem__(self, key):
18
+ del self.raw[key]
19
+ super().__delitem__(key)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes