Skip to content

Commit 942e281

Browse files
authored
PYTHON-1889 Single-source the version tuple/string (#1079)
1 parent 1c9193f commit 942e281

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

RELEASE.rst

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,15 @@ Doing a Release
4343
3. Add release notes to doc/changelog.rst. Generally just summarize/clarify
4444
the git log, but you might add some more long form notes for big changes.
4545

46-
4. Search and replace the "devN" version number w/ the new version number (see
47-
note above in `Versioning`_).
46+
4. Make sure version number is updated in ``pymongo/_version.py``
4847

49-
5. Make sure version number is updated in setup.py and pymongo/__init__.py
48+
5. Commit with a BUMP version_number message, eg ``git commit -m 'BUMP 3.11.0'``.
5049

51-
6. Commit with a BUMP version_number message, eg ``git commit -m 'BUMP 3.11.0'``.
50+
6. Tag w/ version_number, eg, ``git tag -a '3.11.0' -m 'BUMP 3.11.0' <COMMIT>``.
5251

53-
7. Tag w/ version_number, eg, ``git tag -a '3.11.0' -m '3.11.0' <COMMIT>``.
52+
7. Push commit / tag, eg ``git push && git push --tags``.
5453

55-
8. Push commit / tag, eg ``git push && git push --tags``.
56-
57-
9. Pushing a tag will trigger a release process in Evergreen which builds
54+
8. Pushing a tag will trigger a release process in Evergreen which builds
5855
wheels for manylinux, macOS, and Windows. Wait for the "release-combine"
5956
task to complete and then download the "Release files all" archive. See:
6057
https://evergreen.mongodb.com/waterfall/mongo-python-driver?bv_filter=release
@@ -70,27 +67,27 @@ Doing a Release
7067
...
7168
pymongo-<version>.tar.gz
7269

73-
10. Upload all the release packages to PyPI with twine::
70+
9. Upload all the release packages to PyPI with twine::
7471

7572
$ python3 -m twine upload path/to/archive/*
7673

77-
11. Make sure the new version appears on https://pymongo.readthedocs.io/. If the
74+
10. Make sure the new version appears on https://pymongo.readthedocs.io/. If the
7875
new version does not show up automatically, trigger a rebuild of "latest":
7976
https://readthedocs.org/projects/pymongo/builds/
8077

81-
12. Bump the version number to <next version>.dev0 in setup.py/__init__.py,
78+
11. Bump the version number to <next version>.dev0 in ``pymongo/_version.py``,
8279
commit, push.
8380

84-
13. Publish the release version in Jira.
81+
12. Publish the release version in Jira.
8582

86-
14. Announce the release on:
83+
13. Announce the release on:
8784
https://www.mongodb.com/community/forums/c/announcements/driver-releases/110
8885

89-
15. File a ticket for DOCSP highlighting changes in server version and Python
86+
14. File a ticket for DOCSP highlighting changes in server version and Python
9087
version compatibility or the lack thereof, for example:
9188
https://jira.mongodb.org/browse/DOCSP-13536
9289

93-
16. Create a GitHub Release for the tag using
90+
15. Create a GitHub Release for the tag using
9491
https://github.com/mongodb/mongo-python-driver/releases/new.
9592
The title should be "PyMongo X.Y.Z", and the description should contain
9693
a link to the release notes on the the community forum, e.g.

pymongo/__init__.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Python driver for MongoDB."""
1616

17-
from typing import ContextManager, Optional, Tuple, Union
17+
from typing import ContextManager, Optional
1818

1919
__all__ = [
2020
"ASCENDING",
@@ -84,21 +84,8 @@
8484
.. _text index: http://mongodb.com/docs/manual/core/index-text/
8585
"""
8686

87-
version_tuple: Tuple[Union[int, str], ...] = (4, 3, 1)
88-
89-
90-
def get_version_string() -> str:
91-
if isinstance(version_tuple[-1], str):
92-
return ".".join(map(str, version_tuple[:-1])) + version_tuple[-1]
93-
return ".".join(map(str, version_tuple))
94-
95-
96-
__version__: str = get_version_string()
97-
version = __version__
98-
99-
"""Current version of PyMongo."""
100-
10187
from pymongo import _csot
88+
from pymongo._version import __version__, get_version_string, version, version_tuple
10289
from pymongo.collection import ReturnDocument
10390
from pymongo.common import MAX_SUPPORTED_WIRE_VERSION, MIN_SUPPORTED_WIRE_VERSION
10491
from pymongo.cursor import CursorType

pymongo/_version.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2022-present MongoDB, Inc.
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+
"""Current version of PyMongo."""
16+
from typing import Tuple, Union
17+
18+
version_tuple: Tuple[Union[int, str], ...] = (4, 3, 1)
19+
20+
21+
def get_version_string() -> str:
22+
if isinstance(version_tuple[-1], str):
23+
return ".".join(map(str, version_tuple[:-1])) + version_tuple[-1]
24+
return ".".join(map(str, version_tuple))
25+
26+
27+
__version__: str = get_version_string()
28+
version = __version__

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
except ImportError:
3535
_HAVE_SPHINX = False
3636

37-
version = "4.3.1"
37+
version_ns = {}
38+
with open("pymongo/_version.py") as fp:
39+
exec(fp.read(), version_ns)
40+
version = version_ns["__version__"]
3841

3942
f = open("README.rst")
4043
try:

0 commit comments

Comments
 (0)