Skip to content

Commit cd5cbb2

Browse files
QuLogicanntzer
andcommitted
Fix Windows build on setuptools that default to local distutils.
This is a cross port of matplotlib/mplcairo@2991c72 and matplotlib/mplcairo@2991c72 Fixes matplotlib#23147 Co-authored-by: Antony Lee <[email protected]>
1 parent 518eb93 commit cd5cbb2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

setupext.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import sysconfig
1414
import tarfile
15+
from tempfile import TemporaryDirectory
1516
import textwrap
1617
import urllib.request
1718

@@ -691,15 +692,31 @@ def do_custom_build(self, env):
691692
f.write(vcxproj)
692693

693694
cc = get_ccompiler()
694-
cc.initialize() # Get msbuild in the %PATH% of cc.spawn.
695+
cc.initialize()
696+
# On setuptools versions that use "local" distutils,
697+
# ``cc.spawn(["msbuild", ...])`` no longer manages to locate the
698+
# right executable, even though they are correctly on the PATH,
699+
# because only the env kwarg to Popen() is updated, and not
700+
# os.environ["PATH"]. Instead, use shutil.which to walk the PATH
701+
# and get absolute executable paths.
702+
with TemporaryDirectory() as tmpdir:
703+
dest = Path(tmpdir, "path")
704+
cc.spawn([
705+
sys.executable, "-c",
706+
"import pathlib, shutil, sys\n"
707+
"dest = pathlib.Path(sys.argv[1])\n"
708+
"dest.write_text(shutil.which('msbuild'))\n",
709+
str(dest),
710+
])
711+
msbuild_path = dest.read_text()
695712
# Freetype 2.10.0+ support static builds.
696713
msbuild_config = (
697714
"Release Static"
698715
if [*map(int, LOCAL_FREETYPE_VERSION.split("."))] >= [2, 10]
699716
else "Release"
700717
)
701718

702-
cc.spawn(["msbuild", str(sln_path),
719+
cc.spawn([msbuild_path, str(sln_path),
703720
"/t:Clean;Build",
704721
f"/p:Configuration={msbuild_config};"
705722
f"Platform={msbuild_platform}"])

0 commit comments

Comments
 (0)