Skip to content

Commit 83db1d7

Browse files
joinsionparthea
andauthored
feat: expose library version at googleapiclient.__version__ (#1623)
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent b8de30d commit 83db1d7

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

googleapiclient/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
import json
2727
import logging
2828
import platform
29-
import pkg_resources
3029
import urllib
3130

31+
from googleapiclient import version as googleapiclient_version
3232
from googleapiclient.errors import HttpError
3333

34-
_LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
34+
_LIBRARY_VERSION = googleapiclient_version.__version__
3535
_PY_VERSION = platform.python_version()
3636

3737
LOGGER = logging.getLogger(__name__)

googleapiclient/version.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
__version__ = "2.33.0"

setup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@
5151
with io.open(readme_filename, encoding="utf-8") as readme_file:
5252
readme = readme_file.read()
5353

54-
version = "2.33.0"
54+
package_root = os.path.abspath(os.path.dirname(__file__))
55+
56+
version = {}
57+
with open(os.path.join(package_root, "googleapiclient/version.py")) as fp:
58+
exec(fp.read(), version)
59+
version = version["__version__"]
5560

5661
setup(
5762
name="google-api-python-client",

tests/test_json_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
import io
2626
import httplib2
2727
import json
28-
import pkg_resources
2928
import platform
3029
import unittest
3130
import urllib
3231

3332
import googleapiclient.model
3433

34+
from googleapiclient import version as googleapiclient_version
3535
from googleapiclient.errors import HttpError
3636
from googleapiclient.model import JsonModel
3737

38-
_LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
38+
_LIBRARY_VERSION = googleapiclient_version.__version__
3939
CSV_TEXT_MOCK = 'column1,column2,column3\nstring1,1.2,string2'
4040

4141

0 commit comments

Comments
 (0)