Skip to content

Commit

Permalink
sysconfig: skip customize_compiler() with MSVC Python again
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lazka committed Jul 4, 2024
1 parent 4a3406b commit bacd9c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ def customize_compiler(compiler): # noqa: C901
Mainly needed on Unix, so we can plug in the information that
varies across Unices and is stored in Python's Makefile.
"""
if compiler.compiler_type in ["unix", "cygwin", "mingw32"]:
if compiler.compiler_type in ["unix", "cygwin"] or (
compiler.compiler_type == "mingw32" and is_mingw()
):
_customize_macos()

(
Expand Down
10 changes: 10 additions & 0 deletions distutils/tests/test_mingwccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from distutils.util import split_quoted, is_mingw
from distutils.errors import DistutilsPlatformError, CCompilerError
from distutils import sysconfig


class TestMingw32CCompiler:
Expand Down Expand Up @@ -43,3 +44,12 @@ def test_cygwincc_error(self, monkeypatch):

with pytest.raises(CCompilerError):
distutils.cygwinccompiler.Mingw32CCompiler()

def test_customize_compiler_with_msvc_python(self):
from distutils.cygwinccompiler import Mingw32CCompiler

# In case we have an MSVC Python build, but still want to use
# Mingw32CCompiler, then customize_compiler() shouldn't fail at least.
# https://github.com/pypa/setuptools/issues/4456
compiler = Mingw32CCompiler()
sysconfig.customize_compiler(compiler)

0 comments on commit bacd9c6

Please sign in to comment.