Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ jobs:
- name: Build wheels
env:
CIBW_BUILD: ${{ matrix.buildplat[2] }}
# Strip any in-place C extensions from previous builds
# so they don't leak into the next wheel.
CIBW_BEFORE_BUILD: python ./tools/clean.py
run: python -m cibuildwheel --output-dir wheelhouse

- name: Assert all versions in wheelhouse
Expand Down
38 changes: 9 additions & 29 deletions tools/clean.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2009-2015 MongoDB, Inc.
# Copyright 2009-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,37 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Clean up script for build artifacts.
"""Remove built C extensions from the source tree.

Only really intended to be used by internal build scripts.
Used as cibuildwheel's before-build hook so artifacts from one Python
version do not leak into the wheel built for the next.
"""
from __future__ import annotations

import sys
from pathlib import Path

try:
Path("pymongo/_cmessage.so").unlink()
Path("bson/_cbson.so").unlink()
except BaseException: # noqa: S110
pass

try:
Path("pymongo/_cmessage.pyd").unlink()
Path("bson/_cbson.pyd").unlink()
except BaseException: # noqa: S110
pass

try:
from pymongo import _cmessage # type: ignore[attr-defined] # noqa: F401

sys.exit("could still import _cmessage")
except ImportError:
pass

try:
from bson import _cbson # type: ignore[attr-defined] # noqa: F401

sys.exit("could still import _cbson")
except ImportError:
pass
for pkg in ("bson", "pymongo"):
for pattern in ("*.so", "*.pyd"):
for path in Path(pkg).glob(pattern):
path.unlink()
print(f"removed {path}")
Loading