30
30
31
31
# ** Values known at compile time **
32
32
# os_name -- [in] one of 'nt', 'posix', 'darwin'
33
+ # is_mingw -- [in] True if targeting MinGW
33
34
# PREFIX -- [in] sysconfig.get_config_var(...)
34
35
# EXEC_PREFIX -- [in] sysconfig.get_config_var(...)
35
36
# PYTHONPATH -- [in] sysconfig.get_config_var(...)
51
52
# ENV_PYTHONHOME -- [in] getenv(...)
52
53
# ENV_PYTHONEXECUTABLE -- [in] getenv(...)
53
54
# ENV___PYVENV_LAUNCHER__ -- [in] getenv(...)
55
+ # ENV_MSYSTEM -- [in] getenv(...)
54
56
55
57
# ** Values calculated at runtime **
56
58
# config -- [in/out] dict of the PyConfig structure
185
187
ZIP_LANDMARK = f'{ platlibdir } /python{ VERSION_MAJOR } { VERSION_MINOR } .zip'
186
188
DELIM = ':'
187
189
SEP = '/'
190
+ ALTSEP = None
188
191
189
- elif os_name == 'nt' :
192
+ elif os_name == 'nt' and is_mingw :
193
+ BUILDDIR_TXT = 'pybuilddir.txt'
194
+ BUILD_LANDMARK = 'Modules/Setup.local'
195
+ DEFAULT_PROGRAM_NAME = f'python{ VERSION_MAJOR } '
196
+ STDLIB_SUBDIR = f'{ platlibdir } /python{ VERSION_MAJOR } .{ VERSION_MINOR } '
197
+ STDLIB_LANDMARKS = [f'{ STDLIB_SUBDIR } /os.py' , f'{ STDLIB_SUBDIR } /os.pyc' ]
198
+ PLATSTDLIB_LANDMARK = f'{ platlibdir } /python{ VERSION_MAJOR } .{ VERSION_MINOR } /lib-dynload'
199
+ BUILDSTDLIB_LANDMARKS = ['Lib/os.py' ]
200
+ VENV_LANDMARK = 'pyvenv.cfg'
201
+ ZIP_LANDMARK = f'{ platlibdir } /python{ VERSION_MAJOR } { VERSION_MINOR } .zip'
202
+ DELIM = ';'
203
+ if ENV_MSYSTEM :
204
+ SEP = '/'
205
+ ALTSEP = '\\ '
206
+ else :
207
+ SEP = '\\ '
208
+ ALTSEP = '/'
209
+
210
+ elif os_name == 'nt' : # MSVC
190
211
BUILDDIR_TXT = 'pybuilddir.txt'
191
212
BUILD_LANDMARK = f'{ VPATH } \\ Modules\\ Setup.local'
192
213
DEFAULT_PROGRAM_NAME = f'python'
199
220
WINREG_KEY = f'SOFTWARE\\ Python\\ PythonCore\\ { PYWINVER } \\ PythonPath'
200
221
DELIM = ';'
201
222
SEP = '\\ '
223
+ ALTSEP = '/'
202
224
203
225
204
226
# ******************************************************************************
@@ -263,10 +285,10 @@ def search_up(prefix, *landmarks, test=isfile):
263
285
if not executable :
264
286
executable = real_executable
265
287
266
- if not executable and SEP in program_name :
288
+ if not executable and (SEP in program_name or
289
+ (ALTSEP and ALTSEP in program_name )):
267
290
# Resolve partial path program_name against current directory
268
291
executable = abspath (program_name )
269
-
270
292
if not executable :
271
293
# All platforms default to real_executable if known at this
272
294
# stage. POSIX does not set this value.
@@ -497,15 +519,15 @@ def search_up(prefix, *landmarks, test=isfile):
497
519
except (FileNotFoundError , PermissionError ):
498
520
if isfile (joinpath (real_executable_dir , BUILD_LANDMARK )):
499
521
build_prefix = joinpath (real_executable_dir , VPATH )
500
- if os_name == 'nt' :
522
+ if os_name == 'nt' and not is_mingw :
501
523
# QUIRK: Windows builds need platstdlib_dir to be the executable
502
524
# dir. Normally the builddir marker handles this, but in this
503
525
# case we need to correct manually.
504
526
platstdlib_dir = real_executable_dir
505
527
506
528
if build_prefix :
507
- if os_name == 'nt' :
508
- # QUIRK: No searching for more landmarks on Windows
529
+ if os_name == 'nt' and not is_mingw :
530
+ # QUIRK: No searching for more landmarks on MSVC
509
531
build_stdlib_prefix = build_prefix
510
532
else :
511
533
build_stdlib_prefix = search_up (build_prefix , * BUILDSTDLIB_LANDMARKS )
@@ -597,7 +619,7 @@ def search_up(prefix, *landmarks, test=isfile):
597
619
598
620
# Detect exec_prefix by searching from executable for the platstdlib_dir
599
621
if PLATSTDLIB_LANDMARK and not exec_prefix :
600
- if os_name == 'nt' :
622
+ if os_name == 'nt' and ( not is_mingw ) :
601
623
# QUIRK: Windows always assumed these were the same
602
624
# gh-100320: Our PYDs are assumed to be relative to the Lib directory
603
625
# (that is, prefix) rather than the executable (that is, executable_dir)
@@ -607,7 +629,7 @@ def search_up(prefix, *landmarks, test=isfile):
607
629
if not exec_prefix and EXEC_PREFIX :
608
630
exec_prefix = EXEC_PREFIX
609
631
if not exec_prefix or not isdir (joinpath (exec_prefix , PLATSTDLIB_LANDMARK )):
610
- if os_name == 'nt' :
632
+ if os_name == 'nt' and ( not is_mingw ) :
611
633
# QUIRK: If DLLs is missing on Windows, don't warn, just assume
612
634
# that they're in exec_prefix
613
635
if not platstdlib_dir :
@@ -660,7 +682,7 @@ def search_up(prefix, *landmarks, test=isfile):
660
682
pythonpath .append (abspath (p ))
661
683
662
684
# Then add the default zip file
663
- if os_name == 'nt' :
685
+ if os_name == 'nt' and ( not is_mingw ) :
664
686
# QUIRK: Windows uses the library directory rather than the prefix
665
687
if library :
666
688
library_dir = dirname (library )
@@ -673,7 +695,7 @@ def search_up(prefix, *landmarks, test=isfile):
673
695
else :
674
696
pythonpath .append (joinpath (prefix , ZIP_LANDMARK ))
675
697
676
- if os_name == 'nt' and use_environment and winreg :
698
+ if ( not is_mingw ) and os_name == 'nt' and use_environment and winreg :
677
699
# QUIRK: Windows also lists paths in the registry. Paths are stored
678
700
# as the default value of each subkey of
679
701
# {HKCU,HKLM}\Software\Python\PythonCore\{winver}\PythonPath
@@ -714,7 +736,7 @@ def search_up(prefix, *landmarks, test=isfile):
714
736
if not platstdlib_dir and exec_prefix :
715
737
platstdlib_dir = joinpath (exec_prefix , PLATSTDLIB_LANDMARK )
716
738
717
- if os_name == 'nt' :
739
+ if os_name == 'nt' and ( not is_mingw ) :
718
740
# QUIRK: Windows generates paths differently
719
741
if platstdlib_dir :
720
742
pythonpath .append (platstdlib_dir )
@@ -742,8 +764,8 @@ def search_up(prefix, *landmarks, test=isfile):
742
764
743
765
# QUIRK: Non-Windows replaces prefix/exec_prefix with defaults when running
744
766
# in build directory. This happens after pythonpath calculation.
745
- if os_name != 'nt' and build_prefix :
746
- prefix = config .get ('prefix' ) or PREFIX
767
+ if ( os_name != 'nt' or is_mingw ) and build_prefix :
768
+ prefix = config .get ('prefix' ) or abspath ( PREFIX )
747
769
exec_prefix = config .get ('exec_prefix' ) or EXEC_PREFIX or prefix
748
770
749
771
0 commit comments