Masood Malekghassemi | 451887b | 2015-03-30 17:44:19 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Craig Tiller | d4db33d | 2015-05-21 15:27:05 -0700 | [diff] [blame] | 2 | # Copyright 2015, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Masood Malekghassemi | 451887b | 2015-03-30 17:44:19 -0700 | [diff] [blame] | 30 | |
| 31 | import argparse |
| 32 | import os |
| 33 | import shutil |
| 34 | import subprocess |
| 35 | |
| 36 | parser = argparse.ArgumentParser( |
| 37 | description='Submit the package to a PyPI repository.') |
| 38 | parser.add_argument( |
| 39 | '--repository', '-r', metavar='r', type=str, default='pypi', |
| 40 | help='The repository to push the package to. ' |
| 41 | 'Ensure the value appears in your .pypirc file. ' |
| 42 | 'Defaults to "pypi".' |
| 43 | ) |
| 44 | parser.add_argument( |
| 45 | '--identity', '-i', metavar='i', type=str, |
| 46 | help='GPG identity to sign the files with.' |
| 47 | ) |
| 48 | parser.add_argument( |
| 49 | '--username', '-u', metavar='u', type=str, |
| 50 | help='Username to authenticate with the repository. Not needed if you have ' |
| 51 | 'configured your .pypirc to include your username.' |
| 52 | ) |
| 53 | parser.add_argument( |
| 54 | '--password', '-p', metavar='p', type=str, |
| 55 | help='Password to authenticate with the repository. Not needed if you have ' |
| 56 | 'configured your .pypirc to include your password.' |
| 57 | ) |
| 58 | args = parser.parse_args() |
| 59 | |
| 60 | # Move to the root directory of Python GRPC. |
| 61 | pkgdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| 62 | '../../../src/python/src') |
| 63 | # Remove previous distributions; they somehow confuse twine. |
| 64 | try: |
| 65 | shutil.rmtree(os.path.join(pkgdir, 'dist/')) |
| 66 | except: |
| 67 | pass |
| 68 | |
| 69 | # Make the push. |
| 70 | cmd = ['python', 'setup.py', 'sdist'] |
Masood Malekghassemi | 2b34e5a | 2015-04-07 11:03:11 -0700 | [diff] [blame] | 71 | subprocess.call(cmd, cwd=pkgdir) |
Masood Malekghassemi | 451887b | 2015-03-30 17:44:19 -0700 | [diff] [blame] | 72 | |
| 73 | cmd = ['twine', 'upload', '-r', args.repository] |
| 74 | if args.identity is not None: |
| 75 | cmd.extend(['-i', args.identity]) |
| 76 | if args.username is not None: |
| 77 | cmd.extend(['-u', args.username]) |
| 78 | if args.password is not None: |
| 79 | cmd.extend(['-p', args.password]) |
| 80 | cmd.append('dist/*') |
| 81 | |
| 82 | subprocess.call(cmd, cwd=pkgdir) |