|
1 | | -# Copyright 2009-2015 MongoDB, Inc. |
| 1 | +# Copyright 2009-present MongoDB, Inc. |
2 | 2 | # |
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | # you may not use this file except in compliance with the License. |
|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -"""Clean up script for build artifacts. |
| 15 | +"""Remove built C extensions from the source tree. |
16 | 16 |
|
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. |
18 | 19 | """ |
19 | 20 | from __future__ import annotations |
20 | 21 |
|
21 | | -import sys |
22 | 22 | from pathlib import Path |
23 | 23 |
|
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