quart
quart copied to clipboard
Hot reload does not work within poetry scripts
When creating a Quart app using Poetry as a dependency manager and using Poetry to run a server with scripts, how reload fails to restart the app.
- Create Quart app using Poetry
- Add a script to
pyproject.toml[tool.poetry.scripts]section that points to your app or app factory, likedev = helloworld:app. Make sure that app uses reloader, with snippet like this:
in app/serve.py
def dev() -> None:
app = create_app() # your implementation of app factory
app.run(debug=True, use_reloader=True)
and in pyproject.toml
[tool.poetry.scripts]
dev = "app.serve:dev"
- Create a package with
poetry install - Run it with
poetry run dev - Save a file in your project to trigger hot reload
Expected result: Project reloads, allowing you to see your changes immidiately
Observed result: Project fails to reload with the next stacktrace
* Serving Quart app 'qrt'
* Debug mode: True
* Please use an ASGI server (e.g. Hypercorn) directly in production
* Running on http://127.0.0.1:5000 (CTRL + C to quit)
[2024-03-27 00:52:21 +0100] [14224] [INFO] Running on http://127.0.0.1:5000 (CTRL + C to quit)
File "C:\Projects\Python\qrt\.venv\Scripts\dev.cmd", line 1
@echo off
^^^
SyntaxError: invalid syntax
dev.cmd is a file created in your virtual environment by Poetry on poetry install (name of file same as the name of script in pyproject.toml) it tells poetry how to run the command and runs on hot reload, but it seems that file is treated as a Python script, while it should be treated as a Windows command-line script.
It seems as important bug to me since you recommend using Poetry for project management.
Environment:
- OS: Windows 11
- Python version: 3.12.2
- Quart version: 0.19.4
If you need an example of my Quart project: https://github.com/healplease/qrt
This seems like something that needs to be reported to Poetry.