Skip to content

Commit 9398607

Browse files
committed
Bringing auto-gen import re-writing up to date with files.
There were some manual (via `sed` with the command line) edits made for certain gRPC related parts of `*_pb2.py` files that used dispatch tables to map service names onto request/response protobuf types. For example request_deserializers = { ('google.longrunning.Operations', 'CancelOperation'): google.longrunning.operations_pb2.CancelOperationRequest.FromString, ('google.longrunning.Operations', 'DeleteOperation'): google.longrunning.operations_pb2.DeleteOperationRequest.FromString, ('google.longrunning.Operations', 'GetOperation'): google.longrunning.operations_pb2.GetOperationRequest.FromString, ('google.longrunning.Operations', 'ListOperations'): google.longrunning.operations_pb2.ListOperationsRequest.FromString, } needed to be transformed into request_deserializers = { ('google.longrunning.Operations', 'CancelOperation'): gcloud.bigtable._generated.operations_pb2.CancelOperationRequest.FromString, ('google.longrunning.Operations', 'DeleteOperation'): gcloud.bigtable._generated.operations_pb2.DeleteOperationRequest.FromString, ('google.longrunning.Operations', 'GetOperation'): gcloud.bigtable._generated.operations_pb2.GetOperationRequest.FromString, ('google.longrunning.Operations', 'ListOperations'): gcloud.bigtable._generated.operations_pb2.ListOperationsRequest.FromString, }
1 parent 56218ef commit 9398607

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/rewrite_imports.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ def transform_old_to_new(line, old_module, new_module,
4949
"from {old_module} import ..."
5050
then checks if the line contains
5151
"import {old_module} ..."
52-
and finally checks if the line starts with (ignoring whitespace)
52+
then checks if the line starts with (ignoring whitespace)
5353
"{old_module} ..."
54+
and finally checks if the line contians
55+
"'some-dict-key': {old_module} ..."
5456
5557
In any of these cases, "{old_module}" is replaced with "{new_module}".
5658
If none match, nothing is returned.
@@ -96,6 +98,11 @@ def transform_old_to_new(line, old_module, new_module,
9698
# Only replace the first instance of the old_module.
9799
return line.replace(old_module, new_module, 1)
98100

101+
# Finally check for usage in dictionaries.
102+
if ': ' + old_module in line:
103+
# Only replace the first instance of the old_module.
104+
return line.replace(': ' + old_module, ': ' + new_module, 1)
105+
99106

100107
def transform_line(line):
101108
"""Transforms an import line in a PB2 module.

0 commit comments

Comments
 (0)