Skip to content

Commit ad50dbf

Browse files
authored
feat: update to the latest version of the code generator (googleapis#147)
The compute protos are now [available in googleapis/googleapis](https://github.com/googleapis/googleapis/tree/master/google/cloud/compute/v1), and the generated code is also available in googleapis/googleapis-gen [here](https://github.com/googleapis/googleapis-gen/tree/master/google/cloud/compute/v1/compute-small-v1-py). This PR pulls in the latest version of the generated client from googleapis-gen, which may have significant differences. I've added the `do not merge` label while we discuss whether any differences could break user code. This PR also deletes `synth.py` and adds configuration files for owl bot. owl bot will save time for maintainers as it will automatically open PRs when there are updates in googleapis-gen without requiring maintainers to run synthtool to build the client from protos. Additionally, similar to autosynth, PRs will be automatically opened when there are updates to templated files. fix(deps): require google-api-core >=2.2.0 fix(deps): require proto-plus >=1.19.7 docs: list oneofs in docstring fix: add 'dict' annotation type to 'request' feat: support self-signed JWT flow for service accounts chore(samples): Merging usage bucket tests into one, to avoid race conditions
1 parent e0edc35 commit ad50dbf

File tree

410 files changed

+88267
-41238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+88267
-41238
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
docker:
16+
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
17+
digest: sha256:ec49167c606648a063d1222220b48119c912562849a0528f35bfb592a9f72737
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
docker:
16+
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
17+
18+
deep-remove-regex:
19+
- /owl-bot-staging
20+
21+
deep-copy-regex:
22+
- source: /google/cloud/compute/(v.*)/compute-v.*-py/(.*)
23+
dest: /owl-bot-staging/$1/$2
24+
25+
begin-after-commit-hash: 70f7f0525414fe4dfeb2fc2e81546b073f83a621

packages/google-cloud-compute/docs/index.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.. include:: README.rst
22

3+
.. include:: multiprocessing.rst
4+
5+
36
API Reference
47
-------------
58
.. toctree::
@@ -15,6 +18,6 @@ Changelog
1518
For a list of all ``google-cloud-compute`` releases:
1619

1720
.. toctree::
18-
:maxdepth: 2
21+
:maxdepth: 2
1922

20-
changelog
23+
changelog

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@
1414
# limitations under the License.
1515
#
1616
from collections import OrderedDict
17-
from distutils import util
1817
import os
1918
import re
20-
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
19+
from typing import Dict, Optional, Sequence, Tuple, Type, Union
2120
import pkg_resources
2221

23-
from google.api_core import client_options as client_options_lib # type: ignore
24-
from google.api_core import exceptions as core_exceptions # type: ignore
25-
from google.api_core import gapic_v1 # type: ignore
26-
from google.api_core import retry as retries # type: ignore
22+
from google.api_core import client_options as client_options_lib
23+
from google.api_core import exceptions as core_exceptions
24+
from google.api_core import gapic_v1
25+
from google.api_core import retry as retries
2726
from google.auth import credentials as ga_credentials # type: ignore
2827
from google.auth.transport import mtls # type: ignore
2928
from google.auth.transport.grpc import SslCredentials # type: ignore
3029
from google.auth.exceptions import MutualTLSChannelError # type: ignore
3130
from google.oauth2 import service_account # type: ignore
3231

32+
try:
33+
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault]
34+
except AttributeError: # pragma: NO COVER
35+
OptionalRetry = Union[retries.Retry, object] # type: ignore
36+
3337
from google.cloud.compute_v1.services.accelerator_types import pagers
3438
from google.cloud.compute_v1.types import compute
3539
from .transports.base import AcceleratorTypesTransport, DEFAULT_CLIENT_INFO
@@ -265,8 +269,15 @@ def __init__(
265269
client_options = client_options_lib.ClientOptions()
266270

267271
# Create SSL credentials for mutual TLS if needed.
268-
use_client_cert = bool(
269-
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
272+
if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in (
273+
"true",
274+
"false",
275+
):
276+
raise ValueError(
277+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
278+
)
279+
use_client_cert = (
280+
os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true"
270281
)
271282

272283
client_cert_source_func = None
@@ -328,21 +339,22 @@ def __init__(
328339
client_cert_source_for_mtls=client_cert_source_func,
329340
quota_project_id=client_options.quota_project_id,
330341
client_info=client_info,
342+
always_use_jwt_access=True,
331343
)
332344

333345
def aggregated_list(
334346
self,
335-
request: compute.AggregatedListAcceleratorTypesRequest = None,
347+
request: Union[compute.AggregatedListAcceleratorTypesRequest, dict] = None,
336348
*,
337349
project: str = None,
338-
retry: retries.Retry = gapic_v1.method.DEFAULT,
350+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
339351
timeout: float = None,
340352
metadata: Sequence[Tuple[str, str]] = (),
341353
) -> pagers.AggregatedListPager:
342354
r"""Retrieves an aggregated list of accelerator types.
343355
344356
Args:
345-
request (google.cloud.compute_v1.types.AggregatedListAcceleratorTypesRequest):
357+
request (Union[google.cloud.compute_v1.types.AggregatedListAcceleratorTypesRequest, dict]):
346358
The request object. A request message for
347359
AcceleratorTypes.AggregatedList. See the method
348360
description for details.
@@ -403,19 +415,19 @@ def aggregated_list(
403415

404416
def get(
405417
self,
406-
request: compute.GetAcceleratorTypeRequest = None,
418+
request: Union[compute.GetAcceleratorTypeRequest, dict] = None,
407419
*,
408420
project: str = None,
409421
zone: str = None,
410422
accelerator_type: str = None,
411-
retry: retries.Retry = gapic_v1.method.DEFAULT,
423+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
412424
timeout: float = None,
413425
metadata: Sequence[Tuple[str, str]] = (),
414426
) -> compute.AcceleratorType:
415427
r"""Returns the specified accelerator type.
416428
417429
Args:
418-
request (google.cloud.compute_v1.types.GetAcceleratorTypeRequest):
430+
request (Union[google.cloud.compute_v1.types.GetAcceleratorTypeRequest, dict]):
419431
The request object. A request message for
420432
AcceleratorTypes.Get. See the method description for
421433
details.
@@ -493,19 +505,19 @@ def get(
493505

494506
def list(
495507
self,
496-
request: compute.ListAcceleratorTypesRequest = None,
508+
request: Union[compute.ListAcceleratorTypesRequest, dict] = None,
497509
*,
498510
project: str = None,
499511
zone: str = None,
500-
retry: retries.Retry = gapic_v1.method.DEFAULT,
512+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
501513
timeout: float = None,
502514
metadata: Sequence[Tuple[str, str]] = (),
503515
) -> pagers.ListPager:
504516
r"""Retrieves a list of accelerator types that are
505517
available to the specified project.
506518
507519
Args:
508-
request (google.cloud.compute_v1.types.ListAcceleratorTypesRequest):
520+
request (Union[google.cloud.compute_v1.types.ListAcceleratorTypesRequest, dict]):
509521
The request object. A request message for
510522
AcceleratorTypes.List. See the method description for
511523
details.
@@ -574,6 +586,19 @@ def list(
574586
# Done; return the response.
575587
return response
576588

589+
def __enter__(self):
590+
return self
591+
592+
def __exit__(self, type, value, traceback):
593+
"""Releases underlying transport's resources.
594+
595+
.. warning::
596+
ONLY use as a context manager if the transport is NOT shared
597+
with other clients! Exiting the with block will CLOSE the transport
598+
and may cause errors in other clients!
599+
"""
600+
self.transport.close()
601+
577602

578603
try:
579604
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/pagers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#
1616
from typing import (
1717
Any,
18-
AsyncIterable,
18+
AsyncIterator,
1919
Awaitable,
2020
Callable,
21-
Iterable,
2221
Sequence,
2322
Tuple,
2423
Optional,
24+
Iterator,
2525
)
2626

2727
from google.cloud.compute_v1.types import compute
@@ -74,14 +74,14 @@ def __getattr__(self, name: str) -> Any:
7474
return getattr(self._response, name)
7575

7676
@property
77-
def pages(self) -> Iterable[compute.AcceleratorTypeAggregatedList]:
77+
def pages(self) -> Iterator[compute.AcceleratorTypeAggregatedList]:
7878
yield self._response
7979
while self._response.next_page_token:
8080
self._request.page_token = self._response.next_page_token
8181
self._response = self._method(self._request, metadata=self._metadata)
8282
yield self._response
8383

84-
def __iter__(self) -> Iterable[Tuple[str, compute.AcceleratorTypesScopedList]]:
84+
def __iter__(self) -> Iterator[Tuple[str, compute.AcceleratorTypesScopedList]]:
8585
for page in self.pages:
8686
yield from page.items.items()
8787

@@ -139,14 +139,14 @@ def __getattr__(self, name: str) -> Any:
139139
return getattr(self._response, name)
140140

141141
@property
142-
def pages(self) -> Iterable[compute.AcceleratorTypeList]:
142+
def pages(self) -> Iterator[compute.AcceleratorTypeList]:
143143
yield self._response
144144
while self._response.next_page_token:
145145
self._request.page_token = self._response.next_page_token
146146
self._response = self._method(self._request, metadata=self._metadata)
147147
yield self._response
148148

149-
def __iter__(self) -> Iterable[compute.AcceleratorType]:
149+
def __iter__(self) -> Iterator[compute.AcceleratorType]:
150150
for page in self.pages:
151151
yield from page.items
152152

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
#
1616
import abc
1717
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18-
import packaging.version
1918
import pkg_resources
20-
from requests import __version__ as requests_version
2119

2220
import google.auth # type: ignore
23-
import google.api_core # type: ignore
24-
from google.api_core import exceptions as core_exceptions # type: ignore
25-
from google.api_core import gapic_v1 # type: ignore
26-
from google.api_core import retry as retries # type: ignore
21+
import google.api_core
22+
from google.api_core import exceptions as core_exceptions
23+
from google.api_core import gapic_v1
24+
from google.api_core import retry as retries
2725
from google.auth import credentials as ga_credentials # type: ignore
2826
from google.oauth2 import service_account # type: ignore
2927

@@ -32,21 +30,10 @@
3230
try:
3331
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
3432
gapic_version=pkg_resources.get_distribution("google-cloud-compute",).version,
35-
grpc_version=None,
36-
rest_version=requests_version,
3733
)
3834
except pkg_resources.DistributionNotFound:
3935
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
4036

41-
try:
42-
# google.auth.__version__ was added in 1.26.0
43-
_GOOGLE_AUTH_VERSION = google.auth.__version__
44-
except AttributeError:
45-
try: # try pkg_resources if it is available
46-
_GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version
47-
except pkg_resources.DistributionNotFound: # pragma: NO COVER
48-
_GOOGLE_AUTH_VERSION = None
49-
5037

5138
class AcceleratorTypesTransport(abc.ABC):
5239
"""Abstract transport class for AcceleratorTypes."""
@@ -100,7 +87,7 @@ def __init__(
10087
host += ":443"
10188
self._host = host
10289

103-
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
90+
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
10491

10592
# Save the scopes.
10693
self._scopes = scopes
@@ -122,7 +109,7 @@ def __init__(
122109
**scopes_kwargs, quota_project_id=quota_project_id
123110
)
124111

125-
# If the credentials is service account credentials, then always try to use self signed JWT.
112+
# If the credentials are service account credentials, then always try to use self signed JWT.
126113
if (
127114
always_use_jwt_access
128115
and isinstance(credentials, service_account.Credentials)
@@ -133,29 +120,6 @@ def __init__(
133120
# Save the credentials.
134121
self._credentials = credentials
135122

136-
# TODO(busunkim): This method is in the base transport
137-
# to avoid duplicating code across the transport classes. These functions
138-
# should be deleted once the minimum required versions of google-auth is increased.
139-
140-
# TODO: Remove this function once google-auth >= 1.25.0 is required
141-
@classmethod
142-
def _get_scopes_kwargs(
143-
cls, host: str, scopes: Optional[Sequence[str]]
144-
) -> Dict[str, Optional[Sequence[str]]]:
145-
"""Returns scopes kwargs to pass to google-auth methods depending on the google-auth version"""
146-
147-
scopes_kwargs = {}
148-
149-
if _GOOGLE_AUTH_VERSION and (
150-
packaging.version.parse(_GOOGLE_AUTH_VERSION)
151-
>= packaging.version.parse("1.25.0")
152-
):
153-
scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES}
154-
else:
155-
scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES}
156-
157-
return scopes_kwargs
158-
159123
def _prep_wrapped_messages(self, client_info):
160124
# Precompute the wrapped methods.
161125
self._wrapped_methods = {
@@ -170,6 +134,15 @@ def _prep_wrapped_messages(self, client_info):
170134
),
171135
}
172136

137+
def close(self):
138+
"""Closes resources associated with the transport.
139+
140+
.. warning::
141+
Only call this method if the transport is NOT shared
142+
with other clients - this may cause errors in other clients!
143+
"""
144+
raise NotImplementedError()
145+
173146
@property
174147
def aggregated_list(
175148
self,

0 commit comments

Comments
 (0)