From cfccdf02a3b0e9d3cdf59a053766963da8f7da37 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 14:58:12 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#154) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency fix: fix extras_require typo in setup.py committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../services/budget_service/async_client.py | 34 +++--- .../services/budget_service/client.py | 12 ++- .../budget_service/transports/base.py | 35 +----- .../budget_service/transports/grpc_asyncio.py | 1 - .../billing/budgets_v1/types/budget_model.py | 18 ++++ .../services/budget_service/async_client.py | 34 +++--- .../services/budget_service/client.py | 12 ++- .../budget_service/transports/base.py | 35 +----- .../budget_service/transports/grpc_asyncio.py | 1 - .../budgets_v1beta1/types/budget_model.py | 18 ++++ setup.py | 5 +- testing/constraints-3.6.txt | 3 +- .../gapic/budgets_v1/test_budget_service.py | 100 ++---------------- .../budgets_v1beta1/test_budget_service.py | 100 ++---------------- 14 files changed, 109 insertions(+), 299 deletions(-) diff --git a/google/cloud/billing/budgets_v1/services/budget_service/async_client.py b/google/cloud/billing/budgets_v1/services/budget_service/async_client.py index 1164ee0..87d678b 100644 --- a/google/cloud/billing/budgets_v1/services/budget_service/async_client.py +++ b/google/cloud/billing/budgets_v1/services/budget_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.billing.budgets_v1.services.budget_service import pagers from google.cloud.billing.budgets_v1.types import budget_model from google.cloud.billing.budgets_v1.types import budget_service @@ -168,11 +170,11 @@ def __init__( async def create_budget( self, - request: budget_service.CreateBudgetRequest = None, + request: Union[budget_service.CreateBudgetRequest, dict] = None, *, parent: str = None, budget: budget_model.Budget = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -182,7 +184,7 @@ async def create_budget( create. Args: - request (:class:`google.cloud.billing.budgets_v1.types.CreateBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1.types.CreateBudgetRequest, dict]): The request object. Request for CreateBudget parent (:class:`str`): Required. The name of the billing account to create the @@ -257,11 +259,11 @@ async def create_budget( async def update_budget( self, - request: budget_service.UpdateBudgetRequest = None, + request: Union[budget_service.UpdateBudgetRequest, dict] = None, *, budget: budget_model.Budget = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -272,7 +274,7 @@ async def update_budget( changed by this method. Args: - request (:class:`google.cloud.billing.budgets_v1.types.UpdateBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1.types.UpdateBudgetRequest, dict]): The request object. Request for UpdateBudget budget (:class:`google.cloud.billing.budgets_v1.types.Budget`): Required. The updated budget object. @@ -365,10 +367,10 @@ async def update_budget( async def get_budget( self, - request: budget_service.GetBudgetRequest = None, + request: Union[budget_service.GetBudgetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -380,7 +382,7 @@ async def get_budget( Cloud Console. Args: - request (:class:`google.cloud.billing.budgets_v1.types.GetBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1.types.GetBudgetRequest, dict]): The request object. Request for GetBudget name (:class:`str`): Required. Name of budget to get. Values are of the form @@ -457,10 +459,10 @@ async def get_budget( async def list_budgets( self, - request: budget_service.ListBudgetsRequest = None, + request: Union[budget_service.ListBudgetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBudgetsAsyncPager: @@ -472,7 +474,7 @@ async def list_budgets( Cloud Console. Args: - request (:class:`google.cloud.billing.budgets_v1.types.ListBudgetsRequest`): + request (Union[google.cloud.billing.budgets_v1.types.ListBudgetsRequest, dict]): The request object. Request for ListBudgets parent (:class:`str`): Required. Name of billing account to list budgets under. @@ -551,10 +553,10 @@ async def list_budgets( async def delete_budget( self, - request: budget_service.DeleteBudgetRequest = None, + request: Union[budget_service.DeleteBudgetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -562,7 +564,7 @@ async def delete_budget( deleted. Args: - request (:class:`google.cloud.billing.budgets_v1.types.DeleteBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1.types.DeleteBudgetRequest, dict]): The request object. Request for DeleteBudget name (:class:`str`): Required. Name of the budget to delete. Values are of diff --git a/google/cloud/billing/budgets_v1/services/budget_service/client.py b/google/cloud/billing/budgets_v1/services/budget_service/client.py index 84a5634..5938b89 100644 --- a/google/cloud/billing/budgets_v1/services/budget_service/client.py +++ b/google/cloud/billing/budgets_v1/services/budget_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.billing.budgets_v1.services.budget_service import pagers from google.cloud.billing.budgets_v1.types import budget_model from google.cloud.billing.budgets_v1.types import budget_service @@ -355,7 +357,7 @@ def create_budget( *, parent: str = None, budget: budget_model.Budget = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -444,7 +446,7 @@ def update_budget( *, budget: budget_model.Budget = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -541,7 +543,7 @@ def get_budget( request: Union[budget_service.GetBudgetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -623,7 +625,7 @@ def list_budgets( request: Union[budget_service.ListBudgetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBudgetsPager: @@ -707,7 +709,7 @@ def delete_budget( request: Union[budget_service.DeleteBudgetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: diff --git a/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py b/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py index 5b41d40..3271a9c 100644 --- a/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py +++ b/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -39,15 +38,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class BudgetServiceTransport(abc.ABC): """Abstract transport class for BudgetService.""" @@ -100,7 +90,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -133,29 +123,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py b/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py index 5882e3b..be920a0 100644 --- a/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py +++ b/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/cloud/billing/budgets_v1/types/budget_model.py b/google/cloud/billing/budgets_v1/types/budget_model.py index 8e899f0..d2a24ff 100644 --- a/google/cloud/billing/budgets_v1/types/budget_model.py +++ b/google/cloud/billing/budgets_v1/types/budget_model.py @@ -102,6 +102,13 @@ class Budget(proto.Message): class BudgetAmount(proto.Message): r"""The budgeted amount for each usage period. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: specified_amount (google.type.money_pb2.Money): A specified amount to use as the budget. ``currency_code`` @@ -110,6 +117,7 @@ class BudgetAmount(proto.Message): updating a budget, it must match the currency_code of the existing budget. The ``currency_code`` is provided on output. + This field is a member of `oneof`_ ``budget_amount``. last_period_amount (google.cloud.billing.budgets_v1.types.LastPeriodAmount): Use the last period's actual spend as the budget for the present period. LastPeriodAmount can only be set when the @@ -117,6 +125,7 @@ class BudgetAmount(proto.Message): [Filter.calendar_period][google.cloud.billing.budgets.v1.Filter.calendar_period]. It cannot be set in combination with [Filter.custom_period][google.cloud.billing.budgets.v1.Filter.custom_period]. + This field is a member of `oneof`_ ``budget_amount``. """ specified_amount = proto.Field( @@ -226,6 +235,13 @@ class Filter(proto.Message): r"""A filter for a budget, limiting the scope of the cost to calculate. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: projects (Sequence[str]): Optional. A set of projects of the form @@ -282,11 +298,13 @@ class Filter(proto.Message): After that, it will track usage from July 1 to September 30 when the current calendar month is July, August, September, so on. + This field is a member of `oneof`_ ``usage_period``. custom_period (google.cloud.billing.budgets_v1.types.CustomPeriod): Optional. Specifies to track usage from any start date (required) to any end date (optional). This time period is static, it does not recur. + This field is a member of `oneof`_ ``usage_period``. """ class CreditTypesTreatment(proto.Enum): diff --git a/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py b/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py index 34935cd..558b233 100644 --- a/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py +++ b/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.billing.budgets_v1beta1.services.budget_service import pagers from google.cloud.billing.budgets_v1beta1.types import budget_model from google.cloud.billing.budgets_v1beta1.types import budget_service @@ -167,9 +169,9 @@ def __init__( async def create_budget( self, - request: budget_service.CreateBudgetRequest = None, + request: Union[budget_service.CreateBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -179,7 +181,7 @@ async def create_budget( number of budgets you can create. Args: - request (:class:`google.cloud.billing.budgets_v1beta1.types.CreateBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1beta1.types.CreateBudgetRequest, dict]): The request object. Request for CreateBudget retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -225,9 +227,9 @@ async def create_budget( async def update_budget( self, - request: budget_service.UpdateBudgetRequest = None, + request: Union[budget_service.UpdateBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -238,7 +240,7 @@ async def update_budget( changed by this method. Args: - request (:class:`google.cloud.billing.budgets_v1beta1.types.UpdateBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1beta1.types.UpdateBudgetRequest, dict]): The request object. Request for UpdateBudget retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -296,9 +298,9 @@ async def update_budget( async def get_budget( self, - request: budget_service.GetBudgetRequest = None, + request: Union[budget_service.GetBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -310,7 +312,7 @@ async def get_budget( Cloud Console. Args: - request (:class:`google.cloud.billing.budgets_v1beta1.types.GetBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1beta1.types.GetBudgetRequest, dict]): The request object. Request for GetBudget retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -366,9 +368,9 @@ async def get_budget( async def list_budgets( self, - request: budget_service.ListBudgetsRequest = None, + request: Union[budget_service.ListBudgetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBudgetsAsyncPager: @@ -380,7 +382,7 @@ async def list_budgets( Cloud Console. Args: - request (:class:`google.cloud.billing.budgets_v1beta1.types.ListBudgetsRequest`): + request (Union[google.cloud.billing.budgets_v1beta1.types.ListBudgetsRequest, dict]): The request object. Request for ListBudgets retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -437,9 +439,9 @@ async def list_budgets( async def delete_budget( self, - request: budget_service.DeleteBudgetRequest = None, + request: Union[budget_service.DeleteBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -447,7 +449,7 @@ async def delete_budget( deleted. Args: - request (:class:`google.cloud.billing.budgets_v1beta1.types.DeleteBudgetRequest`): + request (Union[google.cloud.billing.budgets_v1beta1.types.DeleteBudgetRequest, dict]): The request object. Request for DeleteBudget retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. diff --git a/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py b/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py index cc3053d..0dc1d5f 100644 --- a/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py +++ b/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.billing.budgets_v1beta1.services.budget_service import pagers from google.cloud.billing.budgets_v1beta1.types import budget_model from google.cloud.billing.budgets_v1beta1.types import budget_service @@ -352,7 +354,7 @@ def create_budget( self, request: Union[budget_service.CreateBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -411,7 +413,7 @@ def update_budget( self, request: Union[budget_service.UpdateBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -473,7 +475,7 @@ def get_budget( self, request: Union[budget_service.GetBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> budget_model.Budget: @@ -534,7 +536,7 @@ def list_budgets( self, request: Union[budget_service.ListBudgetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBudgetsPager: @@ -596,7 +598,7 @@ def delete_budget( self, request: Union[budget_service.DeleteBudgetRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: diff --git a/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py b/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py index a358aff..5f62618 100644 --- a/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py +++ b/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -39,15 +38,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class BudgetServiceTransport(abc.ABC): """Abstract transport class for BudgetService.""" @@ -100,7 +90,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -133,29 +123,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py b/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py index 674e5a9..92b432b 100644 --- a/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py +++ b/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/cloud/billing/budgets_v1beta1/types/budget_model.py b/google/cloud/billing/budgets_v1beta1/types/budget_model.py index a68f880..cd943cc 100644 --- a/google/cloud/billing/budgets_v1beta1/types/budget_model.py +++ b/google/cloud/billing/budgets_v1beta1/types/budget_model.py @@ -100,6 +100,13 @@ class Budget(proto.Message): class BudgetAmount(proto.Message): r"""The budgeted amount for each usage period. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: specified_amount (google.type.money_pb2.Money): A specified amount to use as the budget. ``currency_code`` @@ -108,6 +115,7 @@ class BudgetAmount(proto.Message): updating a budget, it must match the currency_code of the existing budget. The ``currency_code`` is provided on output. + This field is a member of `oneof`_ ``budget_amount``. last_period_amount (google.cloud.billing.budgets_v1beta1.types.LastPeriodAmount): Use the last period's actual spend as the budget for the present period. LastPeriodAmount can only be set when the @@ -115,6 +123,7 @@ class BudgetAmount(proto.Message): [Filter.calendar_period][google.cloud.billing.budgets.v1beta1.Filter.calendar_period]. It cannot be set in combination with [Filter.custom_period][google.cloud.billing.budgets.v1beta1.Filter.custom_period]. + This field is a member of `oneof`_ ``budget_amount``. """ specified_amount = proto.Field( @@ -224,6 +233,13 @@ class Filter(proto.Message): r"""A filter for a budget, limiting the scope of the cost to calculate. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: projects (Sequence[str]): Optional. A set of projects of the form @@ -280,11 +296,13 @@ class Filter(proto.Message): After that, it will track usage from July 1 to September 30 when the current calendar month is July, August, September, so on. + This field is a member of `oneof`_ ``usage_period``. custom_period (google.cloud.billing.budgets_v1beta1.types.CustomPeriod): Optional. Specifies to track usage from any start date (required) to any end date (optional). This time period is static, it does not recur. + This field is a member of `oneof`_ ``usage_period``. """ class CreditTypesTreatment(proto.Enum): diff --git a/setup.py b/setup.py index dcdd4ac..e2eb1c0 100644 --- a/setup.py +++ b/setup.py @@ -28,9 +28,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.10.0", - "packaging >= 14.3", ] extras = {"libcst": "libcst >= 0.2.5"} @@ -81,7 +80,7 @@ scripts=["scripts/fixup_budgets_v1beta1_keywords.py"], namespace_packages=namespaces, install_requires=dependencies, - extras_requires=extras, + extras_require=extras, include_package_data=True, zip_safe=False, ) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 9edacb4..4af7e2d 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,7 +5,6 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.10.0 libcst==0.2.5 -packaging==14.3 diff --git a/tests/unit/gapic/budgets_v1/test_budget_service.py b/tests/unit/gapic/budgets_v1/test_budget_service.py index 2a1b30e..0e63781 100644 --- a/tests/unit/gapic/budgets_v1/test_budget_service.py +++ b/tests/unit/gapic/budgets_v1/test_budget_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -38,9 +37,6 @@ from google.cloud.billing.budgets_v1.services.budget_service import BudgetServiceClient from google.cloud.billing.budgets_v1.services.budget_service import pagers from google.cloud.billing.budgets_v1.services.budget_service import transports -from google.cloud.billing.budgets_v1.services.budget_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.billing.budgets_v1.types import budget_model from google.cloud.billing.budgets_v1.types import budget_service from google.oauth2 import service_account @@ -51,20 +47,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -221,7 +203,7 @@ def test_budget_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -238,7 +220,7 @@ def test_budget_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -255,7 +237,7 @@ def test_budget_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -284,7 +266,7 @@ def test_budget_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -343,7 +325,7 @@ def test_budget_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -385,7 +367,7 @@ def test_budget_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -407,7 +389,7 @@ def test_budget_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -438,7 +420,7 @@ def test_budget_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -469,7 +451,7 @@ def test_budget_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1789,7 +1771,6 @@ def test_budget_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_budget_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1813,29 +1794,6 @@ def test_budget_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_budget_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.billing.budgets_v1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.BudgetServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-billing", - "https://www.googleapis.com/auth/cloud-platform", - ), - quota_project_id="octopus", - ) - - def test_budget_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1847,7 +1805,6 @@ def test_budget_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_budget_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1863,21 +1820,6 @@ def test_budget_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_budget_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - BudgetServiceClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-billing", - "https://www.googleapis.com/auth/cloud-platform", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1885,7 +1827,6 @@ def test_budget_service_auth_adc_old_google_auth(): transports.BudgetServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_budget_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1902,29 +1843,6 @@ def test_budget_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.BudgetServiceGrpcTransport, - transports.BudgetServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_budget_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-billing", - "https://www.googleapis.com/auth/cloud-platform", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/budgets_v1beta1/test_budget_service.py b/tests/unit/gapic/budgets_v1beta1/test_budget_service.py index 625c6cc..feee982 100644 --- a/tests/unit/gapic/budgets_v1beta1/test_budget_service.py +++ b/tests/unit/gapic/budgets_v1beta1/test_budget_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.billing.budgets_v1beta1.services.budget_service import pagers from google.cloud.billing.budgets_v1beta1.services.budget_service import transports -from google.cloud.billing.budgets_v1beta1.services.budget_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.billing.budgets_v1beta1.types import budget_model from google.cloud.billing.budgets_v1beta1.types import budget_service from google.oauth2 import service_account @@ -53,20 +49,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -223,7 +205,7 @@ def test_budget_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -240,7 +222,7 @@ def test_budget_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -257,7 +239,7 @@ def test_budget_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -286,7 +268,7 @@ def test_budget_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -345,7 +327,7 @@ def test_budget_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -387,7 +369,7 @@ def test_budget_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -409,7 +391,7 @@ def test_budget_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -440,7 +422,7 @@ def test_budget_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -471,7 +453,7 @@ def test_budget_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1437,7 +1419,6 @@ def test_budget_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_budget_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1461,29 +1442,6 @@ def test_budget_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_budget_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.billing.budgets_v1beta1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.BudgetServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-billing", - "https://www.googleapis.com/auth/cloud-platform", - ), - quota_project_id="octopus", - ) - - def test_budget_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1495,7 +1453,6 @@ def test_budget_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_budget_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1511,21 +1468,6 @@ def test_budget_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_budget_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - BudgetServiceClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-billing", - "https://www.googleapis.com/auth/cloud-platform", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1533,7 +1475,6 @@ def test_budget_service_auth_adc_old_google_auth(): transports.BudgetServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_budget_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1550,29 +1491,6 @@ def test_budget_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.BudgetServiceGrpcTransport, - transports.BudgetServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_budget_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-billing", - "https://www.googleapis.com/auth/cloud-platform", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [