有了天蓝色的管道和诗歌,有什么办法可以避免在每个脚本中都采购 ~/.poetry/env 吗?
With azure pipelines and poetry, is there any way to avoid sourcing ~/.poetry/env in every script?
我目前使用下面的脚本构建我的程序包并将其发布到私有 Azure Artifacts 提要。
在每个脚本中,我必须 运行 行 source $HOME/.poetry/env
否则找不到诗歌命令。
有没有办法消除这种重复?
完整脚本:
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)。
请在您的第一个脚本任务中添加 echo "##vso[task.setvariable variable=PATH]${PATH}:$HOME/.poetry/bin"
以将路径 $HOME/.poetry/bin
设置为系统 PATH 变量。那么您将不再需要在以下脚本任务中添加 source $HOME/.poetry/env
。请检查以下示例。
echo "##vso[task.setvariable...."
只会在以下任务中生效
所以第一个脚本任务还需要用到"source $HOME/.poetry/env"
请查看Set variables in scripts了解更多信息。
- 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()
我目前使用下面的脚本构建我的程序包并将其发布到私有 Azure Artifacts 提要。
在每个脚本中,我必须 运行 行 source $HOME/.poetry/env
否则找不到诗歌命令。
有没有办法消除这种重复?
完整脚本:
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)。
请在您的第一个脚本任务中添加 echo "##vso[task.setvariable variable=PATH]${PATH}:$HOME/.poetry/bin"
以将路径 $HOME/.poetry/bin
设置为系统 PATH 变量。那么您将不再需要在以下脚本任务中添加 source $HOME/.poetry/env
。请检查以下示例。
echo "##vso[task.setvariable...."
只会在以下任务中生效
所以第一个脚本任务还需要用到"source $HOME/.poetry/env"
请查看Set variables in scripts了解更多信息。
- 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()