blob: 15bd8d855f6948cff34a99195714a8edbf708833 [file] [log] [blame]
Nathaniel Manistaae4fbcd2015-09-23 16:29:44 +00001#!/usr/bin/env python2.7
Craig Tiller6169d5f2016-03-31 07:46:18 -07002# Copyright 2015, Google Inc.
Masood Malekghassemid65632a2015-07-27 14:30:09 -07003# 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.
30
31import argparse
32import os
33import os.path
34import shutil
35import subprocess
36import tempfile
37
38parser = argparse.ArgumentParser()
39parser.add_argument('--config', metavar='c', type=str, nargs=1,
40 help='GRPC/GPR libraries build configuration',
41 default='opt')
42parser.add_argument('--submit', action='store_true')
43parser.add_argument('--gh-user', type=str, help='GitHub user to push as.')
44parser.add_argument('--gh-repo-owner', type=str,
45 help=('Owner of the GitHub repository to be pushed; '
46 'defaults to --gh-user.'))
47parser.add_argument('--doc-branch', type=str)
48args = parser.parse_args()
49
50SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
51PROJECT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..'))
52
53CONFIG = args.config
Masood Malekghassemi3ee1f9b2016-02-22 18:37:18 -080054SETUP_PATH = os.path.join(PROJECT_ROOT, 'setup.py')
55REQUIREMENTS_PATH = os.path.join(PROJECT_ROOT, 'requirements.txt')
56DOC_PATH = os.path.join(PROJECT_ROOT, 'doc/build')
Masood Malekghassemid65632a2015-07-27 14:30:09 -070057INCLUDE_PATH = os.path.join(PROJECT_ROOT, 'include')
58LIBRARY_PATH = os.path.join(PROJECT_ROOT, 'libs/{}'.format(CONFIG))
59VIRTUALENV_DIR = os.path.join(SCRIPT_DIR, 'distrib_virtualenv')
60VIRTUALENV_PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python')
Masood Malekghassemi3ee1f9b2016-02-22 18:37:18 -080061VIRTUALENV_PIP_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'pip')
Masood Malekghassemid65632a2015-07-27 14:30:09 -070062
63environment = os.environ.copy()
64environment.update({
65 'CONFIG': CONFIG,
66 'CFLAGS': '-I{}'.format(INCLUDE_PATH),
67 'LDFLAGS': '-L{}'.format(LIBRARY_PATH),
Masood Malekghassemi3ee1f9b2016-02-22 18:37:18 -080068 'LD_LIBRARY_PATH': LIBRARY_PATH,
69 'GRPC_PYTHON_BUILD_WITH_CYTHON': '1',
Masood Malekghassemid65632a2015-07-27 14:30:09 -070070})
71
72subprocess_arguments_list = [
Masood Malekghassemid65632a2015-07-27 14:30:09 -070073 {'args': ['virtualenv', VIRTUALENV_DIR], 'env': environment},
Masood Malekghassemi6f7d4222016-07-20 17:16:07 -070074 {'args': [VIRTUALENV_PIP_PATH, 'install', '--upgrade', 'pip'],
75 'env': environment},
Masood Malekghassemi3ee1f9b2016-02-22 18:37:18 -080076 {'args': [VIRTUALENV_PIP_PATH, 'install', '-r', REQUIREMENTS_PATH],
77 'env': environment},
Masood Malekghassemid65632a2015-07-27 14:30:09 -070078 {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'build'], 'env': environment},
79 {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'doc'], 'env': environment},
80]
81
82for subprocess_arguments in subprocess_arguments_list:
Masood Malekghassemi3ee1f9b2016-02-22 18:37:18 -080083 print('Running command: {}'.format(subprocess_arguments['args']))
Masood Malekghassemid65632a2015-07-27 14:30:09 -070084 subprocess.check_call(**subprocess_arguments)
85
86if args.submit:
87 assert args.gh_user
88 assert args.doc_branch
89 github_user = args.gh_user
90 github_repository_owner = (
Masood Malekghassemi38fc0bb2015-09-10 08:49:57 -070091 args.gh_repo_owner if args.gh_repo_owner else args.gh_user)
Masood Malekghassemid65632a2015-07-27 14:30:09 -070092 # Create a temporary directory out of tree, checkout gh-pages from the
93 # specified repository, edit it, and push it. It's up to the user to then go
94 # onto GitHub and make a PR against grpc/grpc:gh-pages.
95 repo_parent_dir = tempfile.mkdtemp()
96 repo_dir = os.path.join(repo_parent_dir, 'grpc')
97 python_doc_dir = os.path.join(repo_dir, 'python')
98 doc_branch = args.doc_branch
99
100 subprocess.check_call([
101 'git', 'clone', 'https://{}@github.com/{}/grpc'.format(
102 github_user, github_repository_owner)
103 ], cwd=repo_parent_dir)
104 subprocess.check_call([
105 'git', 'remote', 'add', 'upstream', 'https://github.com/grpc/grpc'
106 ], cwd=repo_dir)
107 subprocess.check_call(['git', 'fetch', 'upstream'], cwd=repo_dir)
108 subprocess.check_call([
109 'git', 'checkout', 'upstream/gh-pages', '-b', doc_branch
110 ], cwd=repo_dir)
111 shutil.rmtree(python_doc_dir, ignore_errors=True)
112 shutil.copytree(DOC_PATH, python_doc_dir)
113 subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir)
114 subprocess.check_call([
115 'git', 'commit', '-m', 'Auto-update Python documentation'
116 ], cwd=repo_dir)
117 subprocess.check_call([
118 'git', 'push', '--set-upstream', 'origin', doc_branch
119 ], cwd=repo_dir)
120 shutil.rmtree(repo_parent_dir)