1
0

pypi.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. from configparser import Error
  4. from requests.exceptions import HTTPError
  5. from twine.commands.upload import main as twine_upload
  6. from twine.utils import get_config
  7. from .utils import ScriptError
  8. def pypi_upload(args):
  9. print('Uploading to PyPi')
  10. try:
  11. rel = args.release.replace('-rc', 'rc')
  12. twine_upload([
  13. 'dist/docker_compose-{}*.whl'.format(rel),
  14. 'dist/docker-compose-{}*.tar.gz'.format(rel)
  15. ])
  16. except HTTPError as e:
  17. if e.response.status_code == 400 and 'File already exists' in str(e):
  18. if not args.finalize_resume:
  19. raise ScriptError(
  20. 'Package already uploaded on PyPi.'
  21. )
  22. print('Skipping PyPi upload - package already uploaded')
  23. else:
  24. raise ScriptError('Unexpected HTTP error uploading package to PyPi: {}'.format(e))
  25. def check_pypirc():
  26. try:
  27. config = get_config()
  28. except Error as e:
  29. raise ScriptError('Failed to parse .pypirc file: {}'.format(e))
  30. if config is None:
  31. raise ScriptError('Failed to parse .pypirc file')
  32. if 'pypi' not in config:
  33. raise ScriptError('Missing [pypi] section in .pypirc file')
  34. if not (config['pypi'].get('username') and config['pypi'].get('password')):
  35. raise ScriptError('Missing login/password pair for pypi repo')