如何使用 Poetry 发布到 Azure Devops PyPI 提要?
How to publish to an Azure Devops PyPI feed with Poetry?
我正在尝试设置 Azure Devops 以使用 Poetry 发布到 PyPI 提要。
我了解 Twine 身份验证和将凭据存储到 Azure Key Vault。但是有没有更直接的方法呢?像这样:
- script: |
source .venv/bin/activate
poetry build
displayName: Build wheel
- script: |
source .venv/bin/activate
poetry publish -u USER -p PASS
displayName: Publish wheel
是的。在 Azure DevOps Web 界面中:
- 创建新的 PyPI 提要(工件 > 新提要 > 创建)。
- 创建 PyPI 凭据(连接到提要 > Python > 生成 Python 凭据)。
- 创建名为
username
和 password
的 secret 管道变量,并使用 PyPI 凭据赋值(管道 > 编辑 > 变量 > 新变量 > 保留此值机密 > 确定)。
- 更新
azure-pipelines.yml
CI 文件的内容:
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: 3.7
displayName: Install Python
- script: |
python -m pip install -U pip
pip install poetry
poetry install
displayName: Install software
- script: |
poetry run python -m unittest discover tests/ -v
displayName: Test software
- script: |
poetry build
displayName: Package software
- script: |
poetry config repositories.azure https://pkgs.dev.azure.com/{your organization}/_packaging/{your feed}/pypi/upload
poetry config http-basic.azure $(username) $(password)
poetry publish -r azure
exit 0
displayName: Publish software
您可能需要使用 $(System.AccessToken) 变量:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
poetry config repositories.myazurepypi https://myorg.pkgs.visualstudio.com/123415462134546/_packaging/lcp-tools/pypi/upload/
poetry publish -r myazurepypi -u a -p $(System.AccessToken)
如何使用 poetry
构建并使用 twine
发布,这样我们就可以利用 Azure 自己的 TwineAuthenticate
:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
- script: |
python -m pip install --upgrade pip
pip install poetry
pip install twine
poetry install --no-dev
displayName: 'Install dependencies'
- script: |
poetry build
displayName: 'Build package'
- task: TwineAuthenticate@1
inputs:
artifactFeed: 'repo-name/feed-name'
- script: |
twine upload -r repo-name --config-file $(PYPIRC_PATH) dist/*.whl
displayName: Upload package to Azure Artifact
我正在尝试设置 Azure Devops 以使用 Poetry 发布到 PyPI 提要。
我了解 Twine 身份验证和将凭据存储到 Azure Key Vault。但是有没有更直接的方法呢?像这样:
- script: |
source .venv/bin/activate
poetry build
displayName: Build wheel
- script: |
source .venv/bin/activate
poetry publish -u USER -p PASS
displayName: Publish wheel
是的。在 Azure DevOps Web 界面中:
- 创建新的 PyPI 提要(工件 > 新提要 > 创建)。
- 创建 PyPI 凭据(连接到提要 > Python > 生成 Python 凭据)。
- 创建名为
username
和password
的 secret 管道变量,并使用 PyPI 凭据赋值(管道 > 编辑 > 变量 > 新变量 > 保留此值机密 > 确定)。 - 更新
azure-pipelines.yml
CI 文件的内容:
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: 3.7
displayName: Install Python
- script: |
python -m pip install -U pip
pip install poetry
poetry install
displayName: Install software
- script: |
poetry run python -m unittest discover tests/ -v
displayName: Test software
- script: |
poetry build
displayName: Package software
- script: |
poetry config repositories.azure https://pkgs.dev.azure.com/{your organization}/_packaging/{your feed}/pypi/upload
poetry config http-basic.azure $(username) $(password)
poetry publish -r azure
exit 0
displayName: Publish software
您可能需要使用 $(System.AccessToken) 变量:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
poetry config repositories.myazurepypi https://myorg.pkgs.visualstudio.com/123415462134546/_packaging/lcp-tools/pypi/upload/
poetry publish -r myazurepypi -u a -p $(System.AccessToken)
如何使用 poetry
构建并使用 twine
发布,这样我们就可以利用 Azure 自己的 TwineAuthenticate
:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
- script: |
python -m pip install --upgrade pip
pip install poetry
pip install twine
poetry install --no-dev
displayName: 'Install dependencies'
- script: |
poetry build
displayName: 'Build package'
- task: TwineAuthenticate@1
inputs:
artifactFeed: 'repo-name/feed-name'
- script: |
twine upload -r repo-name --config-file $(PYPIRC_PATH) dist/*.whl
displayName: Upload package to Azure Artifact