@@ -17,6 +17,7 @@ def __init__(self, options):
1717 super (Builtin , self ).__init__ (options )
1818 self .python_spec = options .python if options .python else [sys .executable ]
1919 self .app_data = options .app_data
20+ self .try_first_with = options .try_first_with
2021
2122 @classmethod
2223 def add_parser_arguments (cls , parser ):
@@ -31,10 +32,19 @@ def add_parser_arguments(cls, parser):
3132 help = "interpreter based on what to create environment (path/identifier) "
3233 "- by default use the interpreter where the tool is installed - first found wins" ,
3334 )
35+ parser .add_argument (
36+ "--try-first-with" ,
37+ dest = "try_first_with" ,
38+ metavar = "py_exe" ,
39+ type = str ,
40+ action = "append" ,
41+ default = [],
42+ help = "try first these interpreters before starting the discovery" ,
43+ )
3444
3545 def run (self ):
3646 for python_spec in self .python_spec :
37- result = get_interpreter (python_spec , self .app_data )
47+ result = get_interpreter (python_spec , self .try_first_with , self . app_data )
3848 if result is not None :
3949 return result
4050 return None
@@ -47,11 +57,11 @@ def __unicode__(self):
4757 return "{} discover of python_spec={!r}" .format (self .__class__ .__name__ , spec )
4858
4959
50- def get_interpreter (key , app_data = None ):
60+ def get_interpreter (key , try_first_with , app_data = None ):
5161 spec = PythonSpec .from_string_spec (key )
5262 logging .info ("find interpreter for spec %r" , spec )
5363 proposed_paths = set ()
54- for interpreter , impl_must_match in propose_interpreters (spec , app_data ):
64+ for interpreter , impl_must_match in propose_interpreters (spec , try_first_with , app_data ):
5565 key = interpreter .system_executable , impl_must_match
5666 if key in proposed_paths :
5767 continue
@@ -62,7 +72,17 @@ def get_interpreter(key, app_data=None):
6272 proposed_paths .add (key )
6373
6474
65- def propose_interpreters (spec , app_data ):
75+ def propose_interpreters (spec , try_first_with , app_data ):
76+ # 0. try with first
77+ for py_exe in try_first_with :
78+ path = os .path .abspath (py_exe )
79+ try :
80+ os .lstat (path ) # Windows Store Python does not work with os.path.exists, but does for os.lstat
81+ except OSError :
82+ pass
83+ else :
84+ yield PythonInfo .from_exe (os .path .abspath (path ), app_data ), True
85+
6686 # 1. if it's a path and exists
6787 if spec .path is not None :
6888 try :
0 commit comments