hmr 0.4.0.1__tar.gz → 0.4.0.3__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.4.0.1
3
+ Version: 0.4.0.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
@@ -6,7 +6,7 @@ description = "Hot Module Reload for Python"
6
6
  dependencies = [
7
7
  "watchfiles>=0.21,<2 ; sys_platform != 'emscripten'",
8
8
  ]
9
- version = "0.4.0.1"
9
+ version = "0.4.0.3"
10
10
 
11
11
  [project.scripts]
12
12
  hmr = "reactivity.hmr:cli"
@@ -1,16 +1,23 @@
1
1
  from .core import AsyncReloader, BaseReloader, SyncReloader
2
+ from .hooks import call_post_reload_hooks, call_pre_reload_hooks
2
3
 
3
4
 
4
- def _clean_up(r: BaseReloader):
5
- r.entry_module.load.dispose()
6
- r.entry_module.load.invalidate()
5
+ class LifecycleMixin(BaseReloader):
6
+ def run_with_hooks(self):
7
+ call_pre_reload_hooks()
8
+ self.run_entry_file()
9
+ call_post_reload_hooks()
10
+
11
+ def clean_up(self):
12
+ self.entry_module.load.dispose()
13
+ self.entry_module.load.invalidate()
7
14
 
8
15
 
9
- class SyncReloaderAPI(SyncReloader):
16
+ class SyncReloaderAPI(SyncReloader, LifecycleMixin):
10
17
  def __enter__(self):
11
18
  from threading import Thread
12
19
 
13
- self.run_entry_file()
20
+ self.run_with_hooks()
14
21
  self.thread = Thread(target=self.start_watching)
15
22
  self.thread.start()
16
23
  return super()
@@ -18,27 +25,27 @@ class SyncReloaderAPI(SyncReloader):
18
25
  def __exit__(self, *_):
19
26
  self.stop_watching()
20
27
  self.thread.join()
21
- _clean_up(self)
28
+ self.clean_up()
22
29
 
23
30
  async def __aenter__(self):
24
31
  from asyncio import ensure_future, to_thread
25
32
 
26
- await to_thread(self.run_entry_file)
33
+ await to_thread(self.run_with_hooks)
27
34
  self.future = ensure_future(to_thread(self.start_watching))
28
35
  return super()
29
36
 
30
37
  async def __aexit__(self, *_):
31
38
  self.stop_watching()
32
39
  await self.future
33
- _clean_up(self)
40
+ self.clean_up()
34
41
 
35
42
 
36
- class AsyncReloaderAPI(AsyncReloader):
43
+ class AsyncReloaderAPI(AsyncReloader, LifecycleMixin):
37
44
  def __enter__(self):
38
45
  from asyncio import run
39
46
  from threading import Thread
40
47
 
41
- self.run_entry_file()
48
+ self.run_with_hooks()
42
49
  self.thread = Thread(target=lambda: run(self.start_watching()))
43
50
  self.thread.start()
44
51
  return super()
@@ -46,16 +53,16 @@ class AsyncReloaderAPI(AsyncReloader):
46
53
  def __exit__(self, *_):
47
54
  self.stop_watching()
48
55
  self.thread.join()
49
- _clean_up(self)
56
+ self.clean_up()
50
57
 
51
58
  async def __aenter__(self):
52
59
  from asyncio import ensure_future, to_thread
53
60
 
54
- await to_thread(self.run_entry_file)
61
+ await to_thread(self.run_with_hooks)
55
62
  self.future = ensure_future(self.start_watching())
56
63
  return super()
57
64
 
58
65
  async def __aexit__(self, *_):
59
66
  self.stop_watching()
60
67
  await self.future
61
- _clean_up(self)
68
+ self.clean_up()
@@ -339,4 +339,4 @@ def cli():
339
339
  SyncReloader(entry).keep_watching_until_interrupt()
340
340
 
341
341
 
342
- __version__ = "0.4.0.1"
342
+ __version__ = "0.4.0.3"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes