如何使用 Poetry 发布到 Azure Devops PyPI 源?

Dan*_*eaw 4 python azure-devops python-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
Run Code Online (Sandbox Code Playgroud)

Mag*_*ero 5

是的。在 Azure DevOps Web 界面中:

  1. 创建一个新的 PyPI 提要(工件 > 新提要 > 创建)。
  2. 创建 PyPI 凭据(连接到提要 > Python > 生成 Python 凭据)。
  3. 创建使用 PyPI 凭据命名和赋值的秘密管道变量(管道 > 编辑 > 变量 > 新变量 > 将此值保密 > 确定)。usernamepassword
  4. 使用以下内容更新azure-pipelines.ymlCI 文件的内容:
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
Run Code Online (Sandbox Code Playgroud)


Luc*_*cia 5

How about building with poetry and publishing with twine, so we can take advantage of Azure's own 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
Run Code Online (Sandbox Code Playgroud)