如何在 pyproject.toml 中添加自定义脚本的快捷方式(使用诗歌)

ier*_*dna 1 python python-poetry pyproject.toml

我最近从 Pipenv 转向诗歌。我习惯在我的 Pipfile 中包含此部分:

[scripts]
test="pytest -s"
test:watch="ptw --runner 'pytest -s'"
Run Code Online (Sandbox Code Playgroud)

因此我可以轻松运行测试,而无需键入完整命令或输入 shell,例如:

[scripts]
test="pytest -s"
test:watch="ptw --runner 'pytest -s'"
Run Code Online (Sandbox Code Playgroud)

当我在 pyproject.toml 中尝试类似的操作时:

pipenv run test:watch
Run Code Online (Sandbox Code Playgroud)

我收到错误:

[tool.poetry.scripts]
watch = "ptw --runner 'pytest -s'"
Run Code Online (Sandbox Code Playgroud)

我应该为此使用 pyproject.toml 中的不同部分吗?

sin*_*roc 6

[tool.poetry.scripts]Poetry 文件中的条目与Pipenv文件中的条目的pyproject.toml用途不同。这是Poetry文档。它适用于入口点,值的形式应为:。[scripts]Pipfilescriptsconsole_scripts importable.module:object.attr

您可能想要使用诸如pothepoet或任何其他类似的“任务运行程序”工具来实现您的目标,例如: