Skip to content

Commit d8b6b8a

Browse files
authored
PYTHON-5839 - PyMongo wheels have multiple versions of C extensions (#2865)
1 parent 22c7c40 commit d8b6b8a

2 files changed

Lines changed: 12 additions & 29 deletions

File tree

.github/workflows/dist.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ jobs:
7878
- name: Build wheels
7979
env:
8080
CIBW_BUILD: ${{ matrix.buildplat[2] }}
81+
# Strip any in-place C extensions from previous builds
82+
# so they don't leak into the next wheel.
83+
CIBW_BEFORE_BUILD: python ./tools/clean.py
8184
run: python -m cibuildwheel --output-dir wheelhouse
8285

8386
- name: Assert all versions in wheelhouse

tools/clean.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2009-2015 MongoDB, Inc.
1+
# Copyright 2009-present MongoDB, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,37 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Clean up script for build artifacts.
15+
"""Remove built C extensions from the source tree.
1616
17-
Only really intended to be used by internal build scripts.
17+
Used as cibuildwheel's before-build hook so artifacts from one Python
18+
version do not leak into the wheel built for the next.
1819
"""
1920
from __future__ import annotations
2021

21-
import sys
2222
from pathlib import Path
2323

24-
try:
25-
Path("pymongo/_cmessage.so").unlink()
26-
Path("bson/_cbson.so").unlink()
27-
except BaseException: # noqa: S110
28-
pass
29-
30-
try:
31-
Path("pymongo/_cmessage.pyd").unlink()
32-
Path("bson/_cbson.pyd").unlink()
33-
except BaseException: # noqa: S110
34-
pass
35-
36-
try:
37-
from pymongo import _cmessage # type: ignore[attr-defined] # noqa: F401
38-
39-
sys.exit("could still import _cmessage")
40-
except ImportError:
41-
pass
42-
43-
try:
44-
from bson import _cbson # type: ignore[attr-defined] # noqa: F401
45-
46-
sys.exit("could still import _cbson")
47-
except ImportError:
48-
pass
24+
for pkg in ("bson", "pymongo"):
25+
for pattern in ("*.so", "*.pyd"):
26+
for path in Path(pkg).glob(pattern):
27+
path.unlink()
28+
print(f"removed {path}")

0 commit comments

Comments
 (0)