Skip to content

Commit bacd9c6

Browse files
committed
sysconfig: skip customize_compiler() with MSVC Python again
By enabling customize_compiler() when using the mingw compiler class in 2ad8784 this also enabled it for when the mingw compiler class was used with a MSVC built CPython. MSVC CPython doesn't have any of the config vars that are required in customize_compiler() though. And while it would be nice if all the env vars would be considered in that scenario too, it's not clear how this should be implemented without any sysconfig provided fallbacks (if CC isn't set but CFLAGS is, there is no way to pass things to set_executables() etc.) Given that, just restore the previous behaviour, skip customize_compiler() with MSVC Python in all cases, and add a test. Fixes https://github.com/pypa/setuptools/issues/4456
1 parent 4a3406b commit bacd9c6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

distutils/sysconfig.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ def customize_compiler(compiler): # noqa: C901
293293
Mainly needed on Unix, so we can plug in the information that
294294
varies across Unices and is stored in Python's Makefile.
295295
"""
296-
if compiler.compiler_type in ["unix", "cygwin", "mingw32"]:
296+
if compiler.compiler_type in ["unix", "cygwin"] or (
297+
compiler.compiler_type == "mingw32" and is_mingw()
298+
):
297299
_customize_macos()
298300

299301
(

distutils/tests/test_mingwccompiler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from distutils.util import split_quoted, is_mingw
44
from distutils.errors import DistutilsPlatformError, CCompilerError
5+
from distutils import sysconfig
56

67

78
class TestMingw32CCompiler:
@@ -43,3 +44,12 @@ def test_cygwincc_error(self, monkeypatch):
4344

4445
with pytest.raises(CCompilerError):
4546
distutils.cygwinccompiler.Mingw32CCompiler()
47+
48+
def test_customize_compiler_with_msvc_python(self):
49+
from distutils.cygwinccompiler import Mingw32CCompiler
50+
51+
# In case we have an MSVC Python build, but still want to use
52+
# Mingw32CCompiler, then customize_compiler() shouldn't fail at least.
53+
# https://github.com/pypa/setuptools/issues/4456
54+
compiler = Mingw32CCompiler()
55+
sysconfig.customize_compiler(compiler)

0 commit comments

Comments
 (0)