Skip to content

Commit 42b3f01

Browse files
authored
feat: add support for google.cloud.ndb.__version__ (#929)
1 parent 182fe4e commit 42b3f01

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

google/cloud/ndb/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
.. autodata:: __all__
2222
"""
2323

24-
from pkg_resources import get_distribution
24+
from google.cloud.ndb import version
2525

26-
__version__ = get_distribution("google-cloud-ndb").version
26+
__version__ = version.__version__
2727

2828
from google.cloud.ndb.client import Client
2929
from google.cloud.ndb.context import AutoBatcher
@@ -131,6 +131,7 @@
131131
from google.cloud.ndb._transaction import non_transactional
132132

133133
__all__ = [
134+
"__version__",
134135
"AutoBatcher",
135136
"Client",
136137
"Context",

google/cloud/ndb/version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 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.2.2"

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414

1515
import io
1616
import os
17+
import re
1718

1819
import setuptools
1920

2021

22+
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
23+
24+
version = None
25+
26+
with open(os.path.join(PACKAGE_ROOT, "google/cloud/ndb/version.py")) as fp:
27+
version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read())
28+
assert len(version_candidates) == 1
29+
version = version_candidates[0]
30+
2131
def main():
2232
package_root = os.path.abspath(os.path.dirname(__file__))
2333
readme_filename = os.path.join(package_root, "README.md")
@@ -36,7 +46,7 @@ def main():
3646

3747
setuptools.setup(
3848
name="google-cloud-ndb",
39-
version = "2.2.2",
49+
version = version,
4050
description="NDB library for Google Cloud Datastore",
4151
long_description=readme,
4252
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)