Merge pull request #23720 from lidizheng/fix-docgen-py

Fix and simplify Python docgen script
pull/23729/head
Lidi Zheng 4 years ago committed by GitHub
commit 1fc6b16278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      templates/tools/distrib/python/grpc_version.py.template
  2. 84
      tools/distrib/python/docgen.py
  3. 17
      tools/distrib/python/grpc_version.py

@ -0,0 +1,19 @@
%YAML 1.2
--- |
# Copyright 2020 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!!
VERSION = '${settings.python_version.pep440()}'

@ -22,77 +22,54 @@ import shutil
import subprocess
import sys
import tempfile
import grpc_version
parser = argparse.ArgumentParser()
parser.add_argument('--config',
metavar='c',
type=str,
nargs=1,
help='GRPC/GPR libraries build configuration',
default='opt')
parser.add_argument('--submit', action='store_true')
parser.add_argument('--repo-owner',
type=str,
help=('Owner of the GitHub repository to be pushed'))
parser.add_argument('--doc-branch', type=str)
parser.add_argument('--doc-branch',
type=str,
default='python-doc-%s' % grpc_version.VERSION)
args = parser.parse_args()
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..'))
CONFIG = args.config
SETUP_PATH = os.path.join(PROJECT_ROOT, 'setup.py')
REQUIREMENTS_PATH = os.path.join(PROJECT_ROOT, 'requirements.bazel.txt')
DOC_PATH = os.path.join(PROJECT_ROOT, 'doc/build')
INCLUDE_PATH = os.path.join(PROJECT_ROOT, 'include')
LIBRARY_PATH = os.path.join(PROJECT_ROOT, 'libs/{}'.format(CONFIG))
VIRTUALENV_DIR = os.path.join(SCRIPT_DIR, 'distrib_virtualenv')
VIRTUALENV_PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python')
VIRTUALENV_PIP_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'pip')
environment = os.environ.copy()
environment.update({
'CONFIG': CONFIG,
'CFLAGS': '-I{}'.format(INCLUDE_PATH),
'LDFLAGS': '-L{}'.format(LIBRARY_PATH),
'LD_LIBRARY_PATH': LIBRARY_PATH,
'GRPC_PYTHON_BUILD_WITH_CYTHON': '1',
'GRPC_PYTHON_ENABLE_DOCUMENTATION_BUILD': '1',
})
if "VIRTUAL_ENV" in os.environ:
VIRTUALENV_DIR = os.environ['VIRTUAL_ENV']
PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python')
subprocess_arguments_list = []
else:
VIRTUALENV_DIR = os.path.join(SCRIPT_DIR, 'distrib_virtualenv')
PYTHON_PATH = os.path.join(VIRTUALENV_DIR, 'bin', 'python')
subprocess_arguments_list = [
['python3', '-m', 'virtualenv', VIRTUALENV_DIR],
]
subprocess_arguments_list = [
{
'args': ['virtualenv', VIRTUALENV_DIR],
'env': environment
},
{
'args': [VIRTUALENV_PIP_PATH, 'install', '--upgrade', 'pip==19.3.1'],
'env': environment
},
{
'args': [VIRTUALENV_PIP_PATH, 'install', '-r', REQUIREMENTS_PATH],
'env': environment
},
{
'args': [VIRTUALENV_PIP_PATH, 'install', 'Sphinx~=1.8.1'],
'env': environment
},
{
'args': [VIRTUALENV_PYTHON_PATH, SETUP_PATH, 'doc'],
'env': environment
},
subprocess_arguments_list += [
[PYTHON_PATH, '-m', 'pip', 'install', '--upgrade', 'pip==19.3.1'],
[PYTHON_PATH, '-m', 'pip', 'install', '-r', REQUIREMENTS_PATH],
[PYTHON_PATH, '-m', 'pip', 'install', '--upgrade', 'Sphinx'],
[PYTHON_PATH, SETUP_PATH, 'doc'],
]
for subprocess_arguments in subprocess_arguments_list:
print('Running command: {}'.format(subprocess_arguments['args']))
subprocess.check_call(**subprocess_arguments)
print('Running command: {}'.format(subprocess_arguments))
subprocess.check_call(args=subprocess_arguments)
if not args.submit:
if not args.repo_owner or not args.doc_branch:
tty_width = int(os.popen('stty size', 'r').read().split()[1])
print('-' * tty_width)
print('Please check generated Python doc inside doc/build')
elif args.submit:
assert args.repo_owner
assert args.doc_branch
github_repository_owner = args.repo_owner
print(
'To push to a GitHub repo, please provide repo owner and doc branch name'
)
else:
# Create a temporary directory out of tree, checkout gh-pages from the
# specified repository, edit it, and push it. It's up to the user to then go
# onto GitHub and make a PR against grpc/grpc:gh-pages.
@ -114,13 +91,14 @@ elif args.submit:
subprocess.check_call(['git', 'checkout', '-b', doc_branch], cwd=repo_dir)
subprocess.check_call([
'git', 'remote', 'add', 'ssh-origin',
'git@github.com:%s/grpc.git' % (github_repository_owner)
'git@github.com:%s/grpc.git' % (args.repo_owner)
],
cwd=repo_dir)
print('Updating documentation...')
shutil.rmtree(python_doc_dir, ignore_errors=True)
shutil.copytree(DOC_PATH, python_doc_dir)
print('Attempting to push documentation...')
print('Attempting to push documentation to %s/%s...' %
(args.repo_owner, doc_branch))
try:
subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir)
subprocess.check_call(

@ -0,0 +1,17 @@
# Copyright 2020 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!!
VERSION = '1.32.0.dev0'
Loading…
Cancel
Save