【问题标题】:How to publish to an Azure Devops PyPI feed with Poetry?如何使用 Poetry 发布到 Azure Devops PyPI 提要?
【发布时间】:2019-03-30 20:26:49
【问题描述】:

我正在尝试设置 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

【问题讨论】:

    标签: python azure-devops python-poetry


    【解决方案1】:

    是的。在 Azure DevOps Web 界面中:

    1. 创建一个新的 PyPI 提要(工件 > 新提要 > 创建)。
    2. 创建 PyPI 凭据(连接到 feed > Python > 生成 Python 凭据)。
    3. 创建 secret 名为 usernamepassword 的管道变量,并使用 PyPI 凭据进行赋值(管道 > 编辑 > 变量 > 新变量 > 将此值保密 > 确定)。
    4. 使用以下内容更新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
    

    【讨论】:

    • 这是否意味着我会在我的 .azure-pipelines.yml 中以纯文本形式发布我的密码或个人身份验证令牌?如果没有,我不确定我是否理解您提到的诗歌 http-basic 配置行中的内容。
    • @DanYeaw 是的,您在azure-pipelines.yml 中以纯文本形式写下您的凭据(您要求一个简单的解决方案)。
    • 是的,直截了当很好,但我们还需要一些不会将我们的凭据暴露给所有人的东西
    • @DanYeaw 我已经使用 Azure Pipelines secret variables 更新了设置 PyPI 凭据的答案,而不会将它们暴露给版本控制系统,这是推荐的做法。我希望这会有所帮助。
    【解决方案2】:

    您可能想要使用 $(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)
    

    【讨论】:

      【解决方案3】:

      使用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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-23
        • 2020-07-31
        • 2020-01-18
        • 2021-04-17
        • 2019-03-26
        • 2021-08-01
        • 2019-11-30
        • 1970-01-01
        相关资源
        最近更新 更多