This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow relative imports when entire prefix is stripped.
When running under Python 3, PEP 0328 formalized `import package` as an absolute import. This PEP introduced a new syntax, `import .package` as a relative import (of a "sub" package). Finally, the syntax `from . import bar` was made to import a "peer" package. Python gRPC code generated by the gRPC compiler uses the gRPC package name as the absolute import, which works great if you own that particular namespace, and can afford to allocate that namespace to that protobuf globally, or are running under the (now EOL) Python 2. There are some existing reports of this problem on GitHub and elsewhere on the internet such as protocolbuffers/protobuf#881 https://www.bountysource.com/issues/27402421-python-generated-code-import-paths https://stackoverflow.com/questions/57213543/grpc-generated-python-script-fails-to-find-a-local-module-in-the-same-directory that outline this issue, and tend to be closed WONTFIX or people work around it by sed'ing the output protobuf files. This change allows the use of the prefixes (and a previously broken codepath) to work around this bug by doing something that semantically feels right-ish. The gRPC Python plugin accepts arguments to strip prefixes via the `--grpc_python_out` flag. For example: --grpc_python_out=grpc_2_0,mycorp.:. will cause the generated imports to become: `from myservice.v1 import baz` rather than `from mycorp.myservice.v1 import baz` Now, when when this is taken to the extreme, and the *entire* prefix except for the final dot is stripped -- for instance: --grpc_python_out=grpc_2_0,mycorp.myservice.v1:. THe existing gRPC plugin will generate the (buggy) output of: `from import baz` This patch changes the behavior of that (buggy) output to become: `from . import baz` Which will allow the import of a peer package under Python 3 without having to exist in a global namespace that matches the protobuf package tree. Beyond the fact this feels like the correct usage of the prefix stripping feature, this also can not result in broken output, since the output was previously broken, so no one is relying on this particular behavior.
- Loading branch information
Showing
14 changed files
with
21 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule abseil-cpp
updated
48 files
Submodule benchmark
updated
37 files
+1 −0 | .gitignore | |
+5 −0 | AUTHORS | |
+2 −0 | BUILD.bazel | |
+5 −2 | CMakeLists.txt | |
+7 −1 | CONTRIBUTORS | |
+142 −31 | README.md | |
+9 −3 | WORKSPACE | |
+1 −1 | appveyor.yml | |
+2 −2 | cmake/CXXFeatureCheck.cmake | |
+1 −1 | cmake/GoogleTest.cmake | |
+5 −2 | include/benchmark/benchmark.h | |
+1 −1 | mingw.py | |
+6 −2 | src/CMakeLists.txt | |
+68 −63 | src/benchmark.cc | |
+2 −0 | src/benchmark_register.cc | |
+1 −1 | src/benchmark_runner.cc | |
+37 −31 | src/commandlineflags.cc | |
+41 −11 | src/commandlineflags.h | |
+10 −12 | src/console_reporter.cc | |
+4 −0 | src/counter.cc | |
+5 −0 | src/counter.h | |
+15 −0 | src/cycleclock.h | |
+2 −2 | src/json_reporter.cc | |
+1 −1 | src/mutex.h | |
+1 −1 | src/reporter.cc | |
+10 −1 | src/sysinfo.cc | |
+1 −1 | src/thread_manager.h | |
+3 −3 | src/thread_timer.h | |
+28 −20 | test/BUILD | |
+31 −30 | test/CMakeLists.txt | |
+125 −2 | test/commandlineflags_gtest.cc | |
+2 −0 | test/complexity_test.cc | |
+10 −0 | test/output_test_helper.cc | |
+9 −3 | test/reporter_output_test.cc | |
+7 −0 | test/string_util_gtest.cc | |
+2 −0 | test/user_counters_tabular_test.cc | |
+93 −0 | test/user_counters_test.cc |
Submodule boringssl-with-bazel
updated
5726 files
Submodule cares
updated
58 files
Submodule gflags
updated
7 files
+38 −24 | INSTALL.md | |
+2 −2 | cmake/config.cmake.in | |
+2 −2 | cmake/package.pc.in | |
+6 −6 | src/gflags.cc | |
+1 −1 | src/gflags.h.in | |
+3 −3 | src/gflags_completions.cc | |
+7 −7 | src/gflags_reporting.cc |
Submodule googleapis
updated
2628 files
Submodule googletest
updated
121 files
Submodule libuv
updated
91 files
Submodule protobuf
updated
from fe1790 to 10c48c
Submodule protoc-gen-validate
updated
from e14318 to cc1ae4
Submodule udpa
updated
39 files