16 from __future__
import print_function
28 parser = argparse.ArgumentParser()
29 parser.add_argument(
'--repo-owner',
31 help=(
'Owner of the GitHub repository to be pushed'))
32 parser.add_argument(
'--doc-branch',
34 default=
'python-doc-%s' % grpc_version.VERSION)
35 args = parser.parse_args()
37 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
38 PROJECT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR,
'..',
'..',
'..'))
40 SETUP_PATH = os.path.join(PROJECT_ROOT,
'setup.py')
41 REQUIREMENTS_PATH = os.path.join(PROJECT_ROOT,
'requirements.bazel.txt')
42 DOC_PATH = os.path.join(PROJECT_ROOT,
'doc/build')
44 if "VIRTUAL_ENV" in os.environ:
45 VIRTUALENV_DIR = os.environ[
'VIRTUAL_ENV']
46 PYTHON_PATH = os.path.join(VIRTUALENV_DIR,
'bin',
'python')
47 subprocess_arguments_list = []
49 VIRTUALENV_DIR = os.path.join(SCRIPT_DIR,
'distrib_virtualenv')
50 PYTHON_PATH = os.path.join(VIRTUALENV_DIR,
'bin',
'python')
51 subprocess_arguments_list = [
52 [
'python3',
'-m',
'virtualenv', VIRTUALENV_DIR],
55 subprocess_arguments_list += [
56 [PYTHON_PATH,
'-m',
'pip',
'install',
'--upgrade',
'pip==19.3.1'],
57 [PYTHON_PATH,
'-m',
'pip',
'install',
'-r', REQUIREMENTS_PATH],
58 [PYTHON_PATH,
'-m',
'pip',
'install',
'--upgrade',
'Sphinx'],
59 [PYTHON_PATH, SETUP_PATH,
'doc'],
62 for subprocess_arguments
in subprocess_arguments_list:
63 print(
'Running command: {}'.
format(subprocess_arguments))
64 subprocess.check_call(args=subprocess_arguments)
66 if not args.repo_owner
or not args.doc_branch:
68 print(
'-' * tty_width)
69 print(
'Please check generated Python doc inside doc/build')
71 'To push to a GitHub repo, please provide repo owner and doc branch name'
77 repo_parent_dir = tempfile.mkdtemp()
78 print(
'Documentation parent directory: {}'.
format(repo_parent_dir))
79 repo_dir = os.path.join(repo_parent_dir,
'grpc')
80 python_doc_dir = os.path.join(repo_dir,
'python')
81 doc_branch = args.doc_branch
83 print(
'Cloning your repository...')
84 subprocess.check_call([
89 'https://github.com/grpc/grpc',
92 subprocess.check_call([
'git',
'checkout',
'-b', doc_branch], cwd=repo_dir)
93 subprocess.check_call([
94 'git',
'remote',
'add',
'ssh-origin',
95 'git@github.com:%s/grpc.git' % args.repo_owner
98 print(
'Updating documentation...')
99 shutil.rmtree(python_doc_dir, ignore_errors=
True)
100 shutil.copytree(DOC_PATH, python_doc_dir)
101 print(
'Attempting to push documentation to %s/%s...' %
102 (args.repo_owner, doc_branch))
104 subprocess.check_call([
'git',
'add',
'--all'], cwd=repo_dir)
105 subprocess.check_call(
106 [
'git',
'commit',
'-m',
'Auto-update Python documentation'],
108 subprocess.check_call(
109 [
'git',
'push',
'--set-upstream',
'ssh-origin', doc_branch],
111 except subprocess.CalledProcessError:
112 print(
'Failed to push documentation. Examine this directory and push '
113 'manually: {}'.
format(repo_parent_dir))
115 shutil.rmtree(repo_parent_dir)