blob: dd48f440ba075efe279ad0e7d497845c56f344b3 [file] [log] [blame]
Masood Malekghassemi451887b2015-03-30 17:44:19 -07001#!/usr/bin/env python
Craig Tillerd4db33d2015-05-21 15:27:05 -07002# 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 Malekghassemi451887b2015-03-30 17:44:19 -070030
31import argparse
32import os
33import shutil
34import subprocess
35
36parser = argparse.ArgumentParser(
37 description='Submit the package to a PyPI repository.')
38parser.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)
44parser.add_argument(
45 '--identity', '-i', metavar='i', type=str,
46 help='GPG identity to sign the files with.'
47)
48parser.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)
53parser.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)
58args = parser.parse_args()
59
60# Move to the root directory of Python GRPC.
61pkgdir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
62 '../../../src/python/src')
63# Remove previous distributions; they somehow confuse twine.
64try:
65 shutil.rmtree(os.path.join(pkgdir, 'dist/'))
66except:
67 pass
68
69# Make the push.
70cmd = ['python', 'setup.py', 'sdist']
Masood Malekghassemi2b34e5a2015-04-07 11:03:11 -070071subprocess.call(cmd, cwd=pkgdir)
Masood Malekghassemi451887b2015-03-30 17:44:19 -070072
73cmd = ['twine', 'upload', '-r', args.repository]
74if args.identity is not None:
75 cmd.extend(['-i', args.identity])
76if args.username is not None:
77 cmd.extend(['-u', args.username])
78if args.password is not None:
79 cmd.extend(['-p', args.password])
80cmd.append('dist/*')
81
82subprocess.call(cmd, cwd=pkgdir)