Skip to content

Commit 69b5ce0

Browse files
authored
Merge branch 'master' into PYTHON-4804
2 parents 9dac71a + d1e4167 commit 69b5ce0

Some content is hidden

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

62 files changed

+900
-510
lines changed

.evergreen/config.yml

Lines changed: 74 additions & 141 deletions
Large diffs are not rendered by default.

.evergreen/utils.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -o xtrace
44

55
find_python3() {
66
PYTHON=""
7-
# Add a fallback system python3 if it is available and Python 3.8+.
8-
if is_python_38 "$(command -v python3)"; then
7+
# Add a fallback system python3 if it is available and Python 3.9+.
8+
if is_python_39 "$(command -v python3)"; then
99
PYTHON="$(command -v python3)"
1010
fi
1111
# Find a suitable toolchain version, if available.
@@ -14,23 +14,23 @@ find_python3() {
1414
if [ -d "/Library/Frameworks/Python.Framework/Versions/3.10" ]; then
1515
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.10/bin/python3"
1616
# macos 10.14
17-
elif [ -d "/Library/Frameworks/Python.Framework/Versions/3.8" ]; then
18-
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.8/bin/python3"
17+
elif [ -d "/Library/Frameworks/Python.Framework/Versions/3.9" ]; then
18+
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.9/bin/python3"
1919
fi
2020
elif [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
21-
PYTHON="C:/python/Python38/python.exe"
21+
PYTHON="C:/python/Python39/python.exe"
2222
else
23-
# Prefer our own toolchain, fall back to mongodb toolchain if it has Python 3.8+.
24-
if [ -f "/opt/python/3.8/bin/python3" ]; then
25-
PYTHON="/opt/python/3.8/bin/python3"
26-
elif is_python_38 "$(command -v /opt/mongodbtoolchain/v4/bin/python3)"; then
23+
# Prefer our own toolchain, fall back to mongodb toolchain if it has Python 3.9+.
24+
if [ -f "/opt/python/3.9/bin/python3" ]; then
25+
PYTHON="/opt/python/3.9/bin/python3"
26+
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v4/bin/python3)"; then
2727
PYTHON="/opt/mongodbtoolchain/v4/bin/python3"
28-
elif is_python_38 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
28+
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
2929
PYTHON="/opt/mongodbtoolchain/v3/bin/python3"
3030
fi
3131
fi
3232
if [ -z "$PYTHON" ]; then
33-
echo "Cannot test without python3.8+ installed!"
33+
echo "Cannot test without python3.9+ installed!"
3434
exit 1
3535
fi
3636
echo "$PYTHON"
@@ -96,15 +96,15 @@ testinstall () {
9696
fi
9797
}
9898

99-
# Function that returns success if the provided Python binary is version 3.8 or later
99+
# Function that returns success if the provided Python binary is version 3.9 or later
100100
# Usage:
101-
# is_python_38 /path/to/python
101+
# is_python_39 /path/to/python
102102
# * param1: Python binary
103-
is_python_38() {
103+
is_python_39() {
104104
if [ -z "$1" ]; then
105105
return 1
106-
elif $1 -c "import sys; exit(sys.version_info[:2] < (3, 8))"; then
107-
# runs when sys.version_info[:2] >= (3, 8)
106+
elif $1 -c "import sys; exit(sys.version_info[:2] < (3, 9))"; then
107+
# runs when sys.version_info[:2] >= (3, 9)
108108
return 0
109109
else
110110
return 1

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: actions/checkout@v4
4040
with:
4141
ref: ${{ inputs.ref }}
42-
- uses: actions/setup-python@v3
42+
- uses: actions/setup-python@v5
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL

.github/workflows/dist.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- uses: actions/setup-python@v5
5454
with:
5555
cache: 'pip'
56-
python-version: 3.8
56+
python-version: 3.9
5757
cache-dependency-path: 'pyproject.toml'
5858
allow-prereleases: true
5959

@@ -67,7 +67,7 @@ jobs:
6767
# Note: the default manylinux is manylinux2014
6868
run: |
6969
python -m pip install -U pip
70-
python -m pip install "cibuildwheel>=2.17,<3"
70+
python -m pip install "cibuildwheel>=2.20,<3"
7171
7272
- name: Build wheels
7373
env:
@@ -79,17 +79,19 @@ jobs:
7979
env:
8080
CIBW_MANYLINUX_X86_64_IMAGE: manylinux1
8181
CIBW_MANYLINUX_I686_IMAGE: manylinux1
82-
CIBW_BUILD: "cp38-${{ matrix.buildplat[1] }} cp39-${{ matrix.buildplat[1] }}"
82+
CIBW_BUILD: "cp39-${{ matrix.buildplat[1] }} cp39-${{ matrix.buildplat[1] }}"
8383
run: python -m cibuildwheel --output-dir wheelhouse
8484

8585
- name: Assert all versions in wheelhouse
8686
if: ${{ ! startsWith(matrix.buildplat[1], 'macos') }}
8787
run: |
88-
ls wheelhouse/*cp38*.whl
8988
ls wheelhouse/*cp39*.whl
9089
ls wheelhouse/*cp310*.whl
9190
ls wheelhouse/*cp311*.whl
9291
ls wheelhouse/*cp312*.whl
92+
ls wheelhouse/*cp313*.whl
93+
# Free-threading builds:
94+
ls wheelhouse/*cp313t*.whl
9395
9496
- uses: actions/upload-artifact@v4
9597
with:
@@ -109,7 +111,7 @@ jobs:
109111
- uses: actions/setup-python@v5
110112
with:
111113
# Build sdist on lowest supported Python
112-
python-version: '3.8'
114+
python-version: '3.9'
113115

114116
- name: Build SDist
115117
run: |

.github/workflows/test-python.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@v4
2323
- uses: actions/setup-python@v5
2424
with:
25-
python-version: "3.8"
25+
python-version: "3.9"
2626
cache: 'pip'
2727
cache-dependency-path: 'pyproject.toml'
2828
- name: Install Python dependencies
@@ -51,11 +51,18 @@ jobs:
5151
strategy:
5252
matrix:
5353
os: [ubuntu-20.04]
54-
python-version: ["3.8", "pypy-3.9", "3.13"]
54+
python-version: ["3.9", "pypy-3.9", "3.13", "3.13t"]
5555
name: CPython ${{ matrix.python-version }}-${{ matrix.os }}
5656
steps:
5757
- uses: actions/checkout@v4
58-
- name: Setup Python
58+
- if: ${{ matrix.python-version == '3.13t' }}
59+
name: Setup free-threaded Python
60+
uses: deadsnakes/[email protected]
61+
with:
62+
python-version: 3.13
63+
nogil: true
64+
- if: ${{ matrix.python-version != '3.13t' }}
65+
name: Setup Python
5966
uses: actions/setup-python@v5
6067
with:
6168
python-version: ${{ matrix.python-version }}
@@ -65,19 +72,27 @@ jobs:
6572
- name: Install dependencies
6673
run: |
6774
pip install -U pip
68-
if [ "${{ matrix.python-version }}" == "3.13" ]; then
75+
if [[ "${{ matrix.python-version }}" == "3.13" ]]; then
6976
pip install --pre cffi setuptools
7077
pip install --no-build-isolation hatch
78+
elif [[ "${{ matrix.python-version }}" == "3.13t" ]]; then
79+
# Hatch can't be installed on 3.13t, use pytest directly.
80+
pip install .
81+
pip install -r requirements/test.txt
7182
else
7283
pip install hatch
7384
fi
7485
- name: Start MongoDB
75-
uses: supercharge/mongodb-github-action@1.10.0
86+
uses: supercharge/mongodb-github-action@1.11.0
7687
with:
7788
mongodb-version: 6.0
7889
- name: Run tests
7990
run: |
80-
hatch run test:test
91+
if [[ "${{ matrix.python-version }}" == "3.13t" ]]; then
92+
pytest -v --durations=5 --maxfail=10
93+
else
94+
hatch run test:test
95+
fi
8196
8297
doctest:
8398
runs-on: ubuntu-latest
@@ -87,14 +102,14 @@ jobs:
87102
- name: Setup Python
88103
uses: actions/setup-python@v5
89104
with:
90-
python-version: "3.8"
105+
python-version: "3.9"
91106
cache: 'pip'
92107
cache-dependency-path: 'pyproject.toml'
93108
- name: Install dependencies
94109
run: |
95110
pip install -U hatch pip
96111
- name: Start MongoDB
97-
uses: supercharge/mongodb-github-action@1.10.0
112+
uses: supercharge/mongodb-github-action@1.11.0
98113
with:
99114
mongodb-version: '8.0.0-rc4'
100115
- name: Run tests
@@ -111,7 +126,7 @@ jobs:
111126
cache: 'pip'
112127
cache-dependency-path: 'pyproject.toml'
113128
# Build docs on lowest supported Python for furo
114-
python-version: '3.8'
129+
python-version: '3.9'
115130
- name: Install dependencies
116131
run: |
117132
pip install -U pip hatch
@@ -129,7 +144,7 @@ jobs:
129144
cache: 'pip'
130145
cache-dependency-path: 'pyproject.toml'
131146
# Build docs on lowest supported Python for furo
132-
python-version: '3.8'
147+
python-version: '3.9'
133148
- name: Install dependencies
134149
run: |
135150
pip install -U pip hatch
@@ -142,7 +157,7 @@ jobs:
142157
runs-on: ubuntu-latest
143158
strategy:
144159
matrix:
145-
python: ["3.8", "3.11"]
160+
python: ["3.9", "3.11"]
146161
steps:
147162
- uses: actions/checkout@v4
148163
- uses: actions/setup-python@v5
@@ -167,7 +182,7 @@ jobs:
167182
cache: 'pip'
168183
cache-dependency-path: 'pyproject.toml'
169184
# Build sdist on lowest supported Python
170-
python-version: '3.8'
185+
python-version: '3.9'
171186
- name: Build SDist
172187
shell: bash
173188
run: |
@@ -199,9 +214,9 @@ jobs:
199214
cache: 'pip'
200215
cache-dependency-path: 'sdist/test/pyproject.toml'
201216
# Test sdist on lowest supported Python
202-
python-version: '3.8'
217+
python-version: '3.9'
203218
- name: Start MongoDB
204-
uses: supercharge/mongodb-github-action@1.10.0
219+
uses: supercharge/mongodb-github-action@1.11.0
205220
- name: Run connect test from sdist
206221
shell: bash
207222
run: |

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ be of interest or that has already been addressed.
1616

1717
## Supported Interpreters
1818

19-
PyMongo supports CPython 3.8+ and PyPy3.9+. Language features not
19+
PyMongo supports CPython 3.9+ and PyPy3.9+. Language features not
2020
supported by all interpreters can not be used.
2121

2222
## Style Guide

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ a native Python driver for MongoDB. The `gridfs` package is a
1414
[gridfs](https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst/)
1515
implementation on top of `pymongo`.
1616

17-
PyMongo supports MongoDB 3.6, 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.
17+
PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.
1818

1919
## Support / Feedback
2020

@@ -90,7 +90,7 @@ package that is incompatible with PyMongo.
9090

9191
## Dependencies
9292

93-
PyMongo supports CPython 3.8+ and PyPy3.9+.
93+
PyMongo supports CPython 3.9+ and PyPy3.9+.
9494

9595
Required dependencies:
9696

bson/_cbsonmodule.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static PyObject* _test_long_long_to_str(PyObject* self, PyObject* args) {
207207
*
208208
* Returns a new ref */
209209
static PyObject* _error(char* name) {
210-
PyObject* error;
210+
PyObject* error = NULL;
211211
PyObject* errors = PyImport_ImportModule("bson.errors");
212212
if (!errors) {
213213
return NULL;
@@ -279,7 +279,7 @@ static PyObject* datetime_from_millis(long long millis) {
279279
* micros = diff * 1000 111000
280280
* Resulting in datetime(1, 1, 1, 1, 1, 1, 111000) -- the expected result
281281
*/
282-
PyObject* datetime;
282+
PyObject* datetime = NULL;
283283
int diff = (int)(((millis % 1000) + 1000) % 1000);
284284
int microseconds = diff * 1000;
285285
Time64_T seconds = (millis - diff) / 1000;
@@ -294,7 +294,7 @@ static PyObject* datetime_from_millis(long long millis) {
294294
timeinfo.tm_sec,
295295
microseconds);
296296
if(!datetime) {
297-
PyObject *etype, *evalue, *etrace;
297+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
298298

299299
/*
300300
* Calling _error clears the error state, so fetch it first.
@@ -350,8 +350,8 @@ static PyObject* datetime_ms_from_millis(PyObject* self, long long millis){
350350
return NULL;
351351
}
352352

353-
PyObject* dt;
354-
PyObject* ll_millis;
353+
PyObject* dt = NULL;
354+
PyObject* ll_millis = NULL;
355355

356356
if (!(ll_millis = PyLong_FromLongLong(millis))){
357357
return NULL;
@@ -1790,7 +1790,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
17901790
PyObject* result;
17911791
unsigned char check_keys;
17921792
unsigned char top_level = 1;
1793-
PyObject* options_obj;
1793+
PyObject* options_obj = NULL;
17941794
codec_options_t options;
17951795
buffer_t buffer;
17961796
PyObject* raw_bson_document_bytes_obj;
@@ -2512,8 +2512,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
25122512
* Wrap any non-InvalidBSON errors in InvalidBSON.
25132513
*/
25142514
if (PyErr_Occurred()) {
2515-
PyObject *etype, *evalue, *etrace;
2516-
PyObject *InvalidBSON;
2515+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
2516+
PyObject *InvalidBSON = NULL;
25172517

25182518
/*
25192519
* Calling _error clears the error state, so fetch it first.
@@ -2585,8 +2585,8 @@ static int _element_to_dict(PyObject* self, const char* string,
25852585
if (!*name) {
25862586
/* If NULL is returned then wrap the UnicodeDecodeError
25872587
in an InvalidBSON error */
2588-
PyObject *etype, *evalue, *etrace;
2589-
PyObject *InvalidBSON;
2588+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
2589+
PyObject *InvalidBSON = NULL;
25902590

25912591
PyErr_Fetch(&etype, &evalue, &etrace);
25922592
if (PyErr_GivenExceptionMatches(etype, PyExc_Exception)) {
@@ -2620,7 +2620,7 @@ static PyObject* _cbson_element_to_dict(PyObject* self, PyObject* args) {
26202620
/* TODO: Support buffer protocol */
26212621
char* string;
26222622
PyObject* bson;
2623-
PyObject* options_obj;
2623+
PyObject* options_obj = NULL;
26242624
codec_options_t options;
26252625
unsigned position;
26262626
unsigned max;
@@ -2732,7 +2732,7 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* args) {
27322732
int32_t size;
27332733
Py_ssize_t total_size;
27342734
const char* string;
2735-
PyObject* bson;
2735+
PyObject* bson = NULL;
27362736
codec_options_t options;
27372737
PyObject* result = NULL;
27382738
PyObject* options_obj;
@@ -3184,6 +3184,9 @@ static PyModuleDef_Slot _cbson_slots[] = {
31843184
{Py_mod_exec, _cbson_exec},
31853185
#if defined(Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED)
31863186
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED},
3187+
#endif
3188+
#if PY_VERSION_HEX >= 0x030D0000
3189+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
31873190
#endif
31883191
{0, NULL},
31893192
};

0 commit comments

Comments
 (0)