hmr 0.5.1__py3-none-any.whl → 0.5.2.1__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.
- hmr-0.5.2.1.dist-info/METADATA +36 -0
- {hmr-0.5.1.dist-info → hmr-0.5.2.1.dist-info}/RECORD +6 -6
- reactivity/hmr/api.py +5 -0
- reactivity/hmr/core.py +6 -3
- hmr-0.5.1.dist-info/METADATA +0 -8
- {hmr-0.5.1.dist-info → hmr-0.5.2.1.dist-info}/WHEEL +0 -0
- {hmr-0.5.1.dist-info → hmr-0.5.2.1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: hmr
|
3
|
+
Version: 0.5.2.1
|
4
|
+
Summary: Hot Module Reload for Python
|
5
|
+
Project-URL: repository, https://github.com/promplate/pyth-on-line/tree/reactivity
|
6
|
+
Requires-Python: >=3.12
|
7
|
+
Requires-Dist: watchfiles<2,>=0.21; sys_platform != "emscripten"
|
8
|
+
Description-Content-Type: text/markdown
|
9
|
+
|
10
|
+
<div align="center">
|
11
|
+
|
12
|
+
# HMR for Python
|
13
|
+
|
14
|
+
<sup> on-demand · fine-grained · pull-push reactivity </sup>
|
15
|
+
|
16
|
+
[](https://pypi.org/project/hmr/)
|
17
|
+
[](https://github.com/promplate/pyth-on-line/blob/reactivity/packages/hmr/pyproject.toml)
|
18
|
+
[](https://pepy.tech/projects/hmr)
|
19
|
+
|
20
|
+
</div>
|
21
|
+
|
22
|
+
HMR means Hot Module Reload / [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/). It is a feature that allows part of your app to be updated at runtime without a full rerun.
|
23
|
+
|
24
|
+
- The module whose source file **you changed** will rerun
|
25
|
+
- The module / function that **depend on** the changed module will rerun
|
26
|
+
- Other modules that are unaffected (like third-party libraries) will not rerun
|
27
|
+
|
28
|
+
Thus, in contrast to the traditional way of **cold-reloading** Python applications (like [watchfiles CLI](https://watchfiles.helpmanual.io/cli/)), HMR is just more efficient.
|
29
|
+
|
30
|
+
Unlike static-analysis tools like [Tach](https://github.com/gauge-sh/tach), HMR works by tracking the dependencies between names and modules **during runtime** through a [reactive system](https://wikipedia.org/wiki/Reactive_programming).
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
If you are running your entry file with `python foo.py bar baz ...`, you can just replace it with `hmr foo.py bar baz ...`.
|
35
|
+
|
36
|
+
You can also try it with `uvx` or `pipx`. If you are using a virtual environment, it is recommended to install `hmr` in the virtual environment instead of globally.
|
@@ -1,14 +1,14 @@
|
|
1
|
-
hmr-0.5.1.dist-info/METADATA,sha256=
|
2
|
-
hmr-0.5.1.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
-
hmr-0.5.1.dist-info/entry_points.txt,sha256=g_T0uJ43WgsdG14kkkdaBQuIL0HO-m1qvtjXMP6d060,59
|
1
|
+
hmr-0.5.2.1.dist-info/METADATA,sha256=A-0hVQkuyKNRaNS-opfmUwmULQY6_SZHYxIHn2RMVQE,2001
|
2
|
+
hmr-0.5.2.1.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
+
hmr-0.5.2.1.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=jJLEq88w5ag2cXuD1T118uEjnEg37_mqvWmFkb47KVY,1300
|
6
6
|
reactivity/helpers.py,sha256=rcrCXy1mmlei-if_BN4nSgS2IG9kBj-jq1YRwEfcITo,5329
|
7
7
|
reactivity/hmr/__init__.py,sha256=S5ZIHqCRpevdzWuhS0aCua_S8F0LkK0YNg6IgeTScFQ,177
|
8
8
|
reactivity/hmr/__main__.py,sha256=uIcyjR5gMFIXH_3hS0B3SD00RirVf7GIct-uItx675o,64
|
9
|
-
reactivity/hmr/api.py,sha256=
|
10
|
-
reactivity/hmr/core.py,sha256=
|
9
|
+
reactivity/hmr/api.py,sha256=sKDQV7uKRVoDifTZKrLQGZP-fzgYbdVjfEOC6ki4NKY,2280
|
10
|
+
reactivity/hmr/core.py,sha256=LpIZubK8XZLAxVM3ZWcxPT14WjcbZVHiU57AMN_KF8Y,11688
|
11
11
|
reactivity/hmr/hooks.py,sha256=jIFpe4CNxfaS9RcR4OIodx_sOZlnJ_IA1T1RtHPXhwU,945
|
12
12
|
reactivity/hmr/utils.py,sha256=h9m7iRXlvsLTrHoXV9gEVbhz3XsPK4KgnStYoCAWE5I,1616
|
13
13
|
reactivity/primitives.py,sha256=QkiUF8bqLZtyXguWwNJi34HJIc-SzUKqi1M9UgTNuvI,5952
|
14
|
-
hmr-0.5.1.dist-info/RECORD,,
|
14
|
+
hmr-0.5.2.1.dist-info/RECORD,,
|
reactivity/hmr/api.py
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
import sys
|
2
|
+
|
1
3
|
from .core import AsyncReloader, BaseReloader, SyncReloader, create_effect
|
2
4
|
from .hooks import call_post_reload_hooks, call_pre_reload_hooks
|
3
5
|
|
4
6
|
|
5
7
|
class LifecycleMixin(BaseReloader):
|
6
8
|
def run_with_hooks(self):
|
9
|
+
self._original_main_module = sys.modules["__main__"]
|
10
|
+
sys.modules["__main__"] = self.entry_module
|
7
11
|
call_pre_reload_hooks()
|
8
12
|
self.effect = create_effect(self.run_entry_file)
|
9
13
|
call_post_reload_hooks()
|
@@ -12,6 +16,7 @@ class LifecycleMixin(BaseReloader):
|
|
12
16
|
self.effect.dispose()
|
13
17
|
self.entry_module.load.dispose()
|
14
18
|
self.entry_module.load.invalidate()
|
19
|
+
sys.modules["__main__"] = self._original_main_module
|
15
20
|
|
16
21
|
|
17
22
|
class SyncReloaderAPI(SyncReloader, LifecycleMixin):
|
reactivity/hmr/core.py
CHANGED
@@ -331,11 +331,14 @@ def cli():
|
|
331
331
|
if len(sys.argv) < 2:
|
332
332
|
print("\n Usage: hmr <entry file>, just like python <entry file>\n")
|
333
333
|
exit(1)
|
334
|
-
|
334
|
+
sys.argv.pop(0) # this file itself
|
335
|
+
entry = sys.argv[0]
|
335
336
|
if not (path := Path(entry)).is_file():
|
336
337
|
raise FileNotFoundError(path.resolve())
|
337
338
|
sys.path.insert(0, ".")
|
338
|
-
SyncReloader(entry)
|
339
|
+
reloader = SyncReloader(entry)
|
340
|
+
sys.modules["__main__"] = reloader.entry_module
|
341
|
+
reloader.keep_watching_until_interrupt()
|
339
342
|
|
340
343
|
|
341
|
-
__version__ = "0.5.1"
|
344
|
+
__version__ = "0.5.2.1"
|
hmr-0.5.1.dist-info/METADATA
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: hmr
|
3
|
-
Version: 0.5.1
|
4
|
-
Summary: Hot Module Reload for Python
|
5
|
-
Project-URL: repository, https://github.com/promplate/pyth-on-line/tree/reactivity
|
6
|
-
Requires-Python: >=3.12
|
7
|
-
Requires-Dist: watchfiles<2,>=0.21; sys_platform != "emscripten"
|
8
|
-
|
File without changes
|
File without changes
|