使用天青的管道和诗歌,有什么方法可以避免在每个脚本中使用〜/.poetry/env? [英] With azure pipelines and poetry, is there any way to avoid sourcing ~/.poetry/env in every script?

查看:84
本文介绍了使用天青的管道和诗歌,有什么方法可以避免在每个脚本中使用〜/.poetry/env?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用下面的脚本来生成我的程序包,并将其发布到私有的Azure Artifacts feed.在每个脚本中,我都必须运行 source $ HOME/.poetry/env 行,否则它将找不到poetry命令.

I currently use the script below to build my package and publish it to a private Azure Artifacts feed. In every script, I have to run the line source $HOME/.poetry/env or it cannot find the poetry command.

是否可以删除此重复?

完整脚本:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

strategy:
  matrix:
    Python38:
      python.version: '3.8'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    sudo apt-get install texlive texlive-latex-extra latexmk
    python -m pip install --upgrade pip
    python -m pip install keyring artifacts-keyring
    curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
    source $HOME/.poetry/env
    poetry install
  displayName: 'Install package and tools'

- script: |
    source $HOME/.poetry/env
    poetry run python -m isort -rc
    poetry run python -m black -l 79 .
  displayName: 'Format code'

- script: |
    source $HOME/.poetry/env
    poetry run python -m flake8
    poetry run python -m bandit -r ini=.bandit .
    poetry run python -m mypy --config-file=mypy.ini src/preppy/ tests/ docs/
  displayName: 'Lint code'

- script: |
    source $HOME/.poetry/env
    poetry run python -m pytest tests/
  displayName: 'Test code'

- script: |
    source $HOME/.poetry/env
    poetry run make clean
    poetry run make latexpdf
  workingDirectory: docs
  displayName: 'Build documentation'

- script: |
    source $HOME/.poetry/env
    poetry build
  displayName: 'Create package'

- script: |
    source $HOME/.poetry/env
    poetry config repositories.azure https://pkgs.dev.azure.com/MY_USERNAME/preppy/_packaging/builds/pypi/upload
    poetry publish -r azure --username=$(pipelines-token) --password=$(pipelines-token)
    exit 0
  displayName: 'Publish artifact'

推荐答案

source $ HOME/.poetry/env 仅适用于当前shell.您需要在代理的系统 PATH 中设置Poetry的bin目录($ HOME/.poetry/bin).

source $HOME/.poetry/env only applies for current shell. You need to set Poetry's bin directory ($HOME/.poetry/bin) in the system PATH of the agent.

请在第一个脚本任务中添加 echo"## vso [task.setvariable variable = PATH] $ {PATH}:$ HOME/.poetry/bin" 以设置路径 $HOME/.poetry/bin 到系统PATH变量.然后,您将不再需要在以下脚本任务中添加 source $ HOME/.poetry/env .请检查以下示例.

Please add echo "##vso[task.setvariable variable=PATH]${PATH}:$HOME/.poetry/bin" in your first script task to set path $HOME/.poetry/bin to system PATH variable. Then you wont need to add source $HOME/.poetry/env in the following script tasks any more. Please check below example.

echo"## vso [task.setvariable ...." 仅在以下任务中生效.

echo "##vso[task.setvariable...."will only take effect in the following tasks.

因此,您仍然需要在第一个脚本任务中使用"source $ HOME/.poetry/env".

请检查在脚本中设置变量以获取更多信息.

Please check Set variables in scripts for more information.

- script: |
    curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

    #below script will only take effect in the following tasks. 
    #So you still need to use "source $HOME/.poetry/env" in the first script task.

    echo "##vso[task.setvariable variable=PATH]${PATH}:$HOME/.poetry/bin" 
    source $HOME/.poetry/env

    poetry install
  displayName: 'Install package and tools'

- script: |
    poetry --version
  condition: always()

这篇关于使用天青的管道和诗歌,有什么方法可以避免在每个脚本中使用〜/.poetry/env?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