我想我缺少一些简单的东西
我有一个python诗歌应用程序:
name = "my-first-api"
version = "0.1.0"
description = ""
readme = "README.md"
packages = [{include = "application"}]
[tool.poetry.scripts]
start = "main:start"
[tool.poetry.dependencies]
python = ">=3.10,<3.12"
pip= "23.0.1"
setuptools="65.5.0"
fastapi="0.89.1"
uvicorn="0.20.0"
[tool.poetry.group.dev.dependencies]
pyinstaller = "^5.10.1"
pytest = "^7.3.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
我可以运行它并使用 Poetry 构建它,但是,我也希望能够使用 poetry 脚本创建可执行文件。
现在我这样构建它:
poetry run pyinstaller main.py --collect-submodules application --onefile --name myapi
我想要类似的东西
poetry package
也自动创建此可执行文件。我该如何连接它?
顺便说一句。这不起作用:(
[tool.poetry.scripts]
start = "main:start"
builddist = "poetry run pyinstaller main.py --collect-submodules application --onefile --name myapi"
您可以在 pyproject.toml 文件中定义一个自定义脚本,该脚本运行带有所需选项的 pyinstaller 命令。
build = "poetry run pyinstaller main.py --collect-submodules application --onefile --name myapi"
如果您愿意,您还可以将脚本的名称(在此示例中构建)自定义为更具描述性的名称。
请注意,这只会构建可执行文件,不会创建包。要创建包,您可以使用 poetry build,它将为您的应用程序创建源代码分发和 wheel 包。
你正在寻找一种方法来定义简单的命令来运行特定的任务。 Poetry 不(还)直接支持这一点。但是至少有一个诗歌插件支持这个:https://github.com/nat-n/poethepoet