Azure Pipelines - 使用 Poetry 的正确方法
对于 Azure Pipelines,使用 poetry
安装 Python 包依赖项的推荐方法是什么?我看到人们只通过 pip
下载poetry
,这是一个很大的禁忌。
- script: |
python -m pip install -U pip
pip install poetry
poetry install
displayName: Install dependencies
我可以使用curl来下载诗歌
。
- script: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
export PATH=$PATH:$HOME/.poetry/bin
poetry install --no-root
displayName: 'Install dependencies'
但在后续的每个步骤中,我都必须再次将诗歌添加到PATH
中...
- script: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
export PATH=$PATH:$HOME/.poetry/bin
poetry install --no-root
displayName: 'Install dependencies'
- script: |
# export PATH=$PATH:$HOME/.poetry/bin
poetry run flake8 src
displayName: 'Linter'
- script: |
# export PATH=$PATH:$HOME/.poetry/bin
poetry add pytest-azurepipelines
poetry run pytest src
displayName: 'Tests'
是否有任何正确方法可以在Azure Pipelines中使用诗歌?
what would be a recommended way to install your Python's package dependencies with poetry
for Azure Pipelines? I see people only downloading poetry
through pip
which is a big no-no.
- script: |
python -m pip install -U pip
pip install poetry
poetry install
displayName: Install dependencies
I can use curl to download poetry
.
- script: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
export PATH=$PATH:$HOME/.poetry/bin
poetry install --no-root
displayName: 'Install dependencies'
But then in each subsequent step I have to add poetry to PATH
again ...
- script: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
export PATH=$PATH:$HOME/.poetry/bin
poetry install --no-root
displayName: 'Install dependencies'
- script: |
# export PATH=$PATH:$HOME/.poetry/bin
poetry run flake8 src
displayName: 'Linter'
- script: |
# export PATH=$PATH:$HOME/.poetry/bin
poetry add pytest-azurepipelines
poetry run pytest src
displayName: 'Tests'
Is there any right way to use poetry in Azure Pipelines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个问题咨询了一位同事。他建议采取单独的步骤将 Poetry 添加到 PATH 中。
Consulted this issue with a collegue. He recommended doing separate step to add Poetry to the PATH.
我不确定这是否是最佳实践,但 Azure 构建代理确实安装了 pipx,这是 受支持的安装 Poetry 的方式。它仍然需要每次安装,但如果没有自托管,您就无法避免这种情况。
我确实尝试过使用诗歌,它似乎按我的预期工作。它为 Poetry 创建了一个单独的虚拟环境,然后您可以随心所欲地使用它。需要注意的是,我不是 Poetry 或 Python 部署专家。
I'm not certain this is a best practice, but Azure build agents do have pipx installed, and this is a supported way to install Poetry. It does still require an install every time, but you can't avoid that without self hosting.
I did try using Poetry and it seems to work as I'd expect. It creates a separate virtual environment for Poetry and then you can use it as you wish. Caveat here is I'm no Poetry or Python deployment expert.
以下
azure-pipelines.yml
对我来说就像一个魅力:The following
azure-pipelines.yml
works like a charm for me:根据您的描述,我认为您使用的代理是微软代理?
我查了微软代理的官方文档,没有提供诗歌。因此,如果您使用 Microsoft 主机代理并且想要使用诗歌,那么在管道运行期间安装诗歌是不可避免的,
因此我建议您在自主机代理上运行管道。
您可以使用虚拟机或已有诗歌的本地计算机,然后在其上设置自主机代理。
之后,您可以在其上运行管道,这次您不需要再安装诗歌了。
详细步骤:
1、在虚拟机或本地机器上运行以下命令。
pip install诗
2、安装configure,并在上述虚拟机或机器上运行代理.
在我这边,我在虚拟机上设置了一个代理:
请参考这个官方文档,这个文档会告诉你如何安装和运行自启动您这边的主机代理:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
3、基于代理运行管道上面运行的。
那么您就不需要每次都安装它。

如果您还有更多疑虑,请告诉我。
From your description, I think the agent you are using is a Microsoft agent?
I checked the official document of the Microsoft agent, there is no poetry provided. Therefore, if you use Microsoft-host agent and you want to use poetry, install poetry during the pipeline run is inevitable
So I recommend you run your pipeline on a self-host agent.
You can use a VM or your local machine which already has the poetry and then set up a self-host agent on it.
After that, you can run your pipeline on it, this time you don't need to install the poetry anymore.
Detailed steps:
1, run the below command on a VM or local machine.
pip install poetry
2, Install configure, and run the agent in above VM or machine.
On my side, I set up an agent on VM:
Please refer to this official document, this document will tell you how to install and run the self-host agent on your side:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
3, Run your pipeline based on the agent that ran above.
Then you don't need to install it every time.

Let me know if you have more concerns.