Skip to content

Commit

Permalink
Merge pull request #621 from ryansb/suggestion/uvicorn-inline
Browse files Browse the repository at this point in the history
Suggestion: don't import uvicorn to allow for alternative asgi servers
  • Loading branch information
jph00 authored Jan 12, 2025
2 parents c21a93f + a19f275 commit efd1916
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'reg_re_param', 'MiddlewareBase', 'FtResponse', 'unqid', 'setup_ws']

# %% ../nbs/api/00_core.ipynb
import json,uuid,inspect,types,uvicorn,signal,asyncio,threading,inspect
import json,uuid,inspect,types,signal,asyncio,threading,inspect

from fastcore.utils import *
from fastcore.xml import *
Expand Down Expand Up @@ -644,6 +644,7 @@ def serve(
if not appname:
if glb.get('__name__')=='__main__': appname = Path(glb.get('__file__', '')).stem
elif code.co_name=='main' and bk.f_back.f_globals.get('__name__')=='__main__': appname = inspect.getmodule(bk).__name__
import uvicorn
if appname:
if not port: port=int(os.getenv("PORT", default=5001))
print(f'Link: http://{"localhost" if host=="0.0.0.0" else host}:{port}')
Expand Down
3 changes: 2 additions & 1 deletion nbs/api/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"outputs": [],
"source": [
"#| export\n",
"import json,uuid,inspect,types,uvicorn,signal,asyncio,threading,inspect\n",
"import json,uuid,inspect,types,signal,asyncio,threading,inspect\n",
"\n",
"from fastcore.utils import *\n",
"from fastcore.xml import *\n",
Expand Down Expand Up @@ -1630,6 +1630,7 @@
" if not appname:\n",
" if glb.get('__name__')=='__main__': appname = Path(glb.get('__file__', '')).stem\n",
" elif code.co_name=='main' and bk.f_back.f_globals.get('__name__')=='__main__': appname = inspect.getmodule(bk).__name__\n",
" import uvicorn\n",
" if appname:\n",
" if not port: port=int(os.getenv(\"PORT\", default=5001))\n",
" print(f'Link: http://{\"localhost\" if host==\"0.0.0.0\" else host}:{port}')\n",
Expand Down

0 comments on commit efd1916

Please sign in to comment.