Re-add compiler protos to grpcio-tools (#31062)

* Re-add compiler protos to grpcio-tools

* Attempt to break

* Actually fail if protobufs don't compile. Who wrote this thing?

* Add an actual test

* yapf

* Whoops. Thought I'd reverted you

* Please the formatter gods
pull/31079/head
Richard Belleville 2 years ago committed by GitHub
parent ffbd468982
commit 2d94537854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/python/grpcio_tests/setup.py
  2. 27
      src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py
  3. 30
      src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/compiler.proto
  4. 2
      tools/distrib/python/grpcio_tools/protoc_lib_deps.py
  5. 11
      tools/distrib/python/make_grpcio_tools.py

@ -67,7 +67,9 @@ PACKAGE_DATA = {
'credentials/server1.key',
'credentials/server1.pem',
],
'tests.protoc_plugin.protos.invocation_testing': ['same.proto',],
'tests.protoc_plugin.protos.invocation_testing': [
'same.proto', 'compiler.proto'
],
'tests.protoc_plugin.protos.invocation_testing.split_messages': [
'messages.proto',
],

@ -26,6 +26,7 @@ import unittest
import grpc
from grpc_tools import protoc
import pkg_resources
import six
from tests.unit import test_common
@ -37,6 +38,8 @@ _COMMON_NAMESPACE = b'package grpc_protoc_plugin.invocation_testing;'
_RELATIVE_PROTO_PATH = 'relative_proto_path'
_RELATIVE_PYTHON_OUT = 'relative_python_out'
_TEST_DIR = os.path.dirname(os.path.realpath(__file__))
@contextlib.contextmanager
def _system_path(path_insertion):
@ -321,10 +324,30 @@ def _create_test_case_classes():
yield _create_test_case_class(split_proto, protoc_style)
class WellKnownTypesTest(unittest.TestCase):
def testWellKnownTypes(self):
os.chdir(_TEST_DIR)
out_dir = tempfile.mkdtemp(suffix="wkt_test", dir='.')
well_known_protos_include = pkg_resources.resource_filename(
'grpc_tools', '_proto')
args = [
'grpc_tools.protoc',
'--proto_path=protos',
'--proto_path={}'.format(well_known_protos_include),
'--python_out={}'.format(out_dir),
'--grpc_python_out={}'.format(out_dir),
'protos/invocation_testing/compiler.proto',
]
rc = protoc.main(args)
self.assertEqual(0, rc)
def load_tests(loader, tests, pattern):
tests = tuple(
tests = (tuple(
loader.loadTestsFromTestCase(test_case_class)
for test_case_class in _create_test_case_classes())
for test_case_class in _create_test_case_classes()) +
tuple(loader.loadTestsFromTestCase(WellKnownTypesTest)))
return unittest.TestSuite(tests=tests)

@ -0,0 +1,30 @@
// Copyright 2022 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.
syntax = "proto3";
import "google/protobuf/any.proto";
import "google/protobuf/api.proto";
import "google/protobuf/compiler/plugin.proto";
import "google/protobuf/descriptor.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/source_context.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/type.proto";
import "google/protobuf/wrappers.proto";
package test_compiler;

File diff suppressed because one or more lines are too long

@ -84,7 +84,10 @@ GRPC_PYTHON_INCLUDE = os.path.join(GRPC_PYTHON_ROOT, 'grpc_root', 'include')
BAZEL_DEPS = os.path.join(GRPC_ROOT, 'tools', 'distrib', 'python',
'bazel_deps.sh')
BAZEL_DEPS_PROTOC_LIB_QUERY = '//:protoc_lib'
BAZEL_DEPS_COMMON_PROTOS_QUERY = '//:well_known_type_protos'
BAZEL_DEPS_COMMON_PROTOS_QUERIES = [
'//:well_known_type_protos',
'//:built_in_runtime_protos',
]
def protobuf_submodule_commit_hash():
@ -112,10 +115,12 @@ def get_deps():
for name in cc_files_output
if name.endswith('.cc') and name.startswith(PROTOBUF_CC_PREFIX)
]
proto_files_output = bazel_query(BAZEL_DEPS_COMMON_PROTOS_QUERY)
raw_proto_files = []
for target in BAZEL_DEPS_COMMON_PROTOS_QUERIES:
raw_proto_files += bazel_query(target)
proto_files = [
name[len(PROTOBUF_PROTO_PREFIX):]
for name in proto_files_output
for name in raw_proto_files
if name.endswith('.proto') and name.startswith(PROTOBUF_PROTO_PREFIX)
]
commit_hash = protobuf_submodule_commit_hash()

Loading…
Cancel
Save