Masood Malekghassemi | 451887b | 2015-03-30 17:44:19 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import argparse |
| 4 | import os |
| 5 | import shutil |
| 6 | import subprocess |
| 7 | |
| 8 | parser = argparse.ArgumentParser( |
| 9 | description='Submit the package to a PyPI repository.') |
| 10 | parser.add_argument( |
| 11 | '--repository', '-r', metavar='r', type=str, default='pypi', |
| 12 | help='The repository to push the package to. ' |
| 13 | 'Ensure the value appears in your .pypirc file. ' |
| 14 | 'Defaults to "pypi".' |
| 15 | ) |
| 16 | parser.add_argument( |
| 17 | '--identity', '-i', metavar='i', type=str, |
| 18 | help='GPG identity to sign the files with.' |
| 19 | ) |
| 20 | parser.add_argument( |
| 21 | '--username', '-u', metavar='u', type=str, |
| 22 | help='Username to authenticate with the repository. Not needed if you have ' |
| 23 | 'configured your .pypirc to include your username.' |
| 24 | ) |
| 25 | parser.add_argument( |
| 26 | '--password', '-p', metavar='p', type=str, |
| 27 | help='Password to authenticate with the repository. Not needed if you have ' |
| 28 | 'configured your .pypirc to include your password.' |
| 29 | ) |
| 30 | args = parser.parse_args() |
| 31 | |
| 32 | # Move to the root directory of Python GRPC. |
| 33 | pkgdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| 34 | '../../../src/python/src') |
| 35 | # Remove previous distributions; they somehow confuse twine. |
| 36 | try: |
| 37 | shutil.rmtree(os.path.join(pkgdir, 'dist/')) |
| 38 | except: |
| 39 | pass |
| 40 | |
| 41 | # Make the push. |
| 42 | cmd = ['python', 'setup.py', 'sdist'] |
| 43 | subprocess.call(cmd) |
| 44 | |
| 45 | cmd = ['twine', 'upload', '-r', args.repository] |
| 46 | if args.identity is not None: |
| 47 | cmd.extend(['-i', args.identity]) |
| 48 | if args.username is not None: |
| 49 | cmd.extend(['-u', args.username]) |
| 50 | if args.password is not None: |
| 51 | cmd.extend(['-p', args.password]) |
| 52 | cmd.append('dist/*') |
| 53 | |
| 54 | subprocess.call(cmd, cwd=pkgdir) |