|
36 | 36 | from collections.abc import MutableSequence |
37 | 37 | from pathlib import Path |
38 | 38 | from setuptools import Extension, setup |
| 39 | +from setuptools._distutils import ccompiler |
39 | 40 | from setuptools.command.build import build |
40 | | -from setuptools.command.build_ext import build_ext |
41 | 41 | from setuptools.modified import newer_group |
42 | 42 | from tempfile import gettempdir |
43 | 43 | from typing import TYPE_CHECKING, Iterable |
|
53 | 53 | from distutils._msvccompiler import MSVCCompiler |
54 | 54 | from distutils.command.install_data import install_data |
55 | 55 |
|
| 56 | + |
| 57 | +def my_new_compiler(**kw): |
| 58 | + if "compiler" in kw and kw["compiler"] in (None, "msvc"): |
| 59 | + return my_compiler() |
| 60 | + return orig_new_compiler(**kw) |
| 61 | + |
| 62 | + |
| 63 | +# No way to cleanly wedge our compiler sub-class in. |
| 64 | +orig_new_compiler = ccompiler.new_compiler |
| 65 | +ccompiler.new_compiler = my_new_compiler # type: ignore[assignment] # Assuming the caller will always use only kwargs |
| 66 | + |
| 67 | + |
| 68 | +# This import has to be delayed to AFTER the compiler hack |
| 69 | +from setuptools.command.build_ext import build_ext # noqa: E402 |
| 70 | + |
56 | 71 | build_id_patch = build_id |
57 | 72 | if not "." in build_id_patch: |
58 | 73 | build_id_patch += ".0" |
@@ -856,17 +871,6 @@ def swig_sources(self, sources, ext=None): |
856 | 871 | return new_sources |
857 | 872 |
|
858 | 873 |
|
859 | | -def my_new_compiler(**kw): |
860 | | - if "compiler" in kw and kw["compiler"] in (None, "msvc"): |
861 | | - return my_compiler() |
862 | | - return orig_new_compiler(**kw) |
863 | | - |
864 | | - |
865 | | -# No way to cleanly wedge our compiler sub-class in. |
866 | | -orig_new_compiler = ccompiler.new_compiler |
867 | | -ccompiler.new_compiler = my_new_compiler # type: ignore[assignment] # Assuming the caller will always use only kwargs |
868 | | - |
869 | | - |
870 | 874 | class my_compiler(MSVCCompiler): |
871 | 875 | def link( |
872 | 876 | self, |
|
0 commit comments