Skip to content

Commit a7ce1ff

Browse files
authored
Spanner: pick up fixes to GAPIC generator. (#6576)
Includes fixes from these PRs: - googleapis/gapic-generator#2407 (closing googleapis/gapic-generator#2389) - googleapis/gapic-generator#2396 (for #5523 and dupes). Includes changes to *all* generated tests. Removes now-spurious docstring fixups. Closes #6507.
1 parent a6e2e9a commit a7ce1ff

File tree

10 files changed

+333
-197
lines changed

10 files changed

+333
-197
lines changed

spanner/google/cloud/spanner_admin_database_v1/gapic/database_admin_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self,
104104
transport=None,
105105
channel=None,
106106
credentials=None,
107-
client_config=database_admin_client_config.config,
107+
client_config=None,
108108
client_info=None):
109109
"""Constructor.
110110
@@ -137,13 +137,20 @@ def __init__(self,
137137
your own client library.
138138
"""
139139
# Raise deprecation warnings for things we want to go away.
140-
if client_config:
141-
warnings.warn('The `client_config` argument is deprecated.',
142-
PendingDeprecationWarning)
140+
if client_config is not None:
141+
warnings.warn(
142+
'The `client_config` argument is deprecated.',
143+
PendingDeprecationWarning,
144+
stacklevel=2)
145+
else:
146+
client_config = database_admin_client_config.config
147+
143148
if channel:
144149
warnings.warn(
145150
'The `channel` argument is deprecated; use '
146-
'`transport` instead.', PendingDeprecationWarning)
151+
'`transport` instead.',
152+
PendingDeprecationWarning,
153+
stacklevel=2)
147154

148155
# Instantiate the transport.
149156
# The transport is responsible for handling serialization and

spanner/google/cloud/spanner_admin_database_v1/gapic/transports/database_admin_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self,
6666
credentials=credentials,
6767
)
6868

69+
self._channel = channel
70+
6971
# gRPC uses objects called "stubs" that are bound to the
7072
# channel and provide a basic method for each RPC.
7173
self._stubs = {
@@ -102,6 +104,15 @@ def create_channel(cls,
102104
scopes=cls._OAUTH_SCOPES,
103105
)
104106

107+
@property
108+
def channel(self):
109+
"""The gRPC channel used by the transport.
110+
111+
Returns:
112+
grpc.Channel: A gRPC channel object.
113+
"""
114+
return self._channel
115+
105116
@property
106117
def list_databases(self):
107118
"""Return the gRPC stub for {$apiMethod.name}.

spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(self,
128128
transport=None,
129129
channel=None,
130130
credentials=None,
131-
client_config=instance_admin_client_config.config,
131+
client_config=None,
132132
client_info=None):
133133
"""Constructor.
134134
@@ -161,13 +161,20 @@ def __init__(self,
161161
your own client library.
162162
"""
163163
# Raise deprecation warnings for things we want to go away.
164-
if client_config:
165-
warnings.warn('The `client_config` argument is deprecated.',
166-
PendingDeprecationWarning)
164+
if client_config is not None:
165+
warnings.warn(
166+
'The `client_config` argument is deprecated.',
167+
PendingDeprecationWarning,
168+
stacklevel=2)
169+
else:
170+
client_config = instance_admin_client_config.config
171+
167172
if channel:
168173
warnings.warn(
169174
'The `channel` argument is deprecated; use '
170-
'`transport` instead.', PendingDeprecationWarning)
175+
'`transport` instead.',
176+
PendingDeprecationWarning,
177+
stacklevel=2)
171178

172179
# Instantiate the transport.
173180
# The transport is responsible for handling serialization and

spanner/google/cloud/spanner_admin_instance_v1/gapic/transports/instance_admin_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self,
6666
credentials=credentials,
6767
)
6868

69+
self._channel = channel
70+
6971
# gRPC uses objects called "stubs" that are bound to the
7072
# channel and provide a basic method for each RPC.
7173
self._stubs = {
@@ -102,6 +104,15 @@ def create_channel(cls,
102104
scopes=cls._OAUTH_SCOPES,
103105
)
104106

107+
@property
108+
def channel(self):
109+
"""The gRPC channel used by the transport.
110+
111+
Returns:
112+
grpc.Channel: A gRPC channel object.
113+
"""
114+
return self._channel
115+
105116
@property
106117
def list_instance_configs(self):
107118
"""Return the gRPC stub for {$apiMethod.name}.

spanner/google/cloud/spanner_v1/gapic/spanner_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self,
106106
transport=None,
107107
channel=None,
108108
credentials=None,
109-
client_config=spanner_client_config.config,
109+
client_config=None,
110110
client_info=None):
111111
"""Constructor.
112112
@@ -139,13 +139,20 @@ def __init__(self,
139139
your own client library.
140140
"""
141141
# Raise deprecation warnings for things we want to go away.
142-
if client_config:
143-
warnings.warn('The `client_config` argument is deprecated.',
144-
PendingDeprecationWarning)
142+
if client_config is not None:
143+
warnings.warn(
144+
'The `client_config` argument is deprecated.',
145+
PendingDeprecationWarning,
146+
stacklevel=2)
147+
else:
148+
client_config = spanner_client_config.config
149+
145150
if channel:
146151
warnings.warn(
147152
'The `channel` argument is deprecated; use '
148-
'`transport` instead.', PendingDeprecationWarning)
153+
'`transport` instead.',
154+
PendingDeprecationWarning,
155+
stacklevel=2)
149156

