2929 project_base = os .path .abspath (os .environ ["_PYTHON_PROJECT_BASE" ])
3030else :
3131 project_base = os .path .dirname (os .path .abspath (sys .executable ))
32- if (os .name == 'nt' and
33- project_base .lower ().endswith (('\\ pcbuild\\ win32' , '\\ pcbuild\\ amd64' ))):
34- project_base = os .path .dirname (os .path .dirname (project_base ))
32+
3533
3634# python_build: (Boolean) if true, we're either building Python or
3735# building an extension with an un-installed Python, so we use
@@ -41,16 +39,26 @@ def _is_python_source_dir(d):
4139 if os .path .isfile (os .path .join (d , "Modules" , fn )):
4240 return True
4341 return False
42+
4443_sys_home = getattr (sys , '_home' , None )
45- if (_sys_home and os .name == 'nt' and
46- _sys_home .lower ().endswith (('\\ pcbuild\\ win32' , '\\ pcbuild\\ amd64' ))):
47- _sys_home = os .path .dirname (os .path .dirname (_sys_home ))
44+
45+ if os .name == 'nt' :
46+ def _fix_pcbuild (d ):
47+ if d and os .path .normcase (d ).startswith (
48+ os .path .normcase (os .path .join (PREFIX , "PCbuild" ))):
49+ return PREFIX
50+ return d
51+ project_base = _fix_pcbuild (project_base )
52+ _sys_home = _fix_pcbuild (_sys_home )
53+
4854def _python_build ():
4955 if _sys_home :
5056 return _is_python_source_dir (_sys_home )
5157 return _is_python_source_dir (project_base )
58+
5259python_build = _python_build ()
5360
61+
5462# Calculate the build qualifier flags if they are defined. Adding the flags
5563# to the include and lib directories only makes sense for an installation, not
5664# an in-source build.
@@ -99,6 +107,11 @@ def get_python_inc(plat_specific=0, prefix=None):
99107 python_dir = 'python' + get_python_version () + build_flags
100108 return os .path .join (prefix , "include" , python_dir )
101109 elif os .name == "nt" :
110+ if python_build :
111+ # Include both the include and PC dir to ensure we can find
112+ # pyconfig.h
113+ return (os .path .join (prefix , "include" ) + os .path .pathsep +
114+ os .path .join (prefix , "PC" ))
102115 return os .path .join (prefix , "include" )
103116 else :
104117 raise DistutilsPlatformError (
0 commit comments