Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Drop usage of pkg_resources #832

Merged
merged 9 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@ exclude_lines =
pragma: NO COVER
# Ignore debug-only repr
def __repr__
# Ignore pkg_resources exceptions.
# This is added at the module level as a safeguard for if someone
# generates the code and tries to run it without pip installing. This
# makes it virtually impossible to test properly.
except pkg_resources.DistributionNotFound
9 changes: 2 additions & 7 deletions google/cloud/pubsub_v1/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import copy
import logging
import os
import pkg_resources
import threading
import time
import typing
Expand All @@ -35,15 +34,11 @@
from google.cloud.pubsub_v1.publisher._sequencer import ordered_sequencer
from google.cloud.pubsub_v1.publisher._sequencer import unordered_sequencer
from google.cloud.pubsub_v1.publisher.flow_controller import FlowController
from google.pubsub_v1 import gapic_version as package_version
from google.pubsub_v1 import types as gapic_types
from google.pubsub_v1.services.publisher import client as publisher_client

try:
__version__ = pkg_resources.get_distribution("google-cloud-pubsub").version
except pkg_resources.DistributionNotFound:
# Distribution might not be available if we are not running from within a
# PIP package.
__version__ = "0.0"
__version__ = package_version.__version__

if typing.TYPE_CHECKING: # pragma: NO COVER
from google.cloud import pubsub_v1
Expand Down
10 changes: 2 additions & 8 deletions google/cloud/pubsub_v1/subscriber/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from __future__ import absolute_import

import os
import pkg_resources
import typing
from typing import cast, Any, Callable, Optional, Sequence, Union
import warnings
Expand All @@ -27,20 +26,15 @@
from google.cloud.pubsub_v1.subscriber import futures
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
from google.pubsub_v1.services.subscriber import client as subscriber_client
from google.pubsub_v1 import gapic_version as package_version

if typing.TYPE_CHECKING: # pragma: NO COVER
from google.cloud.pubsub_v1 import subscriber
from google.pubsub_v1.services.subscriber.transports.grpc import (
SubscriberGrpcTransport,
)


try:
__version__ = pkg_resources.get_distribution("google-cloud-pubsub").version
except pkg_resources.DistributionNotFound:
# Distribution might not be available if we are not running from within
# a PIP package.
__version__ = "0.0"
__version__ = package_version.__version__


class Client(subscriber_client.SubscriberClient):
Expand Down
16 changes: 16 additions & 0 deletions google/pubsub_v1/gapic_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.13.11" # {x-release-please-version}
14 changes: 5 additions & 9 deletions google/pubsub_v1/services/publisher/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
Type,
Union,
)
import pkg_resources

from google.pubsub_v1 import gapic_version as package_version

from google.api_core.client_options import ClientOptions
from google.api_core import exceptions as core_exceptions
Expand Down Expand Up @@ -1558,14 +1559,9 @@ async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=pkg_resources.get_distribution(
"google-cloud-pubsub",
).version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=package_version.__version__
)


__all__ = ("PublisherAsyncClient",)
14 changes: 5 additions & 9 deletions google/pubsub_v1/services/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
Union,
cast,
)
import pkg_resources

from google.pubsub_v1 import gapic_version as package_version

from google.api_core import client_options as client_options_lib
from google.api_core import exceptions as core_exceptions
Expand Down Expand Up @@ -1753,14 +1754,9 @@ def test_iam_permissions(
return response


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=pkg_resources.get_distribution(
"google-cloud-pubsub",
).version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=package_version.__version__
)


__all__ = ("PublisherClient",)
14 changes: 5 additions & 9 deletions google/pubsub_v1/services/publisher/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#
import abc
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
import pkg_resources

from google.pubsub_v1 import gapic_version as package_version

import google.auth # type: ignore
import google.api_core
Expand All @@ -30,14 +31,9 @@
from google.protobuf import empty_pb2 # type: ignore
from google.pubsub_v1.types import pubsub

try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=pkg_resources.get_distribution(
"google-cloud-pubsub",
).version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=package_version.__version__
)


class PublisherTransport(abc.ABC):
Expand Down
32 changes: 14 additions & 18 deletions google/pubsub_v1/services/schema_service/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
Type,
Union,
)
import pkg_resources

from google.pubsub_v1 import gapic_version as package_version

from google.api_core.client_options import ClientOptions
from google.api_core import exceptions as core_exceptions
Expand Down Expand Up @@ -223,7 +224,7 @@ async def create_schema(
schema: Optional[gp_schema.Schema] = None,
schema_id: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> gp_schema.Schema:
r"""Creates a schema.
Expand Down Expand Up @@ -351,7 +352,7 @@ async def get_schema(
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> schema.Schema:
r"""Gets a schema.
Expand Down Expand Up @@ -450,7 +451,7 @@ async def list_schemas(
*,
parent: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListSchemasAsyncPager:
r"""Lists schemas in a project.
Expand Down Expand Up @@ -564,7 +565,7 @@ async def delete_schema(
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
r"""Deletes a schema.
Expand Down Expand Up @@ -655,7 +656,7 @@ async def validate_schema(
parent: Optional[str] = None,
schema: Optional[gp_schema.Schema] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> gp_schema.ValidateSchemaResponse:
r"""Validates a schema.
Expand Down Expand Up @@ -769,7 +770,7 @@ async def validate_message(
request: Optional[Union[schema.ValidateMessageRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> schema.ValidateMessageResponse:
r"""Validates a message against a schema.
Expand Down Expand Up @@ -850,7 +851,7 @@ async def set_iam_policy(
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
r"""Sets the IAM access control policy on the specified function.
Expand Down Expand Up @@ -969,7 +970,7 @@ async def get_iam_policy(
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
r"""Gets the IAM access control policy for a function.
Expand Down Expand Up @@ -1090,7 +1091,7 @@ async def test_iam_permissions(
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> iam_policy_pb2.TestIamPermissionsResponse:
r"""Tests the specified permissions against the IAM access control
Expand Down Expand Up @@ -1151,14 +1152,9 @@ async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=pkg_resources.get_distribution(
"google-cloud-pubsub",
).version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=package_version.__version__
)


__all__ = ("SchemaServiceAsyncClient",)
32 changes: 14 additions & 18 deletions google/pubsub_v1/services/schema_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
Union,
cast,
)
import pkg_resources

from google.pubsub_v1 import gapic_version as package_version

from google.api_core import client_options as client_options_lib
from google.api_core import exceptions as core_exceptions
Expand Down Expand Up @@ -455,7 +456,7 @@ def create_schema(
schema: Optional[gp_schema.Schema] = None,
schema_id: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> gp_schema.Schema:
r"""Creates a schema.
Expand Down Expand Up @@ -583,7 +584,7 @@ def get_schema(
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> schema.Schema:
r"""Gets a schema.
Expand Down Expand Up @@ -682,7 +683,7 @@ def list_schemas(
*,
parent: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListSchemasPager:
r"""Lists schemas in a project.
Expand Down Expand Up @@ -796,7 +797,7 @@ def delete_schema(
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
r"""Deletes a schema.
Expand Down Expand Up @@ -887,7 +888,7 @@ def validate_schema(
parent: Optional[str] = None,
schema: Optional[gp_schema.Schema] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> gp_schema.ValidateSchemaResponse:
r"""Validates a schema.
Expand Down Expand Up @@ -1001,7 +1002,7 @@ def validate_message(
request: Optional[Union[schema.ValidateMessageRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> schema.ValidateMessageResponse:
r"""Validates a message against a schema.
Expand Down Expand Up @@ -1096,7 +1097,7 @@ def set_iam_policy(
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
r"""Sets the IAM access control policy on the specified function.
Expand Down Expand Up @@ -1216,7 +1217,7 @@ def get_iam_policy(
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
r"""Gets the IAM access control policy for a function.
Expand Down Expand Up @@ -1337,7 +1338,7 @@ def test_iam_permissions(
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Optional[float] = None,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> iam_policy_pb2.TestIamPermissionsResponse:
r"""Tests the specified IAM permissions against the IAM access control
Expand Down Expand Up @@ -1392,14 +1393,9 @@ def test_iam_permissions(
return response


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=pkg_resources.get_distribution(
"google-cloud-pubsub",
).version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
client_library_version=package_version.__version__
)


__all__ = ("SchemaServiceClient",)
Loading