fastapi-reloader 1.2__py2.py3-none-any.whl → 1.3__py2.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.
fastapi_reloader/core.py CHANGED
@@ -33,6 +33,11 @@ async def heartbeat():
33
33
  return Response(status_code=200)
34
34
 
35
35
 
36
+ @reload_router.get("/poller.js")
37
+ async def get_poller_js():
38
+ return Response(get_js(), media_type="application/javascript")
39
+
40
+
36
41
  @reload_router.get("/{key:int}")
37
42
  async def simple_refresh_trigger(key: int):
38
43
  async def event_generator():
@@ -1,4 +1,5 @@
1
1
  from collections.abc import Awaitable, Callable
2
+ from contextlib import asynccontextmanager
2
3
  from math import inf
3
4
  from typing import TypeGuard
4
5
 
@@ -9,7 +10,7 @@ from starlette.middleware import Middleware
9
10
  from starlette.middleware.base import BaseHTTPMiddleware
10
11
  from starlette.types import ASGIApp
11
12
 
12
- from .core import get_js, reload_router
13
+ from .core import reload_router
13
14
 
14
15
 
15
16
  def is_streaming_response(response: Response) -> TypeGuard[StreamingResponse]:
@@ -18,7 +19,12 @@ def is_streaming_response(response: Response) -> TypeGuard[StreamingResponse]:
18
19
 
19
20
 
20
21
  def patch_for_auto_reloading(app: ASGIApp):
21
- new_app = FastAPI(openapi_url=None, lifespan=lambda _: LifespanManager(app, inf, inf)) # type: ignore
22
+ @asynccontextmanager
23
+ async def lifespan(_):
24
+ async with LifespanManager(app, inf, inf):
25
+ yield
26
+
27
+ new_app = FastAPI(openapi_url=None, lifespan=lifespan)
22
28
  new_app.include_router(reload_router)
23
29
  new_app.mount("/", app)
24
30
 
@@ -34,7 +40,8 @@ def patch_for_auto_reloading(app: ASGIApp):
34
40
  yield chunk
35
41
  else:
36
42
  yield res.body
37
- yield f"\n\n <script> {get_js()} </script>".encode()
43
+
44
+ yield b'\n\n <script src="/---fastapi-reloader---/poller.js"></script>'
38
45
 
39
46
  headers = {k: v for k, v in res.headers.items() if k.lower() not in {"content-length", "content-encoding", "transfer-encoding"}}
40
47
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastapi-reloader
3
- Version: 1.2
3
+ Version: 1.3
4
4
  Project-URL: Homepage, https://github.com/promplate/hmr
5
5
  Requires-Dist: asgi-lifespan~=2.0
6
6
  Requires-Dist: fastapi~=0.115
@@ -0,0 +1,8 @@
1
+ fastapi_reloader-1.3.dist-info/METADATA,sha256=QrT6bBHmbNP3BbLMDtW7M2nskhCK_AsXgZcELTC5oCk,2268
2
+ fastapi_reloader-1.3.dist-info/WHEEL,sha256=pz1FfwQ2kf9tI4G8U2ObRTKdvsTSmrreuBTtdnO8pJw,94
3
+ fastapi_reloader-1.3.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ fastapi_reloader/__init__.py,sha256=VE5m-0M92Weme8COqLs0LwIx5g6FHhqyOLGAgY6Zkzs,145
5
+ fastapi_reloader/core.py,sha256=eAyPhBZaFiKepy5NcU966adAJwqFTpHlK_uXn1cJQU8,1676
6
+ fastapi_reloader/patcher.py,sha256=NOLTYVkbaZxRN6BSRRbsC0gUtdxn7OdARLZppcZ12jY,1921
7
+ fastapi_reloader/runtime.js,sha256=H9SCpyGpBUmfvcdlzpU4RXnIBCYSQwIqXZ7jd1bdtSo,743
8
+ fastapi_reloader-1.3.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- fastapi_reloader-1.2.dist-info/METADATA,sha256=Fs66FveG8uf_-fymXnGFn3EXM1WlepvGcmE73k-qFBM,2268
2
- fastapi_reloader-1.2.dist-info/WHEEL,sha256=pz1FfwQ2kf9tI4G8U2ObRTKdvsTSmrreuBTtdnO8pJw,94
3
- fastapi_reloader-1.2.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- fastapi_reloader/__init__.py,sha256=VE5m-0M92Weme8COqLs0LwIx5g6FHhqyOLGAgY6Zkzs,145
5
- fastapi_reloader/core.py,sha256=lrfBJoavB2sDzkvN5UyWV91Xm69iLCuigg7pzKKVGfc,1547
6
- fastapi_reloader/patcher.py,sha256=j2Q66egTXHVG2azmNH6tLE2NOGRQOlu052QA9O26KvY,1792
7
- fastapi_reloader/runtime.js,sha256=H9SCpyGpBUmfvcdlzpU4RXnIBCYSQwIqXZ7jd1bdtSo,743
8
- fastapi_reloader-1.2.dist-info/RECORD,,