|
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 | +from setuptools.command.build_ext import ( |
| 69 | + build_ext, # noqa: E402 # This has to be imported AFTER the compiler hack |
| 70 | +) |
| 71 | + |
56 | 72 | build_id_patch = build_id
|
57 | 73 | if not "." in build_id_patch:
|
58 | 74 | build_id_patch += ".0"
|
@@ -856,17 +872,6 @@ def swig_sources(self, sources, ext=None):
|
856 | 872 | return new_sources
|
857 | 873 |
|
858 | 874 |
|
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 | 875 | class my_compiler(MSVCCompiler):
|
871 | 876 | def link(
|
872 | 877 | self,
|
|
0 commit comments