hmr 0.0.1__py3-none-any.whl → 0.0.2__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.1
3
+ Version: 0.0.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
@@ -0,0 +1,9 @@
1
+ hmr-0.0.2.dist-info/METADATA,sha256=duLyWpJHm02MnF37QbCMk-0EebdOcZ4hVnO0xhFgL7I,228
2
+ hmr-0.0.2.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ hmr-0.0.2.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=MI9LV1eU5hs_v3bIIS_ANDIDLas76ULZ60A6rZiJDK4,7585
8
+ reactivity/primitives.py,sha256=EIa_-5XOhffKw_lJ13EoAmFD3l0u_LFG1pJbODZSpMw,3351
9
+ hmr-0.0.2.dist-info/RECORD,,
reactivity/helpers.py CHANGED
@@ -5,7 +5,7 @@ from weakref import WeakKeyDictionary
5
5
  from .primitives import BaseComputation, Batch, Signal, Subscribable
6
6
 
7
7
 
8
- class Memoized[T](Subscribable, BaseComputation):
8
+ class Memoized[T](Subscribable, BaseComputation[T]):
9
9
  def __init__(self, fn: Callable[[], T]):
10
10
  super().__init__()
11
11
  self.fn = fn
@@ -53,9 +53,14 @@ class MemoizedMethod[T, Self]:
53
53
  def __init__(self, method: Callable[[Self], T]):
54
54
  super().__init__()
55
55
  self.method = method
56
+ self.map = WeakKeyDictionary[Self, Memoized]()
56
57
 
57
58
  def __get__(self, instance, owner):
58
- return Memoized(partial(self.method, instance))
59
+ try:
60
+ return self.map[instance]
61
+ except KeyError:
62
+ self.map[instance] = memo = Memoized(partial(self.method, instance))
63
+ return memo
59
64
 
60
65
 
61
66
  class Reactive[K, V](Subscribable, MutableMapping[K, V]):
reactivity/hmr.py CHANGED
@@ -152,12 +152,13 @@ class BaseReloader:
152
152
  if type is Change.modified:
153
153
  path = Path(file).resolve()
154
154
  if path.samefile(self.entry):
155
- self.run_entry_file()
155
+ self.run_entry_file.trigger()
156
156
  elif module := path2module.get(path):
157
157
  try:
158
158
  module.load()
159
159
  except Exception as e:
160
160
  sys.excepthook(e.__class__, e, e.__traceback__)
161
+ self.run_entry_file()
161
162
 
162
163
 
163
164
  class SyncReloader(BaseReloader):
@@ -209,7 +210,13 @@ class AsyncReloader(BaseReloader):
209
210
 
210
211
 
211
212
  def cli():
213
+ if len(sys.argv) < 2:
214
+ print("\n Usage: hmr <entry file>, just like python <entry file>\n")
215
+ exit(1)
212
216
  entry = sys.argv[-1]
213
217
  assert Path(entry).is_file(), f"{entry} is not a file"
214
218
  sys.path.insert(0, ".")
215
219
  SyncReloader(entry, excludes={".venv"}).keep_watching_until_interrupt()
220
+
221
+
222
+ __version__ = "0.0.2"
reactivity/primitives.py CHANGED
@@ -22,7 +22,7 @@ class Subscribable:
22
22
  subscriber.trigger()
23
23
 
24
24
 
25
- class BaseComputation:
25
+ class BaseComputation[T]:
26
26
  def __init__(self):
27
27
  super().__init__()
28
28
  self.dependencies = WeakSet[Subscribable]()
@@ -46,7 +46,7 @@ class BaseComputation:
46
46
  def __exit__(self, *_):
47
47
  self.dispose()
48
48
 
49
- def trigger(self) -> Any: ...
49
+ def trigger(self) -> T: ...
50
50
 
51
51
  def __call__(self):
52
52
  return self.trigger()
@@ -94,7 +94,7 @@ class State[T](Signal[T]):
94
94
  state.set(value)
95
95
 
96
96
 
97
- class Derived[T](BaseComputation):
97
+ class Derived[T](BaseComputation[T]):
98
98
  def __init__(self, fn: Callable[[], T], auto_run=True):
99
99
  super().__init__()
100
100
 
@@ -1,9 +0,0 @@
1
- hmr-0.0.1.dist-info/METADATA,sha256=Z9tnvo1XFCBFioLgAyeAheBfjkCzG2YnWxj8btdlohs,228
2
- hmr-0.0.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- hmr-0.0.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=xb3UThn7CGqJizCeing-vUBVZFwufadIEdWOgCFmuBo,3251
7
- reactivity/hmr.py,sha256=97JT1aFiiL_WoVS7uewIdY_5Vr-dHt6Rz5BKvpP8234,7400
8
- reactivity/primitives.py,sha256=7E99QLSblRfO3wPxRDpVqw8-KR2VI2g4QheShBXFv1g,3347
9
- hmr-0.0.1.dist-info/RECORD,,
File without changes