blob: 4ac8f9c64a847a1455b059bbced463db4f7be327 [file] [log] [blame]
Nathaniel Manistaae4fbcd2015-09-23 16:29:44 +00001#!/usr/bin/env python2.7
Masood Malekghassemid65632a2015-07-27 14:30:09 -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.
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 Malekghassemife8dc882015-07-27 15:30:33 -070054SETUP_PATH = os.path.join(PROJECT_ROOT, 'src/python/grpcio/setup.py')
55DOC_PATH = os.path.join(PROJECT_ROOT, 'src/python/grpcio/doc/build')
Masood Malekghassemid65632a2015-07-27 14:30:09 -070056INCLUDE_PATH = os.path.join(PROJECT_ROOT, 'include')
57LIBRARY_PATH = os.path.join(PROJECT_ROOT, 'libs/{}'.format(CONFIG))
58VIRTUALENV_DIR = os.path.join(SCRIPT_DIR, 'distrib_virtualenv')
59VIRTUALENV_PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python')
60
61environment = os.environ.copy()
62environment.update({
63 'CONFIG': CONFIG,
64 'CFLAGS': '-I{}'.format(INCLUDE_PATH),
65 'LDFLAGS': '-L{}'.format(LIBRARY_PATH),
66 'LD_LIBRARY_PATH': LIBRARY_PATH
67})
68
69subprocess_arguments_list = [
70 {'args': ['make'], 'cwd': PROJECT_ROOT},
71 {'args': ['virtualenv', VIRTUALENV_DIR], 'env': environment},
72 {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'build'], 'env': environment},
73 {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'doc'], 'env': environment},
74]
75
76for subprocess_arguments in subprocess_arguments_list:
77 subprocess.check_call(**subprocess_arguments)
78
79if args.submit:
80 assert args.gh_user
81 assert args.doc_branch
82 github_user = args.gh_user
83 github_repository_owner = (
Masood Malekghassemi38fc0bb2015-09-10 08:49:57 -070084 args.gh_repo_owner if args.gh_repo_owner else args.gh_user)
Masood Malekghassemid65632a2015-07-27 14:30:09 -070085 # Create a temporary directory out of tree, checkout gh-pages from the
86 # specified repository, edit it, and push it. It's up to the user to then go
87 # onto GitHub and make a PR against grpc/grpc:gh-pages.
88 repo_parent_dir = tempfile.mkdtemp()
89 repo_dir = os.path.join(repo_parent_dir, 'grpc')
90 python_doc_dir = os.path.join(repo_dir, 'python')
91 doc_branch = args.doc_branch
92
93 subprocess.check_call([
94 'git', 'clone', 'https://{}@github.com/{}/grpc'.format(
95 github_user, github_repository_owner)
96 ], cwd=repo_parent_dir)
97 subprocess.check_call([
98 'git', 'remote', 'add', 'upstream', 'https://github.com/grpc/grpc'
99 ], cwd=repo_dir)
100 subprocess.check_call(['git', 'fetch', 'upstream'], cwd=repo_dir)
101 subprocess.check_call([
102 'git', 'checkout', 'upstream/gh-pages', '-b', doc_branch
103 ], cwd=repo_dir)
104 shutil.rmtree(python_doc_dir, ignore_errors=True)
105 shutil.copytree(DOC_PATH, python_doc_dir)
106 subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir)
107 subprocess.check_call([
108 'git', 'commit', '-m', 'Auto-update Python documentation'
109 ], cwd=repo_dir)
110 subprocess.check_call([
111 'git', 'push', '--set-upstream', 'origin', doc_branch
112 ], cwd=repo_dir)
113 shutil.rmtree(repo_parent_dir)