--help flag does not work with QUART_APP envvar and create_app factory
还没有人认领这个 Issue。
评估
调研方向
首先阅读 quart/cli.py 中 Quart CLI 的应用加载路径,尤其是它如何读取 QUART_APP 并处理顶层 --help 选项。使用通过 QUART_APP 选择的 create_app 工厂复现问题,然后与 --app 进行比较。当 QUART_APP=run quart --help 能在没有导入错误的情况下显示帮助,且报告中的子命令仍可正常运行时,即为完成。
由索引模型根据 Issue 内容生成。
描述
When using a create_app() factory function, the --help flag does not work with QUART_APP envvar but does work with --app flag. All other quart subcommands work such as 'run'.
Minimal example
Layout
.
├── init.py
├── run.py
└── server.py
server.py
from quart import Quart
def create_app(mode='Development'):
app = Quart(__name__)
print("hello from create_app")
return app
run.py
from .server import create_app
def main():
app = create_app()
app.run()
if __name__ == "__main__":
app.run()
Expected behaviour
% quart --app=run --help
hello from create_app
Usage: quart [OPTIONS] COMMAND [ARGS]...
A general utility script for Quart applications. An application to load must
be given with the '--app' option, 'QUART_APP' environment variable, or with
an 'app.py' file in the current directory.
Options:
-e, --env-file FILE Load environment variables from this file. python-
dotenv must be installed.
-A, --app IMPORT The QUART application or factory function to load, in
the form 'module:name'. Module can be a dotted import
or file path. Name is not required if it is 'app',
'application', 'create_app', or 'make_app', and can be
'name(args)' to pass arguments.
--debug / --no-debug Set 'app.debug' separately from '--env'.
--version Show the Quart version
--help Show this message and exit.
Commands:
routes Show the routes for the app.
run Run a development server.
shell Run a shell in the app context.
% quart --app=run run
hello from create_app
* Serving Quart app 'quarttest.server'
* Debug mode: False
* Please use an ASGI server (e.g. Hypercorn) directly in production
* Running on http://127.0.0.1:5000 (CTRL + C to quit)
Incorrect behaviour
% QUART_APP=run quart --help
Error: While importing 'quarttest.app', an ImportError was raised:
Traceback (most recent call last):
File "/Users/erikmelander/kod/quarttest/venv/lib/python3.11/site-packages/quart/cli.py", line 186, in locate_app
module = import_module(module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'quarttest.app'
Usage: quart [OPTIONS] COMMAND [ARGS]...
A general utility script for Quart applications. An application to load must
be given with the '--app' option, 'QUART_APP' environment variable, or with
an 'app.py' file in the current directory.
Options:
-e, --env-file FILE Load environment variables from this file. python-
dotenv must be installed.
-A, --app IMPORT The QUART application or factory function to load, in
the form 'module:name'. Module can be a dotted import
or file path. Name is not required if it is 'app',
'application', 'create_app', or 'make_app', and can be
'name(args)' to pass arguments.
--debug / --no-debug Set 'app.debug' separately from '--env'.
--version Show the Quart version
--help Show this message and exit.
Commands:
routes Show the routes for the app.
run Run a development server.
shell Run a shell in the app context.
% QUART_APP=run quart run
hello from create_app
* Serving Quart app 'quarttest.server'
* Debug mode: False
* Please use an ASGI server (e.g. Hypercorn) directly in production
* Running on http://127.0.0.1:5000 (CTRL + C to quit)
Environment:
- Python version: 3.11
- Quart version: 0.22.0
- 主要语言
- Python
- 星标
- 3.7k
- 派生
- 209
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pallets/quart 的其他 Issue
-
`abort` typing doesn't accept Response as a valid parameter可能已有人在做 @touilleMan 于 1478 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 68/100
-
process_response marks the session accessed, so every response gets Vary: Cookie可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 78/100
-
Installing asgi_app middleware as documented results in type errors可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 45/100
-
Allow max content length to be modified on a per-request basis可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
-
mypy: Blueprint type mismatch with `flask.sansio.blueprints.Blueprint`可能已有人在做 @hrimov 于 641 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 35/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
btclib-org/btclib#3062 ·
维护者通常 1 天内回复
-
area:evals area:infra enhancement
难度 2/5 1-3 小时 新手友好度 74/100
jse-avl/support-bot#4 · 1 条评论 ·
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 85/100
qte77/agentic-job-offer-to-application-kit#487 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
btclib-org/btclib-wallet#801 · 1 条评论 ·
维护者通常 1 天内回复
-
documentation good first issue
难度 1/5 1-3 小时 新手友好度 94/100