hmr 0.3.1__tar.gz → 0.3.2.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.
- {hmr-0.3.1 → hmr-0.3.2.1}/PKG-INFO +1 -1
- {hmr-0.3.1 → hmr-0.3.2.1}/pyproject.toml +1 -1
- hmr-0.3.2.1/reactivity/hmr/api.py +60 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/hmr/core.py +17 -6
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/__init__.py +0 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/functional.py +0 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/helpers.py +0 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/hmr/__init__.py +0 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/hmr/hooks.py +0 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/hmr/utils.py +0 -0
- {hmr-0.3.1 → hmr-0.3.2.1}/reactivity/primitives.py +0 -0
@@ -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()
|
@@ -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
|
-
|
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,8 @@ 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
|
+
del self._stop_event
|
262
|
+
|
253
263
|
def keep_watching_until_interrupt(self):
|
254
264
|
with suppress(KeyboardInterrupt):
|
255
265
|
self.run_entry_file()
|
@@ -266,7 +276,6 @@ class AsyncReloader(BaseReloader):
|
|
266
276
|
|
267
277
|
def stop_watching(self):
|
268
278
|
self._stop_event.set()
|
269
|
-
del self._stop_event
|
270
279
|
|
271
280
|
async def start_watching(self):
|
272
281
|
from watchfiles import awatch
|
@@ -274,6 +283,8 @@ class AsyncReloader(BaseReloader):
|
|
274
283
|
async for events in awatch(self.entry, *self.includes, watch_filter=self.watch_filter, stop_event=self._stop_event):
|
275
284
|
self.on_events(events)
|
276
285
|
|
286
|
+
del self._stop_event
|
287
|
+
|
277
288
|
async def keep_watching_until_interrupt(self):
|
278
289
|
with suppress(KeyboardInterrupt):
|
279
290
|
self.run_entry_file()
|
@@ -292,4 +303,4 @@ def cli():
|
|
292
303
|
SyncReloader(entry).keep_watching_until_interrupt()
|
293
304
|
|
294
305
|
|
295
|
-
__version__ = "0.3.1"
|
306
|
+
__version__ = "0.3.2.1"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|