make_grpcio_tools.py improvements: more readable diffs (#32583)

- sort source files to ensure stable ordering
- generate one source file per line

together this should produce diffs that are much more readable by humans
when sources get added/removed to/from protobuf (and
make_grpcio_tools.py is used to regenerate).
pull/32590/head
Jan Tattermusch 2 years ago committed by GitHub
parent a27b86fb95
commit 0cde9a7550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 186
      tools/distrib/python/grpcio_tools/protoc_lib_deps.py
  2. 18
      tools/distrib/python/make_grpcio_tools.py

File diff suppressed because one or more lines are too long

@ -21,6 +21,7 @@ import filecmp
import glob
import os
import os.path
import pprint
import shutil
import subprocess
import sys
@ -44,6 +45,7 @@ DEPS_FILE_CONTENT = """
# AUTO-GENERATED BY make_grpcio_tools.py!
CC_FILES={cc_files}
PROTO_FILES={proto_files}
CC_INCLUDE={cc_include}
@ -106,6 +108,18 @@ def bazel_query(query):
return output.decode("ascii").splitlines()
def _pretty_print_list(items):
"""Pretty print python list"""
formatted = pprint.pformat(items, indent=4)
# add newline after opening bracket (and fix indent of the next line)
if formatted.startswith('['):
formatted = formatted[0] + '\n ' + formatted[1:]
# add newline before closing bracket
if formatted.endswith(']'):
formatted = formatted[:-1] + '\n' + formatted[-1]
return formatted
def get_deps():
"""Write the result of the bazel query `query` against protobuf to
`out_file`."""
@ -125,8 +139,8 @@ def get_deps():
]
commit_hash = protobuf_submodule_commit_hash()
deps_file_content = DEPS_FILE_CONTENT.format(
cc_files=cc_files,
proto_files=proto_files,
cc_files=_pretty_print_list(sorted(cc_files)),
proto_files=_pretty_print_list(sorted(proto_files)),
cc_include=repr(GRPC_PYTHON_PROTOBUF_RELATIVE_ROOT),
proto_include=repr(GRPC_PYTHON_PROTOBUF_RELATIVE_ROOT),
commit_hash=COMMIT_HASH_PREFIX + commit_hash + COMMIT_HASH_SUFFIX)

Loading…
Cancel
Save