Skip to content

Commit

Permalink
Spanner: pick up fixes to GAPIC generator. (#6576)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tseaver authored Nov 19, 2018
1 parent a6e2e9a commit a7ce1ff
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=database_admin_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -137,13 +137,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = database_admin_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -102,6 +104,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def list_databases(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=instance_admin_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -161,13 +161,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = instance_admin_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -102,6 +104,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def list_instance_configs(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
17 changes: 12 additions & 5 deletions spanner/google/cloud/spanner_v1/gapic/spanner_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=spanner_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -139,13 +139,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = spanner_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -103,6 +105,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def create_session(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
121 changes: 6 additions & 115 deletions spanner/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

s.move(library / 'google/cloud/spanner_v1/proto')
s.move(library / 'google/cloud/spanner_v1/gapic')
s.move(library / 'tests')

# Add grpcio-gcp options
s.replace(
Expand Down Expand Up @@ -58,6 +59,11 @@
'\g<1>options = [(grpc_gcp.API_CONFIG_CHANNEL_ARG, grpc_gcp_config)]'
'\g<0>',
)
s.replace(
"tests/unit/gapic/v1/test_spanner_client_v1.py",
"from google.cloud import spanner_v1",
"from google.cloud.spanner_v1.gapic import spanner_client as spanner_v1",
)

#----------------------------------------------------------------------------
# Generate instance admin client
Expand Down Expand Up @@ -88,114 +94,6 @@
)

# Fix docstrings
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* The instance is readable via the API, with all requested attributes
but no allocated resources. Its state is `CREATING`.""",
r"""
* The instance is readable via the API, with all requested attributes
but no allocated resources. Its state is `CREATING`.""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* Cancelling the operation renders the instance immediately unreadable
via the API.""",
r"""
* Cancelling the operation renders the instance immediately unreadable
via the API.""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* Billing for all successfully-allocated resources begins \(some types
may have lower than the requested levels\).""",
r"""
* Billing for all successfully-allocated resources begins (some types
may have lower than the requested levels).""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* The instance and \*all of its databases\* immediately and
irrevocably disappear from the API. All data in the databases
is permanently deleted.""",
r"""
* The instance and *all of its databases* immediately and
irrevocably disappear from the API. All data in the databases
is permanently deleted.""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* ``labels.env:dev`` --> The instance has the label \\"env\\" and the value of
::
the label contains the string \\"dev\\".""",
r"""
* ``labels.env:dev`` --> The instance has the label \\"env\\"
and the value of the label contains the string \\"dev\\".""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* ``name:howl labels.env:dev`` --> The instance's name contains \\"howl\\" and
::
it has the label \\"env\\" with its value
containing \\"dev\\".""",
r"""
* ``name:howl labels.env:dev`` --> The instance's name
contains \\"howl\\" and it has the label \\"env\\" with
its value containing \\"dev\\".""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* For resource types for which a decrease in the instance's allocation
has been requested, billing is based on the newly-requested level.""",
r"""
* For resource types for which a decrease in the instance's allocation
has been requested, billing is based on the newly-requested level.""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* Cancelling the operation sets its metadata's
\[cancel_time\]\[google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time\], and begins
restoring resources to their pre-request values. The operation
is guaranteed to succeed at undoing all resource changes,
after which point it terminates with a `CANCELLED` status.""",
r"""
* Cancelling the operation sets its metadata's
[cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time],
and begins restoring resources to their pre-request values.
The operation is guaranteed to succeed at undoing all resource
changes, after which point it terminates with a `CANCELLED` status.""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* Reading the instance via the API continues to give the pre-request
resource levels.""",
r"""
* Reading the instance via the API continues to give the pre-request
resource levels.""",
)
s.replace(
'google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py',
r"""
\* Billing begins for all successfully-allocated resources \(some types
may have lower than the requested levels\).
\* All newly-reserved resources are available for serving the instance's
tables.""",
r"""
* Billing begins for all successfully-allocated resources (some types
may have lower than the requested levels).
* All newly-reserved resources are available for serving the instance's
tables.""",
)
s.replace(
'google/cloud/spanner_v1/proto/transaction_pb2.py',
r"""====*""",
Expand Down Expand Up @@ -239,10 +137,3 @@
'from google\.cloud\.spanner\.admin\.database_v1.proto',
'from google.cloud.spanner_admin_database_v1.proto',
)

# Fix docstrings
s.replace(
'google/cloud/spanner_admin_database_v1/gapic/database_admin_client.py',
r'database ID must be enclosed in backticks \(`` `` ``\).',
r'database ID must be enclosed in backticks.',
)
Loading

0 comments on commit a7ce1ff

Please sign in to comment.