Skip to content

Commit bb819c2

Browse files
authored
fix: drop usage of pkg_resources (#1471)
* fix: drop pkg_resources * fix typo
1 parent 951818a commit bb819c2

File tree

48 files changed

+174
-258
lines changed

Some content is hidden

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

48 files changed

+174
-258
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends '_base.py.j2' %}
22
{% block content %}
33

4-
__version__ = "0.1.0"
4+
__version__ = "0.1.0" # {x-release-please-version}
55
{% endblock %}

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ from collections import OrderedDict
66
import functools
77
import re
88
from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, {% if service.any_server_streaming %}AsyncIterable, Awaitable, {% endif %}{% if service.any_client_streaming %}AsyncIterator, {% endif %}Sequence, Tuple, Type, Union
9-
import pkg_resources
109
{% if service.any_deprecated %}
1110
import warnings
1211
{% endif %}
1312

13+
{% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.versioned_module_name %}
14+
from {{package_path}} import gapic_version as package_version
15+
1416
from google.api_core.client_options import ClientOptions
1517
from google.api_core import exceptions as core_exceptions
1618
from google.api_core import gapic_v1
@@ -676,14 +678,7 @@ class {{ service.async_client_name }}:
676678
async def __aexit__(self, exc_type, exc, tb):
677679
await self.transport.close()
678680

679-
try:
680-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
681-
gapic_version=pkg_resources.get_distribution(
682-
"{{ api.naming.warehouse_package_name }}",
683-
).version,
684-
)
685-
except pkg_resources.DistributionNotFound:
686-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
681+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
687682

688683

689684
__all__ = (

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import functools
1010
import os
1111
import re
1212
from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union, cast
13-
import pkg_resources
1413
{% if service.any_deprecated %}
1514
import warnings
1615
{% endif %}
1716

17+
{% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.versioned_module_name %}
18+
from {{package_path}} import gapic_version as package_version
19+
1820
from google.api_core import client_options as client_options_lib
1921
from google.api_core import exceptions as core_exceptions
2022
{% if service.any_extended_operations_methods %}
@@ -685,14 +687,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
685687
# Done; return the response.
686688
return response
687689
{% endif %}
688-
try:
689-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
690-
gapic_version=pkg_resources.get_distribution(
691-
"{{ api.naming.warehouse_package_name }}",
692-
).version,
693-
)
694-
except pkg_resources.DistributionNotFound:
695-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
690+
691+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
696692

697693

698694
__all__ = (

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import abc
66
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
7-
import pkg_resources
7+
8+
{% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.versioned_module_name %}
9+
from {{package_path}} import gapic_version as package_version
810

911
import google.auth # type: ignore
1012
import google.api_core
@@ -39,14 +41,7 @@ from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + ser
3941
{% endfor %}
4042
{% endfilter %}
4143

42-
try:
43-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
44-
gapic_version=pkg_resources.get_distribution(
45-
'{{ api.naming.warehouse_package_name }}',
46-
).version,
47-
)
48-
except pkg_resources.DistributionNotFound:
49-
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
44+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
5045

5146

5247
class {{ service.name }}Transport(abc.ABC):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends '_base.py.j2' %}
2+
{% block content %}
3+
4+
__version__ = "0.1.0" # {x-release-please-version}
5+
{% endblock %}

packages/gapic-generator/gapic/templates/.coveragerc.j2

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

packages/gapic-generator/gapic/templates/noxfile.py.j2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def mypy(session):
7575
"""Run the type checker."""
7676
session.install(
7777
'mypy',
78-
'types-pkg_resources',
7978
'types-requests',
8079
'types-protobuf'
8180
)

packages/gapic-generator/tests/integration/goldens/asset/.coveragerc

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

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.1.0"
16+
__version__ = "0.1.0" # {x-release-please-version}
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__ = "0.1.0" # {x-release-please-version}

0 commit comments

Comments
 (0)