Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: third_party/grpc/tools/distrib/python/docgen.py

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python2.7
2 # Copyright 2015-2016, 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
31 import argparse
32 import os
33 import os.path
34 import shutil
35 import subprocess
36 import tempfile
37
38 parser = argparse.ArgumentParser()
39 parser.add_argument('--config', metavar='c', type=str, nargs=1,
40 help='GRPC/GPR libraries build configuration',
41 default='opt')
42 parser.add_argument('--submit', action='store_true')
43 parser.add_argument('--gh-user', type=str, help='GitHub user to push as.')
44 parser.add_argument('--gh-repo-owner', type=str,
45 help=('Owner of the GitHub repository to be pushed; '
46 'defaults to --gh-user.'))
47 parser.add_argument('--doc-branch', type=str)
48 args = parser.parse_args()
49
50 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
51 PROJECT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..'))
52
53 CONFIG = args.config
54 SETUP_PATH = os.path.join(PROJECT_ROOT, 'setup.py')
55 REQUIREMENTS_PATH = os.path.join(PROJECT_ROOT, 'requirements.txt')
56 DOC_PATH = os.path.join(PROJECT_ROOT, 'doc/build')
57 INCLUDE_PATH = os.path.join(PROJECT_ROOT, 'include')
58 LIBRARY_PATH = os.path.join(PROJECT_ROOT, 'libs/{}'.format(CONFIG))
59 VIRTUALENV_DIR = os.path.join(SCRIPT_DIR, 'distrib_virtualenv')
60 VIRTUALENV_PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python')
61 VIRTUALENV_PIP_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'pip')
62
63 environment = os.environ.copy()
64 environment.update({
65 'CONFIG': CONFIG,
66 'CFLAGS': '-I{}'.format(INCLUDE_PATH),
67 'LDFLAGS': '-L{}'.format(LIBRARY_PATH),
68 'LD_LIBRARY_PATH': LIBRARY_PATH,
69 'GRPC_PYTHON_BUILD_WITH_CYTHON': '1',
70 })
71
72 subprocess_arguments_list = [
73 {'args': ['make'], 'cwd': PROJECT_ROOT},
74 {'args': ['virtualenv', VIRTUALENV_DIR], 'env': environment},
75 {'args': [VIRTUALENV_PIP_PATH, 'install', '-r', REQUIREMENTS_PATH],
76 'env': environment},
77 {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'build'], 'env': environment},
78 {'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'doc'], 'env': environment},
79 ]
80
81 for subprocess_arguments in subprocess_arguments_list:
82 print('Running command: {}'.format(subprocess_arguments['args']))
83 subprocess.check_call(**subprocess_arguments)
84
85 if args.submit:
86 assert args.gh_user
87 assert args.doc_branch
88 github_user = args.gh_user
89 github_repository_owner = (
90 args.gh_repo_owner if args.gh_repo_owner else args.gh_user)
91 # Create a temporary directory out of tree, checkout gh-pages from the
92 # specified repository, edit it, and push it. It's up to the user to then go
93 # onto GitHub and make a PR against grpc/grpc:gh-pages.
94 repo_parent_dir = tempfile.mkdtemp()
95 repo_dir = os.path.join(repo_parent_dir, 'grpc')
96 python_doc_dir = os.path.join(repo_dir, 'python')
97 doc_branch = args.doc_branch
98
99 subprocess.check_call([
100 'git', 'clone', 'https://{}@github.com/{}/grpc'.format(
101 github_user, github_repository_owner)
102 ], cwd=repo_parent_dir)
103 subprocess.check_call([
104 'git', 'remote', 'add', 'upstream', 'https://github.com/grpc/grpc'
105 ], cwd=repo_dir)
106 subprocess.check_call(['git', 'fetch', 'upstream'], cwd=repo_dir)
107 subprocess.check_call([
108 'git', 'checkout', 'upstream/gh-pages', '-b', doc_branch
109 ], cwd=repo_dir)
110 shutil.rmtree(python_doc_dir, ignore_errors=True)
111 shutil.copytree(DOC_PATH, python_doc_dir)
112 subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir)
113 subprocess.check_call([
114 'git', 'commit', '-m', 'Auto-update Python documentation'
115 ], cwd=repo_dir)
116 subprocess.check_call([
117 'git', 'push', '--set-upstream', 'origin', doc_branch
118 ], cwd=repo_dir)
119 shutil.rmtree(repo_parent_dir)
OLDNEW
« no previous file with comments | « third_party/grpc/tools/distrib/python/.gitignore ('k') | third_party/grpc/tools/distrib/python/submit.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698