简体   繁体   English

将 python package 发布到 azure 工件中

[英]Publishing python package into azure artifacts

Due to poor documentation I'm suffering alot to upload my Python Package to my internal Azure Artifacts: I have followed exactly like this由于糟糕的文档,我很难将我的 Python Package 上传到我的内部Azure

Twine authenticate was successful however unable to upload to feed as it keeps asking username! Twine 身份验证成功,但无法上传到 feed,因为它一直在询问用户名!

Is my setup correct?我的设置正确吗? I need to self authenticate the publish without providing username and password我需要在不提供用户名和密码的情况下对发布进行自我验证

Tools:工具:

  • Twine - latest麻线 - 最新
  • Azure-keyring - latest Azure 密钥环 - 最新
  • keyring - latest钥匙圈 - 最新
  • Python 3.10 Python 3.10

Azure steps: Azure步骤:

    - task: TwineAuthenticate@1
        inputs:
          artifactFeed: feedName
        displayName: Twine Authenticate
    
   - script: | 
      twine upload -r feedName --config-file $(System.DefaultWorkingDirectory)\.pypirc dist/*.whl
     displayName: Publish Package1

PyPirc file: PyPirc 文件:

[distutils]
Index-servers =
  feedName

[feedName]
Repository = https://<host>/tfs/***-Collection/_packaging/feedName/pypi/upload

Starting: Twine Authenticate开始:Twine Authenticate

=======================================================================
Task         : Python twine upload authenticate....
=======================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
Adding authentication to configuration for registry Neon
Successfully added auth for 1 internal feed and 0 external endpoint.
Finishing: Twine Authenticate

Starting: Publish Package开始:发布 Package

Uploading distributions to 
https://******/tfs/****-Collection/_packaging/****/pypi/upload
INFO     dist\***_test_framework-0.1.0-py3-none-any.whl (1.2 KB)              
INFO     Querying keyring for username                                         
WARNING  Error getting username from keyring                                   
         Traceback (most recent call last):                                    
           File "C:\Python310\lib\site-packages\twine\auth.py", line 59, in    
         get_username_from_keyring                                             
             creds = keyring.get_credential(system, None)                      
           File "C:\Python310\lib\site-packages\keyring\core.py", line 72, in  
         get_credential                                                        
             return get_keyring().get_credential(service_name, username)       
           File "C:\Python310\lib\site-packages\keyring\backends\chainer.py",  
         line 71, in get_credential                                            
             credential = keyring.get_credential(service, username)            
           File "C:\Python310\lib\site-packages\artifacts_keyring\__init__.py",
         line 58, in get_credential                                            
             username, password = provider.get_credentials(service)     
    Traceback (most recent call last):
      File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\Python310\lib\runpy.py", line 86, in _run_code
               File "C:\Python310\lib\site-packages\artifacts_keyring\plugin.py",  
             line 67, in get_credentials                                           
                 username, password =                                              
             self._get_credentials_from_credential_provider(url, is_retry=False)   
               File "C:\Python310\lib\site-packages\artifacts_keyring\plugin.py",  
             line 124, in _get_credentials_from_credential_provider                
                 raise RuntimeError("Failed to get credentials: process with PID   
             {pid} exited with code {code}; additional error message: {error}"     
             RuntimeError: Failed to get credentials: process with PID 164 exited  
             with code 2; additional error message:                                
        exec(code, run_globals)
      File "C:\Python310\lib\site-packages\twine\__main__.py", line 51, in <module>
        sys.exit(main())
      File "C:\Python310\lib\site-packages\twine\__main__.py", line 33, in main
        error = cli.dispatch(sys.argv[1:])
      File "C:\Python310\lib\site-packages\twine\cli.py", line 123, in dispatch
        return main(args.args)
      File "C:\Python310\lib\site-packages\twine\commands\upload.py", line 198, in main
        return upload(upload_settings, parsed_args.dists)
      File "C:\Python310\lib\site-packages\twine\commands\upload.py", line 127, in upload
        repository = upload_settings.create_repository()
      File "C:\Python310\lib\site-packages\twine\settings.py", line 329, in create_repository
        self.username,
      File "C:\Python310\lib\site-packages\twine\settings.py", line 131, in username
        return cast(Optional[str], self.auth.username)
      File "C:\Python310\lib\site-packages\twine\auth.py", line 34, in username
        return utils.get_userpass_value(
      File "C:\Python310\lib\site-packages\twine\utils.py", line 248, in get_userpass_value
        value = prompt_strategy()
      File "C:\Python310\lib\site-packages\twine\auth.py", line 85, in username_from_keyring_or_prompt
        return self.prompt("username", input)
      File "C:\Python310\lib\site-packages\twine\auth.py", line 96, in prompt
        return how(f"Enter your {what}: ")
    EOFError: EOF when reading a line
    ##[error]PowerShell exited with code '1'.

在此处输入图像描述

I have done a test on my side, and it works fine:我已经做了一个测试,它工作正常:

Project Scope Feed:项目 Scope 供稿:

yml file .yml 文件

trigger:
- none

variables:
- name: PYPIRC_PATH
  value: .pypirc

steps:
- task: CmdLine@2
  inputs:
    script: |
      pip install wheel
      pip install twine
- task: CmdLine@2
  inputs:
    script: 'python setup.py bdist_wheel'

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: '<Project Name>/<Feed Name>'
- task: CmdLine@2
  inputs:
    script: 'python -m twine upload -r <Feed Name> --config-file $(PYPIRC_PATH) dist/*.whl'

.pypirc .pypirc

[distutils]
Index-servers =
  <Organization Name>

[<Organization Name>]
Repository = https://pkgs.dev.azure.com/<Organization Name>/_packaging/<Feed Name>/pypi/upload

Organization Scope Feed:组织 Scope 供稿:

yml file .yml 文件

trigger:
- none

variables:
- name: PYPIRC_PATH
  value: .pypirc

steps:
- task: CmdLine@2
  inputs:
    script: |
      pip install wheel
      pip install twine
- task: CmdLine@2
  inputs:
    script: 'python setup.py bdist_wheel'

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: '<Organization Scope Feed Name>'
- task: CmdLine@2
  inputs:
    script: 'python -m twine upload -r <Organization Scope Feed Name> --config-file $(PYPIRC_PATH) dist/*.whl'

.pypirc .pypirc

[distutils]
Index-servers =
  <Organization Name>

[<Organization Name>]
Repository = https://pkgs.dev.azure.com/<Organization Name>/_packaging/<Organization Scope Feed Name>/pypi/upload

Please refer to this official document:请参考这份官方文档:

https://docs.microsoft.com/en-us/azure/devops/artifacts/quickstarts/python-cli?view=azure-devops-2022 https://docs.microsoft.com/en-us/azure/devops/artifacts/quickstarts/python-cli?view=azure-devops-2022

Try inserting $(PYPIRC_PATH) on your twine upload step, this file will be auto-generated by the Twine_Authenticate task尝试在您的 twine 上传步骤中插入 $(PYPIRC_PATH),此文件将由 Twine_Authenticate 任务自动生成

Example:例子:

  • task: PowerShell@2任务:PowerShell@2

    inputs:输入:

    targetType: 'inline'目标类型:'内联'

    script: C:\Python310\python -m twine upload -r <feed_name> --config-file $(PYPIRC_PATH) dist/*.whl --non-interactive --skip-existing --verbose脚本:C:\Python310\python -m twine upload -r <feed_name> --config-file $(PYPIRC_PATH) dist/*.whl --non-interactive --skip-existing --verbose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM