Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 060f00b

Browse files
fix: Drop usage of pkg_resources (#832)
* fix(deps): Require google-api-core >=1.34.0, >=2.11.0 fix: Drop usage of pkg_resources fix: Fix timeout default values docs(samples): Snippetgen should call await on the operation coroutine before calling result PiperOrigin-RevId: 493260409 Source-Link: googleapis/googleapis@fea4387 Source-Link: googleapis/googleapis-gen@387b734 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzg3YjczNDRjNzUyOWVlNDRiZTg0ZTYxM2IxOWE4MjA1MDhjNjEyYiJ9 * update replacements in owlbot.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * drop pkg_resources * update replacement in owlbot.py * fix(deps): require google-api-core>=1.34.0,>=2.11.0 * chore: update release-please-config.json * update replacement in owlbot.py * move replacement in owlbot.py Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent f3bf21d commit 060f00b

17 files changed

Lines changed: 132 additions & 164 deletions

File tree

.coveragerc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,3 @@ exclude_lines =
1111
pragma: NO COVER
1212
# Ignore debug-only repr
1313
def __repr__
14-
# Ignore pkg_resources exceptions.
15-
# This is added at the module level as a safeguard for if someone
16-
# generates the code and tries to run it without pip installing. This
17-
# makes it virtually impossible to test properly.
18-
except pkg_resources.DistributionNotFound

google/cloud/pubsub_v1/publisher/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import copy
1818
import logging
1919
import os
20-
import pkg_resources
2120
import threading
2221
import time
2322
import typing
@@ -35,15 +34,11 @@
3534
from google.cloud.pubsub_v1.publisher._sequencer import ordered_sequencer
3635
from google.cloud.pubsub_v1.publisher._sequencer import unordered_sequencer
3736
from google.cloud.pubsub_v1.publisher.flow_controller import FlowController
37+
from google.pubsub_v1 import gapic_version as package_version
3838
from google.pubsub_v1 import types as gapic_types
3939
from google.pubsub_v1.services.publisher import client as publisher_client
4040

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

4843
if typing.TYPE_CHECKING: # pragma: NO COVER
4944
from google.cloud import pubsub_v1

google/cloud/pubsub_v1/subscriber/client.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from __future__ import absolute_import
1616

1717
import os
18-
import pkg_resources
1918
import typing
2019
from typing import cast, Any, Callable, Optional, Sequence, Union
2120
import warnings
@@ -27,20 +26,15 @@
2726
from google.cloud.pubsub_v1.subscriber import futures
2827
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
2928
from google.pubsub_v1.services.subscriber import client as subscriber_client
29+
from google.pubsub_v1 import gapic_version as package_version
3030

3131
if typing.TYPE_CHECKING: # pragma: NO COVER
3232
from google.cloud.pubsub_v1 import subscriber
3333
from google.pubsub_v1.services.subscriber.transports.grpc import (
3434
SubscriberGrpcTransport,
3535
)
3636

37-
38-
try:
39-
__version__ = pkg_resources.get_distribution("google-cloud-pubsub").version
40-
except pkg_resources.DistributionNotFound:
41-
# Distribution might not be available if we are not running from within
42-
# a PIP package.
43-
__version__ = "0.0"
37+
__version__ = package_version.__version__
4438

4539

4640
class Client(subscriber_client.SubscriberClient):

google/pubsub_v1/gapic_version.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
__version__ = "2.13.11" # {x-release-please-version}

google/pubsub_v1/services/publisher/async_client.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
Type,
2828
Union,
2929
)
30-
import pkg_resources
30+
31+
from google.pubsub_v1 import gapic_version as package_version
3132

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

15601561

1561-
try:
1562-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1563-
client_library_version=pkg_resources.get_distribution(
1564-
"google-cloud-pubsub",
1565-
).version,
1566-
)
1567-
except pkg_resources.DistributionNotFound:
1568-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
1562+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1563+
client_library_version=package_version.__version__
1564+
)
15691565

15701566

15711567
__all__ = ("PublisherAsyncClient",)

google/pubsub_v1/services/publisher/client.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
Union,
3030
cast,
3131
)
32-
import pkg_resources
32+
33+
from google.pubsub_v1 import gapic_version as package_version
3334

3435
from google.api_core import client_options as client_options_lib
3536
from google.api_core import exceptions as core_exceptions
@@ -1753,14 +1754,9 @@ def test_iam_permissions(
17531754
return response
17541755

17551756

1756-
try:
1757-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1758-
client_library_version=pkg_resources.get_distribution(
1759-
"google-cloud-pubsub",
1760-
).version,
1761-
)
1762-
except pkg_resources.DistributionNotFound:
1763-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
1757+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1758+
client_library_version=package_version.__version__
1759+
)
17641760

17651761

17661762
__all__ = ("PublisherClient",)

google/pubsub_v1/services/publisher/transports/base.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#
1616
import abc
1717
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18-
import pkg_resources
18+
19+
from google.pubsub_v1 import gapic_version as package_version
1920

2021
import google.auth # type: ignore
2122
import google.api_core
@@ -30,14 +31,9 @@
3031
from google.protobuf import empty_pb2 # type: ignore
3132
from google.pubsub_v1.types import pubsub
3233

33-
try:
34-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
35-
client_library_version=pkg_resources.get_distribution(
36-
"google-cloud-pubsub",
37-
).version,
38-
)
39-
except pkg_resources.DistributionNotFound:
40-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
34+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
35+
client_library_version=package_version.__version__
36+
)
4137

4238

4339
class PublisherTransport(abc.ABC):

google/pubsub_v1/services/schema_service/async_client.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
Type,
2828
Union,
2929
)
30-
import pkg_resources
30+
31+
from google.pubsub_v1 import gapic_version as package_version
3132

3233
from google.api_core.client_options import ClientOptions
3334
from google.api_core import exceptions as core_exceptions
@@ -223,7 +224,7 @@ async def create_schema(
223224
schema: Optional[gp_schema.Schema] = None,
224225
schema_id: Optional[str] = None,
225226
retry: OptionalRetry = gapic_v1.method.DEFAULT,
226-
timeout: Optional[float] = None,
227+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
227228
metadata: Sequence[Tuple[str, str]] = (),
228229
) -> gp_schema.Schema:
229230
r"""Creates a schema.
@@ -351,7 +352,7 @@ async def get_schema(
351352
*,
352353
name: Optional[str] = None,
353354
retry: OptionalRetry = gapic_v1.method.DEFAULT,
354-
timeout: Optional[float] = None,
355+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
355356
metadata: Sequence[Tuple[str, str]] = (),
356357
) -> schema.Schema:
357358
r"""Gets a schema.
@@ -450,7 +451,7 @@ async def list_schemas(
450451
*,
451452
parent: Optional[str] = None,
452453
retry: OptionalRetry = gapic_v1.method.DEFAULT,
453-
timeout: Optional[float] = None,
454+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
454455
metadata: Sequence[Tuple[str, str]] = (),
455456
) -> pagers.ListSchemasAsyncPager:
456457
r"""Lists schemas in a project.
@@ -564,7 +565,7 @@ async def delete_schema(
564565
*,
565566
name: Optional[str] = None,
566567
retry: OptionalRetry = gapic_v1.method.DEFAULT,
567-
timeout: Optional[float] = None,
568+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
568569
metadata: Sequence[Tuple[str, str]] = (),
569570
) -> None:
570571
r"""Deletes a schema.
@@ -655,7 +656,7 @@ async def validate_schema(
655656
parent: Optional[str] = None,
656657
schema: Optional[gp_schema.Schema] = None,
657658
retry: OptionalRetry = gapic_v1.method.DEFAULT,
658-
timeout: Optional[float] = None,
659+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
659660
metadata: Sequence[Tuple[str, str]] = (),
660661
) -> gp_schema.ValidateSchemaResponse:
661662
r"""Validates a schema.
@@ -769,7 +770,7 @@ async def validate_message(
769770
request: Optional[Union[schema.ValidateMessageRequest, dict]] = None,
770771
*,
771772
retry: OptionalRetry = gapic_v1.method.DEFAULT,
772-
timeout: Optional[float] = None,
773+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
773774
metadata: Sequence[Tuple[str, str]] = (),
774775
) -> schema.ValidateMessageResponse:
775776
r"""Validates a message against a schema.
@@ -850,7 +851,7 @@ async def set_iam_policy(
850851
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
851852
*,
852853
retry: OptionalRetry = gapic_v1.method.DEFAULT,
853-
timeout: Optional[float] = None,
854+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
854855
metadata: Sequence[Tuple[str, str]] = (),
855856
) -> policy_pb2.Policy:
856857
r"""Sets the IAM access control policy on the specified function.
@@ -969,7 +970,7 @@ async def get_iam_policy(
969970
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
970971
*,
971972
retry: OptionalRetry = gapic_v1.method.DEFAULT,
972-
timeout: Optional[float] = None,
973+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
973974
metadata: Sequence[Tuple[str, str]] = (),
974975
) -> policy_pb2.Policy:
975976
r"""Gets the IAM access control policy for a function.
@@ -1090,7 +1091,7 @@ async def test_iam_permissions(
10901091
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
10911092
*,
10921093
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1093-
timeout: Optional[float] = None,
1094+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
10941095
metadata: Sequence[Tuple[str, str]] = (),
10951096
) -> iam_policy_pb2.TestIamPermissionsResponse:
10961097
r"""Tests the specified permissions against the IAM access control
@@ -1151,14 +1152,9 @@ async def __aexit__(self, exc_type, exc, tb):
11511152
await self.transport.close()
11521153

11531154

1154-
try:
1155-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1156-
client_library_version=pkg_resources.get_distribution(
1157-
"google-cloud-pubsub",
1158-
).version,
1159-
)
1160-
except pkg_resources.DistributionNotFound:
1161-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
1155+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1156+
client_library_version=package_version.__version__
1157+
)
11621158

11631159

11641160
__all__ = ("SchemaServiceAsyncClient",)

google/pubsub_v1/services/schema_service/client.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
Union,
3030
cast,
3131
)
32-
import pkg_resources
32+
33+
from google.pubsub_v1 import gapic_version as package_version
3334

3435
from google.api_core import client_options as client_options_lib
3536
from google.api_core import exceptions as core_exceptions
@@ -455,7 +456,7 @@ def create_schema(
455456
schema: Optional[gp_schema.Schema] = None,
456457
schema_id: Optional[str] = None,
457458
retry: OptionalRetry = gapic_v1.method.DEFAULT,
458-
timeout: Optional[float] = None,
459+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
459460
metadata: Sequence[Tuple[str, str]] = (),
460461
) -> gp_schema.Schema:
461462
r"""Creates a schema.
@@ -583,7 +584,7 @@ def get_schema(
583584
*,
584585
name: Optional[str] = None,
585586
retry: OptionalRetry = gapic_v1.method.DEFAULT,
586-
timeout: Optional[float] = None,
587+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
587588
metadata: Sequence[Tuple[str, str]] = (),
588589
) -> schema.Schema:
589590
r"""Gets a schema.
@@ -682,7 +683,7 @@ def list_schemas(
682683
*,
683684
parent: Optional[str] = None,
684685
retry: OptionalRetry = gapic_v1.method.DEFAULT,
685-
timeout: Optional[float] = None,
686+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
686687
metadata: Sequence[Tuple[str, str]] = (),
687688
) -> pagers.ListSchemasPager:
688689
r"""Lists schemas in a project.
@@ -796,7 +797,7 @@ def delete_schema(
796797
*,
797798
name: Optional[str] = None,
798799
retry: OptionalRetry = gapic_v1.method.DEFAULT,
799-
timeout: Optional[float] = None,
800+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
800801
metadata: Sequence[Tuple[str, str]] = (),
801802
) -> None:
802803
r"""Deletes a schema.
@@ -887,7 +888,7 @@ def validate_schema(
887888
parent: Optional[str] = None,
888889
schema: Optional[gp_schema.Schema] = None,
889890
retry: OptionalRetry = gapic_v1.method.DEFAULT,
890-
timeout: Optional[float] = None,
891+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
891892
metadata: Sequence[Tuple[str, str]] = (),
892893
) -> gp_schema.ValidateSchemaResponse:
893894
r"""Validates a schema.
@@ -1001,7 +1002,7 @@ def validate_message(
10011002
request: Optional[Union[schema.ValidateMessageRequest, dict]] = None,
10021003
*,
10031004
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1004-
timeout: Optional[float] = None,
1005+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
10051006
metadata: Sequence[Tuple[str, str]] = (),
10061007
) -> schema.ValidateMessageResponse:
10071008
r"""Validates a message against a schema.
@@ -1096,7 +1097,7 @@ def set_iam_policy(
10961097
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
10971098
*,
10981099
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1099-
timeout: Optional[float] = None,
1100+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
11001101
metadata: Sequence[Tuple[str, str]] = (),
11011102
) -> policy_pb2.Policy:
11021103
r"""Sets the IAM access control policy on the specified function.
@@ -1216,7 +1217,7 @@ def get_iam_policy(
12161217
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
12171218
*,
12181219
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1219-
timeout: Optional[float] = None,
1220+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
12201221
metadata: Sequence[Tuple[str, str]] = (),
12211222
) -> policy_pb2.Policy:
12221223
r"""Gets the IAM access control policy for a function.
@@ -1337,7 +1338,7 @@ def test_iam_permissions(
13371338
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
13381339
*,
13391340
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1340-
timeout: Optional[float] = None,
1341+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
13411342
metadata: Sequence[Tuple[str, str]] = (),
13421343
) -> iam_policy_pb2.TestIamPermissionsResponse:
13431344
r"""Tests the specified IAM permissions against the IAM access control
@@ -1392,14 +1393,9 @@ def test_iam_permissions(
13921393
return response
13931394

13941395

1395-
try:
1396-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1397-
client_library_version=pkg_resources.get_distribution(
1398-
"google-cloud-pubsub",
1399-
).version,
1400-
)
1401-
except pkg_resources.DistributionNotFound:
1402-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
1396+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1397+
client_library_version=package_version.__version__
1398+
)
14031399

14041400

14051401
__all__ = ("SchemaServiceClient",)

0 commit comments

Comments
 (0)