Add new functions to grpc api surface

pull/21504/head
Richard Belleville 5 years ago
parent 0f27c1630e
commit b9b126a237
  1. 24
      src/python/grpcio/grpc/__init__.py
  2. 19
      src/python/grpcio_tests/tests/unit/BUILD.bazel
  3. 2
      tools/distrib/python/grpcio_tools/grpc_tools/BUILD
  4. 5
      tools/distrib/python/grpcio_tools/grpc_tools/main.cc
  5. 3
      tools/distrib/python/grpcio_tools/grpc_tools/protoc.py
  6. 1
      tools/distrib/python/grpcio_tools/grpc_tools/protoc_test.py

@ -1967,6 +1967,27 @@ class Compression(enum.IntEnum):
Gzip = _compression.Gzip
def _default_get_protos(*args, **kwargs):
raise NotImplementedError("Install the grpcio-tools package to use get_protos.")
def _default_get_services(*args, **kwargs):
raise NotImplementedError("Install the grpcio-tools package to use get_services.")
def _default_get_protos_and_services(*args, **kwargs):
raise NotImplementedError("Install the grpcio-tools package to use get_protos_and_services.")
try:
import grpc_tools
except ImportError:
get_protos = _default_get_protos
get_services = _default_get_services
get_protos_and_services = _default_get_protos_and_services
else:
from grpc_tools.protoc import get_protos, get_services, get_protos_and_services
################################### __all__ #################################
__all__ = (
@ -2025,6 +2046,9 @@ __all__ = (
'secure_channel',
'intercept_channel',
'server',
'get_protos',
'get_services',
'get_protos_and_services',
)
############################### Extension Shims ################################

@ -89,6 +89,8 @@ py_library(
srcs = [test_file_name],
data = [
"//src/python/grpcio_tests/tests/unit/credentials",
# TODO: Filegroup?
"//src/python/grpcio_tests/unit:data/foo/bar.proto",
],
imports = ["../../"],
main = test_file_name,
@ -109,3 +111,20 @@ py_library(
)
for test_file_name in GRPCIO_TESTS_UNIT
]
py2and3_test(
name = "_dynamic_stubs_test",
size = "small",
srcs = ["_dynamic_stubs_test.py"],
main = "_dynamic_stubs_test.py",
imports = ["../../"],
data = [
"data/foo/bar.proto",
],
deps = [
"//external:six",
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_tests/tests/testing",
"//tools/distrib/python/grpcio_tools/grpc_tools",
],
)

@ -37,6 +37,8 @@ py_library(
deps = [
":cyprotoc",
"@six_archive//:six",
"@com_google_protobuf//:protobuf_python",
"//src/python/grpcio/grpc:grpcio",
],
# TODO: Think about whether we should include well-known protos.
srcs_version = "PY2AND3",

@ -118,7 +118,7 @@ static void calculate_transitive_closure(const ::google::protobuf::FileDescripto
{
for (int i = 0; i < descriptor->dependency_count(); ++i) {
const ::google::protobuf::FileDescriptor* dependency = descriptor->dependency(i);
if (std::find(visited->begin(), visited->end(), dependency) == visited->end()) {
if (visited->find(dependency) == visited->end()) {
calculate_transitive_closure(dependency, transitive_closure, visited);
}
}
@ -146,7 +146,8 @@ static int generate_code(::google::protobuf::compiler::CodeGenerator* code_gener
return 1;
}
std::vector<const ::google::protobuf::FileDescriptor*> transitive_closure;
::detail::calculate_transitive_closure(parsed_file, &transitive_closure, {});
std::unordered_set<const ::google::protobuf::FileDescriptor*> visited;
::detail::calculate_transitive_closure(parsed_file, &transitive_closure, &visited);
detail::GeneratorContextImpl generator_context(transitive_closure, files_out);
std::string error;
for (const auto descriptor : transitive_closure) {

@ -49,7 +49,7 @@ def _module_name_to_proto_file(suffix, module_name):
def _proto_file_to_module_name(suffix, proto_file):
components = proto_file.split(os.path.sep)
proto_base_name = os.path.splitext(components[-1])[0]
return os.path.sep.join(components[:-1] + [proto_base_name + suffix])
return ".".join(components[:-1] + [proto_base_name + suffix])
@contextlib.contextmanager
@ -67,7 +67,6 @@ def _augmented_syspath(new_paths):
# truly already imported the module.
def get_protos(protobuf_path, include_paths=None):
with _augmented_syspath(include_paths):
# TODO: Pull these strings out to module-level constants.
module_name = _proto_file_to_module_name(_PROTO_MODULE_SUFFIX, protobuf_path)
module = importlib.import_module(module_name)
return module

@ -27,6 +27,7 @@ def _run_in_subprocess(test_case):
proc.join()
if not error_queue.empty():
raise error_queue.get()
assert proc.exitcode == 0, "Process exited with code {}".format(proc.exitcode)
def _test_import_protos():
from grpc_tools import protoc

Loading…
Cancel
Save