Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
f0fb7413
Commit
f0fb7413
authored
Mar 14, 2017
by
Nathaniel Manista
Committed by
GitHub
Mar 14, 2017
Browse files
Options
Downloads
Plain Diff
Merge pull request #10141 from nathanielmanistaatgoogle/import-prefix
Add import prefix to Python code generator.
parents
fce0f049
40d55f9d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/compiler/python_generator.cc
+14
-8
14 additions, 8 deletions
src/compiler/python_generator.cc
src/compiler/python_generator.h
+3
-0
3 additions, 0 deletions
src/compiler/python_generator.h
with
17 additions
and
8 deletions
src/compiler/python_generator.cc
+
14
−
8
View file @
f0fb7413
...
@@ -101,18 +101,20 @@ class IndentScope {
...
@@ -101,18 +101,20 @@ class IndentScope {
// TODO(https://github.com/google/protobuf/issues/888):
// TODO(https://github.com/google/protobuf/issues/888):
// Export `ModuleName` from protobuf's
// Export `ModuleName` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
// `src/google/protobuf/compiler/python/python_generator.cc` file.
grpc
::
string
ModuleName
(
const
grpc
::
string
&
filename
)
{
grpc
::
string
ModuleName
(
const
grpc
::
string
&
filename
,
const
grpc
::
string
&
import_prefix
)
{
grpc
::
string
basename
=
StripProto
(
filename
);
grpc
::
string
basename
=
StripProto
(
filename
);
basename
=
StringReplace
(
basename
,
"-"
,
"_"
);
basename
=
StringReplace
(
basename
,
"-"
,
"_"
);
basename
=
StringReplace
(
basename
,
"/"
,
"."
);
basename
=
StringReplace
(
basename
,
"/"
,
"."
);
return
basename
+
"_pb2"
;
return
import_prefix
+
basename
+
"_pb2"
;
}
}
// TODO(https://github.com/google/protobuf/issues/888):
// TODO(https://github.com/google/protobuf/issues/888):
// Export `ModuleAlias` from protobuf's
// Export `ModuleAlias` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
// `src/google/protobuf/compiler/python/python_generator.cc` file.
grpc
::
string
ModuleAlias
(
const
grpc
::
string
&
filename
)
{
grpc
::
string
ModuleAlias
(
const
grpc
::
string
&
filename
,
grpc
::
string
module_name
=
ModuleName
(
filename
);
const
grpc
::
string
&
import_prefix
)
{
grpc
::
string
module_name
=
ModuleName
(
filename
,
import_prefix
);
// We can't have dots in the module name, so we replace each with _dot_.
// We can't have dots in the module name, so we replace each with _dot_.
// But that could lead to a collision between a.b and a_dot_b, so we also
// But that could lead to a collision between a.b and a_dot_b, so we also
// duplicate each underscore.
// duplicate each underscore.
...
@@ -189,7 +191,7 @@ bool PrivateGenerator::GetModuleAndMessagePath(const Descriptor* type,
...
@@ -189,7 +191,7 @@ bool PrivateGenerator::GetModuleAndMessagePath(const Descriptor* type,
grpc
::
string
generator_file_name
=
file
->
name
();
grpc
::
string
generator_file_name
=
file
->
name
();
grpc
::
string
module
;
grpc
::
string
module
;
if
(
generator_file_name
!=
file_name
||
generate_in_pb2_grpc
)
{
if
(
generator_file_name
!=
file_name
||
generate_in_pb2_grpc
)
{
module
=
ModuleAlias
(
file_name
)
+
"."
;
module
=
ModuleAlias
(
file_name
,
config
.
import_prefix
)
+
"."
;
}
else
{
}
else
{
module
=
""
;
module
=
""
;
}
}
...
@@ -666,8 +668,10 @@ bool PrivateGenerator::PrintPreamble() {
...
@@ -666,8 +668,10 @@ bool PrivateGenerator::PrintPreamble() {
for
(
int
k
=
0
;
k
<
2
;
++
k
)
{
for
(
int
k
=
0
;
k
<
2
;
++
k
)
{
const
Descriptor
*
type
=
types
[
k
];
const
Descriptor
*
type
=
types
[
k
];
grpc
::
string
type_file_name
=
type
->
file
()
->
name
();
grpc
::
string
type_file_name
=
type
->
file
()
->
name
();
grpc
::
string
module_name
=
ModuleName
(
type_file_name
);
grpc
::
string
module_name
=
grpc
::
string
module_alias
=
ModuleAlias
(
type_file_name
);
ModuleName
(
type_file_name
,
config
.
import_prefix
);
grpc
::
string
module_alias
=
ModuleAlias
(
type_file_name
,
config
.
import_prefix
);
imports_set
.
insert
(
std
::
make_tuple
(
module_name
,
module_alias
));
imports_set
.
insert
(
std
::
make_tuple
(
module_name
,
module_alias
));
}
}
}
}
...
@@ -766,7 +770,9 @@ pair<bool, grpc::string> PrivateGenerator::GetGrpcServices() {
...
@@ -766,7 +770,9 @@ pair<bool, grpc::string> PrivateGenerator::GetGrpcServices() {
}
// namespace
}
// namespace
GeneratorConfiguration
::
GeneratorConfiguration
()
GeneratorConfiguration
::
GeneratorConfiguration
()
:
grpc_package_root
(
"grpc"
),
beta_package_root
(
"grpc.beta"
)
{}
:
grpc_package_root
(
"grpc"
),
beta_package_root
(
"grpc.beta"
),
import_prefix
(
""
)
{}
PythonGrpcGenerator
::
PythonGrpcGenerator
(
const
GeneratorConfiguration
&
config
)
PythonGrpcGenerator
::
PythonGrpcGenerator
(
const
GeneratorConfiguration
&
config
)
:
config_
(
config
)
{}
:
config_
(
config
)
{}
...
...
This diff is collapsed.
Click to expand it.
src/compiler/python_generator.h
+
3
−
0
View file @
f0fb7413
...
@@ -45,7 +45,10 @@ namespace grpc_python_generator {
...
@@ -45,7 +45,10 @@ namespace grpc_python_generator {
struct
GeneratorConfiguration
{
struct
GeneratorConfiguration
{
GeneratorConfiguration
();
GeneratorConfiguration
();
grpc
::
string
grpc_package_root
;
grpc
::
string
grpc_package_root
;
// TODO(https://github.com/grpc/grpc/issues/8622): Drop this.
grpc
::
string
beta_package_root
;
grpc
::
string
beta_package_root
;
// TODO(https://github.com/google/protobuf/issues/888): Drop this.
grpc
::
string
import_prefix
;
};
};
class
PythonGrpcGenerator
:
public
grpc
::
protobuf
::
compiler
::
CodeGenerator
{
class
PythonGrpcGenerator
:
public
grpc
::
protobuf
::
compiler
::
CodeGenerator
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment