Azure Pipelines - 使用 Poetry 的正确方法
Azure Pipelines - proper way to use Poetry
使用 poetry
为 Azure Pipelines 安装 Python 包依赖项的推荐方法是什么?我看到人们只通过 pip
下载 poetry
,这是一个很大的禁忌。
- script: |
python -m pip install -U pip
pip install poetry
poetry install
displayName: Install dependencies
我可以用curl下载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'
但是在随后的每个步骤中,我都必须再次向 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 中有没有正确使用诗歌的方法?
根据您的描述,我认为您使用的代理是 Microsoft 代理?
我查了一下微软代理的官方文档,没有提供诗歌。所以,如果你用Microsoft-host代理,又想用诗歌,在管道运行期间安装诗歌是必然的
所以我建议您 运行 在 self-host 代理上使用您的管道。
您可以使用 VM 或您的本地计算机已经有诗歌,然后在其上设置 self-host 代理。
之后就可以运行自己的pipeline了,这次就不用再安装poetry了
详细步骤:
1,运行 在 VM 或本地计算机上执行以下命令。
pip install poetry
2、安装配置,运行在上面的虚拟机或机器中安装代理。
在我这边,我在 VM 上设置了一个代理:
请参考这个官方文档,这个文档会告诉你如何安装运行你这边的self-host代理:
https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
3、运行 您的管道基于上述 运行 的代理。
pool:
name: VMAS
steps:
- script: |
echo Write your commands here
echo Hello world
python --version
poetry --version
displayName: 'Command Line Script'
那就不用每次都安装了。
如果您有更多疑虑,请告诉我。
向同事咨询过这个问题。他建议采取单独的步骤将 Poetry 添加到 PATH。
- task: UsePythonVersion@0
inputs:
versionSpec: '3.8'
displayName: 'Use Python 3.8'
- 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: echo "##vso[task.prependpath]$HOME/.poetry/bin"
displayName: Add poetry to PATH
- script: |
poetry run flake8 src
displayName: 'Linter'
- script: |
poetry add pytest-azurepipelines
poetry run pytest src
displayName: 'Tests'
使用 poetry
为 Azure Pipelines 安装 Python 包依赖项的推荐方法是什么?我看到人们只通过 pip
下载 poetry
,这是一个很大的禁忌。
- script: |
python -m pip install -U pip
pip install poetry
poetry install
displayName: Install dependencies
我可以用curl下载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'
但是在随后的每个步骤中,我都必须再次向 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 中有没有正确使用诗歌的方法?
根据您的描述,我认为您使用的代理是 Microsoft 代理?
我查了一下微软代理的官方文档,没有提供诗歌。所以,如果你用Microsoft-host代理,又想用诗歌,在管道运行期间安装诗歌是必然的
所以我建议您 运行 在 self-host 代理上使用您的管道。
您可以使用 VM 或您的本地计算机已经有诗歌,然后在其上设置 self-host 代理。
之后就可以运行自己的pipeline了,这次就不用再安装poetry了
详细步骤:
1,运行 在 VM 或本地计算机上执行以下命令。
pip install poetry
2、安装配置,运行在上面的虚拟机或机器中安装代理。
在我这边,我在 VM 上设置了一个代理:
请参考这个官方文档,这个文档会告诉你如何安装运行你这边的self-host代理:
https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
3、运行 您的管道基于上述 运行 的代理。
pool:
name: VMAS
steps:
- script: |
echo Write your commands here
echo Hello world
python --version
poetry --version
displayName: 'Command Line Script'
那就不用每次都安装了。
如果您有更多疑虑,请告诉我。
向同事咨询过这个问题。他建议采取单独的步骤将 Poetry 添加到 PATH。
- task: UsePythonVersion@0
inputs:
versionSpec: '3.8'
displayName: 'Use Python 3.8'
- 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: echo "##vso[task.prependpath]$HOME/.poetry/bin"
displayName: Add poetry to PATH
- script: |
poetry run flake8 src
displayName: 'Linter'
- script: |
poetry add pytest-azurepipelines
poetry run pytest src
displayName: 'Tests'