hmr 0.3.1__py3-none-any.whl → 0.3.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.3.1
3
+ Version: 0.3.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
@@ -1,12 +1,13 @@
1
- hmr-0.3.1.dist-info/METADATA,sha256=FFdtgroAM1y53V1v6djFpckQYsQ2UCkkQezGr6WXHAk,258
2
- hmr-0.3.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- hmr-0.3.1.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
1
+ hmr-0.3.2.dist-info/METADATA,sha256=zfw1PcNenS5CDvOtkomtt3sLr8vBwrdzTqcjsYNvcFM,258
2
+ hmr-0.3.2.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ hmr-0.3.2.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
- reactivity/hmr/core.py,sha256=iud3bBb5YYilZYs78DURJbjaeZlOnts53GXJgLxSAnE,9996
8
+ reactivity/hmr/api.py,sha256=eqxQuqJUCbHE6vdHplWxxJt1RdItFC42neOB_exbPkE,1665
9
+ reactivity/hmr/core.py,sha256=WLF-GJitT9L8YmmWKyvfrw3WnFfH3bMSJ9MEYrXcM-E,10237
9
10
  reactivity/hmr/hooks.py,sha256=-yLr5ktiyqPb1nDbHsgv6-c_ZkziBjNqCU-0PCfXGYU,592
10
11
  reactivity/hmr/utils.py,sha256=zgKjz3RhcUDYLoIqZFRVBcPtPWUJA1YphJycyrQx3tk,1464
11
12
  reactivity/primitives.py,sha256=DR2waJbzhVKOioHXMliE4FIsxQUq7DZA0umPrlvchA4,4217
12
- hmr-0.3.1.dist-info/RECORD,,
13
+ hmr-0.3.2.dist-info/RECORD,,
reactivity/hmr/api.py ADDED
@@ -0,0 +1,60 @@
1
+ from .core import AsyncReloader, SyncReloader
2
+
3
+
4
+ class SyncReloaderAPI(SyncReloader):
5
+ def __enter__(self):
6
+ from threading import Thread
7
+
8
+ self.run_entry_file()
9
+ self.thread = Thread(target=self.start_watching)
10
+ self.thread.start()
11
+ return super()
12
+
13
+ def __exit__(self, *_):
14
+ self.stop_watching()
15
+ self.thread.join()
16
+ self.run_entry_file.dispose()
17
+ self.run_entry_file.invalidate()
18
+
19
+ async def __aenter__(self):
20
+ from asyncio import ensure_future, to_thread
21
+
22
+ self.run_entry_file()
23
+ self.future = ensure_future(to_thread(self.start_watching))
24
+ return super()
25
+
26
+ async def __aexit__(self, *_):
27
+ self.stop_watching()
28
+ await self.future
29
+ self.run_entry_file.dispose()
30
+ self.run_entry_file.invalidate()
31
+
32
+
33
+ class AsyncReloaderAPI(AsyncReloader):
34
+ def __enter__(self):
35
+ from asyncio import run
36
+ from threading import Thread
37
+
38
+ self.run_entry_file()
39
+ self.thread = Thread(target=lambda: run(self.start_watching()))
40
+ self.thread.start()
41
+ return super()
42
+
43
+ def __exit__(self, *_):
44
+ self.stop_watching()
45
+ self.thread.join()
46
+ self.run_entry_file.dispose()
47
+ self.run_entry_file.invalidate()
48
+
49
+ async def __aenter__(self):
50
+ from asyncio import ensure_future, to_thread
51
+
52
+ await to_thread(self.run_entry_file)
53
+ self.future = ensure_future(self.start_watching())
54
+ return super()
55
+
56
+ async def __aexit__(self, *_):
57
+ self.stop_watching()
58
+ await self.future
59
+ self.run_entry_file.dispose()
60
+ self.run_entry_file.invalidate()
reactivity/hmr/core.py CHANGED
@@ -233,16 +233,24 @@ class BaseReloader:
233
233
  self.run_entry_file()
234
234
 
235
235
 
236
+ class _SimpleEvent:
237
+ def __init__(self):
238
+ self._set = False
239
+
240
+ def set(self):
241
+ self._set = True
242
+
243
+ def is_set(self):
244
+ return self._set
245
+
246
+
236
247
  class SyncReloader(BaseReloader):
237
248
  @cached_property
238
249
  def _stop_event(self):
239
- from threading import Event
240
-
241
- return Event()
250
+ return _SimpleEvent()
242
251
 
243
252
  def stop_watching(self):
244
253
  self._stop_event.set()
245
- del self._stop_event
246
254
 
247
255
  def start_watching(self):
248
256
  from watchfiles import watch
@@ -250,6 +258,10 @@ class SyncReloader(BaseReloader):
250
258
  for events in watch(self.entry, *self.includes, watch_filter=self.watch_filter, stop_event=self._stop_event):
251
259
  self.on_events(events)
252
260
 
261
+ # this should only be called when the stop event is set
262
+ assert self._stop_event.is_set()
263
+ del self._stop_event
264
+
253
265
  def keep_watching_until_interrupt(self):
254
266
  with suppress(KeyboardInterrupt):
255
267
  self.run_entry_file()
@@ -292,4 +304,4 @@ def cli():
292
304
  SyncReloader(entry).keep_watching_until_interrupt()
293
305
 
294
306
 
295
- __version__ = "0.3.1"
307
+ __version__ = "0.3.2"
File without changes