150157
# Instantiate the transport.
151158
# The transport is responsible for handling serialization and

spanner/google/cloud/spanner_v1/gapic/transports/spanner_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def __init__(self,
7171
credentials=credentials,
7272
)
7373

74+
self._channel = channel
75+
7476
# gRPC uses objects called "stubs" that are bound to the
7577
# channel and provide a basic method for each RPC.
7678
self._stubs = {
@@ -103,6 +105,15 @@ def create_channel(cls,
103105
scopes=cls._OAUTH_SCOPES,
104106
)
105107

108+
@property
109+
def channel(self):
110+
"""The gRPC channel used by the transport.
111+
112+
Returns:
113+
grpc.Channel: A gRPC channel object.
114+
"""
115+
return self._channel
116+
106117
@property
107118
def create_session(self):
108119
"""Return the gRPC stub for {$apiMethod.name}.

spanner/synth.py

Lines changed: 6 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
s.move(library / 'google/cloud/spanner_v1/proto')
3232
s.move(library / 'google/cloud/spanner_v1/gapic')
33+
s.move(library / 'tests')
3334

3435
# Add grpcio-gcp options
3536
s.replace(
@@ -58,6 +59,11 @@
5859
'\g<1>options = [(grpc_gcp.API_CONFIG_CHANNEL_ARG, grpc_gcp_config)]'
5960
'\g<0>',
6061
)
62+
s.replace(
63+
"tests/unit/gapic/v1/test_spanner_client_v1.py",
64+
"from google.cloud import spanner_v1",
65+
"from google.cloud.spanner_v1.gapic import spanner_client as spanner_v1",
66+
)
6167

6268
#----------------------------------------------------------------------------
6369
# Generate instance admin client
@@ -88,114 +94,6 @@
8894
)
8995

9096
# Fix docstrings
91-
s.replace(
92-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
93-
r"""
94-
\* The instance is readable via the API, with all requested attributes
95-
but no allocated resources. Its state is `CREATING`.""",
96-
r"""
97-
* The instance is readable via the API, with all requested attributes
98-
but no allocated resources. Its state is `CREATING`.""",
99-
)
100-
s.replace(
101-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
102-
r"""
103-
\* Cancelling the operation renders the instance immediately unreadable
104-
via the API.""",
105-
r"""
106-
* Cancelling the operation renders the instance immediately unreadable
107-
via the API.""",
108-
)
109-
s.replace(
110-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
111-
r"""
112-
\* Billing for all successfully-allocated resources begins \(some types
113-
may have lower than the requested levels\).""",
114-
r"""
115-
* Billing for all successfully-allocated resources begins (some types
116-
may have lower than the requested levels).""",
117-
)
118-
s.replace(
119-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
120-
r"""
121-
\* The instance and \*all of its databases\* immediately and
122-
irrevocably disappear from the API. All data in the databases
123-
is permanently deleted.""",
124-
r"""
125-
* The instance and *all of its databases* immediately and
126-
irrevocably disappear from the API. All data in the databases
127-
is permanently deleted.""",
128-
)
129-
s.replace(
130-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
131-
r"""
132-
\* ``labels.env:dev`` --> The instance has the label \\"env\\" and the value of
133-
::
134-
135-
the label contains the string \\"dev\\".""",
136-
r"""
137-
* ``labels.env:dev`` --> The instance has the label \\"env\\"
138-
and the value of the label contains the string \\"dev\\".""",
139-
)
140-
s.replace(
141-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
142-
r"""
143-
\* ``name:howl labels.env:dev`` --> The instance's name contains \\"howl\\" and
144-
::
145-
146-
it has the label \\"env\\" with its value
147-
containing \\"dev\\".""",
148-
r"""
149-
* ``name:howl labels.env:dev`` --> The instance's name
150-
contains \\"howl\\" and it has the label \\"env\\" with
151-
its value containing \\"dev\\".""",
152-
)
153-
s.replace(
154-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
155-
r"""
156-
\* For resource types for which a decrease in the instance's allocation
157-
has been requested, billing is based on the newly-requested level.""",
158-
r"""
159-
* For resource types for which a decrease in the instance's allocation
160-
has been requested, billing is based on the newly-requested level.""",
161-
)
162-
s.replace(
163-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
164-
r"""
165-
\* Cancelling the operation sets its metadata's
166-
\[cancel_time\]\[google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time\], and begins
167-
restoring resources to their pre-request values. The operation
168-
is guaranteed to succeed at undoing all resource changes,
169-
after which point it terminates with a `CANCELLED` status.""",
170-
r"""
171-
* Cancelling the operation sets its metadata's
172-
[cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time],
173-
and begins restoring resources to their pre-request values.
174-
The operation is guaranteed to succeed at undoing all resource
175-
changes, after which point it terminates with a `CANCELLED` status.""",
176-
)
177-
s.replace(
178-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
179-
r"""
180-
\* Reading the instance via the API continues to give the pre-request
181-
resource levels.""",
182-
r"""
183-
* Reading the instance via the API continues to give the pre-request
184-
resource levels.""",
185-
)
186-
s.replace(
187-
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
188-
r"""
189-
\* Billing begins for all successfully-allocated resources \(some types
190-
may have lower than the requested levels\).
191-
\* All newly-reserved resources are available for serving the instance's
192-
tables.""",
193-
r"""
194-
* Billing begins for all successfully-allocated resources (some types
195-
may have lower than the requested levels).
196-
* All newly-reserved resources are available for serving the instance's
197-
tables.""",
198-
)
19997
s.replace(
20098
'google/cloud/spanner_v1/proto/transaction_pb2.py',
20199
r"""====*""",
@@ -239,10 +137,3 @@
239137
'from google\.cloud\.spanner\.admin\.database_v1.proto',
240138
'from google.cloud.spanner_admin_database_v1.proto',
241139
)
242-
243-
# Fix docstrings
244-
s.replace(
245-
'google/cloud/spanner_admin_database_v1/gapic/database_admin_client.py',
246-
r'database ID must be enclosed in backticks \(`` `` ``\).',
247-
r'database ID must be enclosed in backticks.',
248-
)

0 commit comments

Comments
 (0)