Skip to content

Commit a2cbc32

Browse files
authored
feat: expose library version at google.auth.__version (#683)
Move the version from `setup.py` to `google/auth/version.py`. Same as googleapis/python-api-core#80. (see googleapis/python-api-core#27 for motivation). This is option 3 in https://packaging.python.org/guides/single-sourcing-package-version/. This unblocks a version check I'd like to add in googleapis/python-api-core#134. Usage: ```py >>> import google.auth >>> google.auth.__version__ '1.25.0' ```
1 parent e87b1ec commit a2cbc32

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

google/auth/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616

1717
import logging
1818

19+
from google.auth import version as google_auth_version
1920
from google.auth._default import default, load_credentials_from_file
2021

22+
23+
__version__ = google_auth_version.__version__
24+
25+
2126
__all__ = ["default", "load_credentials_from_file"]
2227

2328
# Set default logging handler to avoid "No handler found" warnings.

google/auth/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__ = "1.27.1"

setup.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import io
16+
import os
1617

1718
from setuptools import find_packages
1819
from setuptools import setup
@@ -37,7 +38,12 @@
3738
with io.open("README.rst", "r") as fh:
3839
long_description = fh.read()
3940

40-
version = "1.27.1"
41+
package_root = os.path.abspath(os.path.dirname(__file__))
42+
43+
version = {}
44+
with open(os.path.join(package_root, "google/auth/version.py")) as fp:
45+
exec(fp.read(), version)
46+
version = version["__version__"]
4147

4248
setup(
4349
name="google-auth",

0 commit comments

Comments
 (0)