You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm working on a project that merges the reusability of fasthtml components with the delightful development experience of .qmd files, and I would like to trigger quarto render <file path> whenever a change is registered for these files.
I'm currently doing this by monkey patching the uvicorn.supervisors.basereload.BaseReload class, but to ensure the image paths generated by quarto are correct, and the converted html is stored in the proper location, I need access to the root path for the project.
Describe the solution you'd like
uvicorn.run has a root_path parameter that is added to the server config, which makes it accessible to instances of BaseReload, so all I need is to be able to pass the project's root to serve.
I'm currently doing this by copying the the serve function from fasthtml's source code and adding the parameter, which totally works...but passing the root_path to uvicorn's objects makes it much easier to extend and customize a webserver project! Alternatively, **kwargs could work since uvicorn.run has a bunch of parameters.
Example code
At the moment I've copied the serve function into my project and added the parameter.
defserve(
appname=None,
app='app',
host='0.0.0.0',
port=None,
reload=True,
reload_includes:list[str]|str|None=None,
reload_excludes:list[str]|str|None=None,
root_path:str="", # <-------- Added parameter here
):
"Run the app in an async server, with live reload set as the default."bk=inspect.currentframe().f_backglb=bk.f_globalscode=bk.f_codeifnotappname:
ifglb.get('__name__')=='__main__': appname=Path(glb.get('__file__', '')).stemelifcode.co_name=='main'andbk.f_back.f_globals.get('__name__')=='__main__': appname=inspect.getmodule(bk).__name__ifappname:
ifnotport: port=int(os.getenv("PORT", default=5001))
uvicorn.run(
f'{appname}:{app}',
host=host,
port=port,
reload=reload,
reload_includes=reload_includes,
reload_excludes=reload_excludes,
root_path=root_path, # <------- Added argument here
)
Problem solved
This change improves customization of the webserver, especially for development!
Additional Context
This is admittedly a small feature request, especially since the serve function is only a handful of lines, but I trust ya'll to be much smarter than me with spinning up servers, so I'd like to use the current (and any future) setup code implemented prior to calling .run, without needing to copy directly from the source code.
Given how simple this appears to be I'm more than happy to open a PR for this, but idk if there's a reason for why the parameters have been limited for the serve function or if ya'll have a design stance on the use of kwargs, though a quick project search shows 31 files with a kwargs reference so maybe nvm on that 😆
Confirmation
Please confirm the following:
I have checked the existing issues and pull requests to ensure this feature hasn't been requested before.
I have read the project's documentation to ensure this feature doesn't already exist.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I'm working on a project that merges the reusability of fasthtml components with the delightful development experience of .qmd files, and I would like to trigger
quarto render <file path>
whenever a change is registered for these files.I'm currently doing this by monkey patching the
uvicorn.supervisors.basereload.BaseReload
class, but to ensure the image paths generated by quarto are correct, and the converted html is stored in the proper location, I need access to the root path for the project.Describe the solution you'd like
uvicorn.run
has aroot_path
parameter that is added to the server config, which makes it accessible to instances of BaseReload, so all I need is to be able to pass the project's root toserve
.I'm currently doing this by copying the the serve function from fasthtml's source code and adding the parameter, which totally works...but passing the
root_path
to uvicorn's objects makes it much easier to extend and customize a webserver project! Alternatively,**kwargs
could work sinceuvicorn.run
has a bunch of parameters.Example code
At the moment I've copied the
serve
function into my project and added the parameter.Problem solved
This change improves customization of the webserver, especially for development!
Additional Context
This is admittedly a small feature request, especially since the serve function is only a handful of lines, but I trust ya'll to be much smarter than me with spinning up servers, so I'd like to use the current (and any future) setup code implemented prior to calling
.run
, without needing to copy directly from the source code.Given how simple this appears to be I'm more than happy to open a PR for this, but idk if there's a reason for why the parameters have been limited for the serve function or if ya'll have a design stance on the use of kwargs, though a quick project search shows 31 files with a kwargs reference so maybe nvm on that 😆
Confirmation
Please confirm the following:
The text was updated successfully, but these errors were encountered: