Skip to content

Commit

Permalink
protodoc: upgrade to Python 3. (#8129)
Browse files Browse the repository at this point in the history
Risk level: Low
Testing: Rebuilt docs, manual inspection of some example generated files.

Signed-off-by: Harvey Tuch <[email protected]>
  • Loading branch information
htuch authored Sep 3, 2019
1 parent cf55298 commit 39a4423
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ rm -rf "${GENERATED_RST_DIR}"
mkdir -p "${GENERATED_RST_DIR}"

source_venv "$BUILD_DIR"
pip install -r "${SCRIPT_DIR}"/requirements.txt
pip3 install -r "${SCRIPT_DIR}"/requirements.txt

bazel build ${BAZEL_BUILD_OPTIONS} @envoy_api//docs:protos --aspects \
tools/protodoc/protodoc.bzl%proto_doc_aspect --output_groups=rst --action_env=CPROFILE_ENABLED \
--action_env=ENVOY_BLOB_SHA --spawn_strategy=standalone --host_force_python=PY2
tools/protodoc/protodoc.bzl%proto_doc_aspect --output_groups=rst --action_env=CPROFILE_ENABLED=1 \
--action_env=ENVOY_BLOB_SHA --spawn_strategy=standalone --host_force_python=PY3

# These are the protos we want to put in docs, this list will grow.
# TODO(htuch): Factor this out of this script.
Expand Down
2 changes: 1 addition & 1 deletion tools/protodoc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ licenses(["notice"]) # Apache 2
py_binary(
name = "protodoc",
srcs = ["protodoc.py"],
python_version = "PY2",
python_version = "PY3",
visibility = ["//visibility:public"],
deps = [
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
Expand Down
8 changes: 4 additions & 4 deletions tools/protodoc/protodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from collections import defaultdict
import cProfile
import functools
import io
import os
import pstats
import StringIO
import re
import sys

Expand Down Expand Up @@ -709,7 +709,7 @@ def GenerateRst(proto_file):
def Main():
# http://www.expobrain.net/2015/09/13/create-a-plugin-for-google-protocol-buffer/
request = plugin_pb2.CodeGeneratorRequest()
request.ParseFromString(sys.stdin.read())
request.ParseFromString(sys.stdin.buffer.read())
response = plugin_pb2.CodeGeneratorResponse()
cprofile_enabled = os.getenv('CPROFILE_ENABLED')

Expand All @@ -724,14 +724,14 @@ def Main():
f.content = GenerateRst(proto_file)
if cprofile_enabled:
pr.disable()
stats_stream = StringIO.StringIO()
stats_stream = io.StringIO()
ps = pstats.Stats(pr,
stream=stats_stream).sort_stats(os.getenv('CPROFILE_SORTBY', 'cumulative'))
stats_file = response.file.add()
stats_file.name = proto_file.name + '.rst.profile'
ps.print_stats()
stats_file.content = stats_stream.getvalue()
sys.stdout.write(response.SerializeToString())
sys.stdout.buffer.write(response.SerializeToString())


if __name__ == '__main__':
Expand Down

0 comments on commit 39a4423

Please sign in to comment.