简体   繁体   中英

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

Twine authenticate was successful however unable to upload to feed as it keeps asking username!

Is my setup correct? I need to self authenticate the publish without providing username and password

Tools:

  • Twine - latest
  • Azure-keyring - latest
  • keyring - latest
  • Python 3.10

Azure steps:

    - 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:

[distutils]
Index-servers =
  feedName

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

Starting: 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

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:

yml file

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

[distutils]
Index-servers =
  <Organization Name>

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

Organization Scope Feed:

yml file

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

[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

Try inserting $(PYPIRC_PATH) on your twine upload step, this file will be auto-generated by the Twine_Authenticate task

Example:

  • task: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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