hmr 0.1.1.1__py3-none-any.whl → 0.1.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.1.1.1
3
+ Version: 0.1.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.1.2.dist-info/METADATA,sha256=tHSOaU8XTf-WF85Hg7r6Fimk-g6WZZa3jJeurid7yno,228
2
+ hmr-0.1.2.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ hmr-0.1.2.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
4
+ reactivity/__init__.py,sha256=pX-RUzkezCC1x4eOWGxNhXbwrbvBLP_3pQuZr9eZz1Y,300
5
+ reactivity/functional.py,sha256=U06vshcVhZ0sb218gcmHtEhfgTNAGtQ7zyvPz2w5qKM,1292
6
+ reactivity/helpers.py,sha256=1KmMCO6lqluHlMsjGQQ9UJZBtbFppjFZnmi9RhowRHo,3872
7
+ reactivity/hmr.py,sha256=lUqHeB_5LlrHMUSWXRvSRGoaMkFAm3ONQNxm5OCk0Uw,9570
8
+ reactivity/primitives.py,sha256=lw4G3GpANRGK5dKw11eYc2-nlOJ1uCO3f3MiLa41jG8,3588
9
+ hmr-0.1.2.dist-info/RECORD,,
reactivity/hmr.py CHANGED
@@ -8,7 +8,7 @@ from importlib.util import spec_from_loader
8
8
  from inspect import currentframe
9
9
  from pathlib import Path
10
10
  from runpy import run_path
11
- from types import ModuleType
11
+ from types import ModuleType, TracebackType
12
12
  from typing import Any
13
13
 
14
14
  from . import Reactive, batch, memoized_method
@@ -60,8 +60,12 @@ class ReactiveModule(ModuleType):
60
60
 
61
61
  @memoized_method
62
62
  def __load(self):
63
- code = compile(self.__file.read_text("utf-8"), str(self.__file), "exec", dont_inherit=True)
64
- exec(code, self.__namespace, self.__namespace_proxy)
63
+ try:
64
+ code = compile(self.__file.read_text("utf-8"), str(self.__file), "exec", dont_inherit=True)
65
+ except SyntaxError as e:
66
+ sys.excepthook(type(e), e, e.__traceback__)
67
+ else:
68
+ exec(code, self.__namespace, self.__namespace_proxy)
65
69
 
66
70
  @property
67
71
  def load(self):
@@ -153,6 +157,30 @@ def get_path_module_map():
153
157
  return {module.file.resolve(): module for module in sys.modules.values() if isinstance(module, ReactiveModule)}
154
158
 
155
159
 
160
+ class ErrorFilter:
161
+ def __init__(self, *exclude_filenames: str):
162
+ self.exclude_filenames = set(exclude_filenames)
163
+
164
+ def __call__(self, tb: TracebackType):
165
+ current = tb
166
+ while current is not None:
167
+ if current.tb_frame.f_code.co_filename not in self.exclude_filenames:
168
+ return current
169
+ current = current.tb_next
170
+ return tb
171
+
172
+ def __enter__(self):
173
+ return self
174
+
175
+ def __exit__(self, exc_type: type[BaseException], exc_value: BaseException, traceback: TracebackType):
176
+ if exc_value is None:
177
+ return
178
+ tb = self(traceback)
179
+ exc_value = exc_value.with_traceback(tb)
180
+ sys.excepthook(exc_type, exc_value, tb)
181
+ return True
182
+
183
+
156
184
  class BaseReloader:
157
185
  def __init__(self, entry_file: str, includes: Iterable[str] = (".",), excludes: Iterable[str] = ()):
158
186
  self.entry = entry_file
@@ -160,13 +188,12 @@ class BaseReloader:
160
188
  self.excludes = excludes
161
189
  patch_meta_path(includes, excludes)
162
190
  self.last_globals = {}
191
+ self.error_filter = ErrorFilter(__file__, "<frozen runpy>")
163
192
 
164
193
  @memoized_method
165
194
  def run_entry_file(self):
166
- try:
195
+ with self.error_filter:
167
196
  self.last_globals = run_path(self.entry, self.last_globals, "__main__")
168
- except Exception as e:
169
- sys.excepthook(e.__class__, e, e.__traceback__)
170
197
 
171
198
  @property
172
199
  def watch_filter(self):
@@ -189,16 +216,12 @@ class BaseReloader:
189
216
  if path.samefile(self.entry):
190
217
  self.run_entry_file.invalidate()
191
218
  elif module := path2module.get(path):
192
- try:
219
+ with self.error_filter:
193
220
  module.load.invalidate()
194
- except Exception as e:
195
- sys.excepthook(e.__class__, e, e.__traceback__)
196
221
 
197
222
  for module in path2module.values():
198
- try:
223
+ with self.error_filter:
199
224
  module.load()
200
- except Exception as e:
201
- sys.excepthook(e.__class__, e, e.__traceback__)
202
225
  self.run_entry_file()
203
226
 
204
227
 
@@ -260,4 +283,4 @@ def cli():
260
283
  SyncReloader(entry, excludes={".venv"}).keep_watching_until_interrupt()
261
284
 
262
285
 
263
- __version__ = "0.1.1.1"
286
+ __version__ = "0.1.2"
@@ -1,9 +0,0 @@
1
- hmr-0.1.1.1.dist-info/METADATA,sha256=_p-qXPd7QH4OLgW2k6B-d9EBzTKdrQjAinQPg7cqJEY,230
2
- hmr-0.1.1.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- hmr-0.1.1.1.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
4
- reactivity/__init__.py,sha256=pX-RUzkezCC1x4eOWGxNhXbwrbvBLP_3pQuZr9eZz1Y,300
5
- reactivity/functional.py,sha256=U06vshcVhZ0sb218gcmHtEhfgTNAGtQ7zyvPz2w5qKM,1292
6
- reactivity/helpers.py,sha256=1KmMCO6lqluHlMsjGQQ9UJZBtbFppjFZnmi9RhowRHo,3872
7
- reactivity/hmr.py,sha256=7KmYr3ZmIrvHCmfVO6MLDjiw4Y_AiNQWPNexcOkfAhs,8885
8
- reactivity/primitives.py,sha256=lw4G3GpANRGK5dKw11eYc2-nlOJ1uCO3f3MiLa41jG8,3588
9
- hmr-0.1.1.1.dist-info/RECORD,,
File without changes