hmr 0.3.2.2__tar.gz → 0.3.3.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.3.2.2
3
+ Version: 0.3.3.1
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.3.2.2"
9
+ version = "0.3.3.1"
10
10
 
11
11
  [project.scripts]
12
12
  hmr = "reactivity.hmr:cli"
@@ -1,4 +1,11 @@
1
- from .core import AsyncReloader, SyncReloader
1
+ from .core import AsyncReloader, BaseReloader, SyncReloader
2
+
3
+
4
+ def _clean_up(r: BaseReloader):
5
+ r.run_entry_file.dispose()
6
+ r.run_entry_file.invalidate()
7
+ r.entry_module.load.dispose()
8
+ r.entry_module.load.invalidate()
2
9
 
3
10
 
4
11
  class SyncReloaderAPI(SyncReloader):
@@ -13,21 +20,19 @@ class SyncReloaderAPI(SyncReloader):
13
20
  def __exit__(self, *_):
14
21
  self.stop_watching()
15
22
  self.thread.join()
16
- self.run_entry_file.dispose()
17
- self.run_entry_file.invalidate()
23
+ _clean_up(self)
18
24
 
19
25
  async def __aenter__(self):
20
26
  from asyncio import ensure_future, to_thread
21
27
 
22
- self.run_entry_file()
28
+ await to_thread(self.run_entry_file)
23
29
  self.future = ensure_future(to_thread(self.start_watching))
24
30
  return super()
25
31
 
26
32
  async def __aexit__(self, *_):
27
33
  self.stop_watching()
28
34
  await self.future
29
- self.run_entry_file.dispose()
30
- self.run_entry_file.invalidate()
35
+ _clean_up(self)
31
36
 
32
37
 
33
38
  class AsyncReloaderAPI(AsyncReloader):
@@ -43,8 +48,7 @@ class AsyncReloaderAPI(AsyncReloader):
43
48
  def __exit__(self, *_):
44
49
  self.stop_watching()
45
50
  self.thread.join()
46
- self.run_entry_file.dispose()
47
- self.run_entry_file.invalidate()
51
+ _clean_up(self)
48
52
 
49
53
  async def __aenter__(self):
50
54
  from asyncio import ensure_future, to_thread
@@ -56,5 +60,4 @@ class AsyncReloaderAPI(AsyncReloader):
56
60
  async def __aexit__(self, *_):
57
61
  self.stop_watching()
58
62
  await self.future
59
- self.run_entry_file.dispose()
60
- self.run_entry_file.invalidate()
63
+ _clean_up(self)
@@ -190,16 +190,17 @@ class BaseReloader:
190
190
  patch_meta_path(includes, excludes)
191
191
  self.error_filter = ErrorFilter(*(str(i) for i in Path(__file__, "../..").resolve().glob("**/*.py")))
192
192
 
193
+ @cached_property
194
+ def entry_module(self):
195
+ namespace = {"__file__": self.entry, "__name__": "__main__"}
196
+ return ReactiveModule(Path(self.entry), namespace, "__main__")
197
+
193
198
  @memoized_method
194
199
  def run_entry_file(self):
195
200
  call_pre_reload_hooks()
196
201
 
197
- with self.error_filter:
198
- if not isinstance(module := sys.modules["__main__"], ReactiveModule):
199
- namespace = {"__file__": self.entry, "__name__": "__main__"}
200
- module = sys.modules["__main__"] = ReactiveModule(Path(self.entry), namespace, "__main__")
201
- module.load.invalidate()
202
- module.load()
202
+ self.entry_module.load.invalidate()
203
+ self.entry_module.load()
203
204
 
204
205
  call_post_reload_hooks()
205
206
 
@@ -224,15 +225,14 @@ class BaseReloader:
224
225
  if path.samefile(self.entry):
225
226
  self.run_entry_file.invalidate()
226
227
  elif module := path2module.get(path):
227
- with self.error_filter:
228
- module.load.invalidate()
228
+ module.load.invalidate()
229
229
 
230
- for module in path2module.values():
231
- if module.file.samefile(self.entry):
232
- continue
233
- with self.error_filter:
230
+ with self.error_filter:
231
+ for module in path2module.values():
232
+ if module.file.samefile(self.entry):
233
+ continue
234
234
  module.load()
235
- self.run_entry_file()
235
+ self.run_entry_file()
236
236
 
237
237
 
238
238
  class _SimpleEvent:
@@ -264,7 +264,8 @@ class SyncReloader(BaseReloader):
264
264
 
265
265
  def keep_watching_until_interrupt(self):
266
266
  with suppress(KeyboardInterrupt):
267
- self.run_entry_file()
267
+ with self.error_filter:
268
+ self.run_entry_file()
268
269
  self.start_watching()
269
270
  self.run_entry_file.dispose()
270
271
 
@@ -289,7 +290,8 @@ class AsyncReloader(BaseReloader):
289
290
 
290
291
  async def keep_watching_until_interrupt(self):
291
292
  with suppress(KeyboardInterrupt):
292
- self.run_entry_file()
293
+ with self.error_filter:
294
+ self.run_entry_file()
293
295
  await self.start_watching()
294
296
  self.run_entry_file.dispose()
295
297
 
@@ -305,4 +307,4 @@ def cli():
305
307
  SyncReloader(entry).keep_watching_until_interrupt()
306
308
 
307
309
 
308
- __version__ = "0.3.2.2"
310
+ __version__ = "0.3.3.1"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes