-
-
Notifications
You must be signed in to change notification settings - Fork 323
Add auto-reloading behavior to reactpy.run
#990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd say it's easier to run every backend using Uvicorn, and rely on Uvicorn's auto reloader. |
Not all supported backends are async (e.g. flask/tornado). All the async ones can use the Uvicorn reloader though. |
|
I have a vague memory of having tried |
Unfortunately it only works through command line. Or more accurately, |
There are two problems we'd need to solve:
If you can solve that, you can write the app string ( I wonder if if would be possible to solve both those problems with some frame trickery: from inspect import currentframe
def run():
frame = currentframe().f_back
app = frame.f_globals["the_app"] = create_development_app() # patch in the application to __main__
entrypoint = frame.f_globals["__file__"] # get the path to the entrypoint file
if frame.f_globals["__name__"] == "__main__":
serve_development_app(app, entrypoint) This is very hand-wavy, but hopefully it gets the idea across. |
Yep, I have a simpler solution that might involve changing our I don't want to overload #1051 with that. Will do in a follow up PR. |
I have no idea how to do that ! Could you share a code ?
Fixed: All is here https://reactpy.dev/docs/guides/getting-started/running-reactpy.html?highlight=uvicorn |
Closed in favor of #1113 |
Current Situation
Currently, if you want to get auto-reloading you need to configure an application and run it using a production-grade web server like Uvicorn and follow their directions on how to set up auto-reloading. It would be great if the
reactpy.run
function did that by default.Proposed Actions
First, decide if we should pass a new
DebugOptions
object to therun
function or simply use**kwargs
. The former aligns with theconfigure
interface, but the latter may help delineate between the two.Add
reload=True
settings for therun
function as well asBackendImplementation.create_development_app
. It's possible that areload_dirs
parameter could make sense here as well, but if the interfaces for specifying what directories to watch varies significantly between the backends we might choose not to do that. It may also be worth adding aThen, it's just a question of making this happen for each backend development server. Since the all the async frameworks run on Uvicorn, that should be fairly straightforward, for Flask/Tornado that will require some investigation.
The text was updated successfully, but these errors were encountered: