File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -71,17 +71,20 @@ def identify_python_interpreter(python: str) -> Optional[str]:
71
71
if py :
72
72
return py
73
73
74
- # TODO: On Windows, `--python .venv/Scripts/python` won't pass the
75
- # exists() check (no .exe extension supplied). But it's pretty
76
- # obvious what the user intends. Should we allow this?
74
+ # If the named file exists, and is executable, use it.
75
+ # If it's a directory, assume it's a virtual environment and
76
+ # look for the environment's Python executable.
77
77
if os .path .exists (python ):
78
- if not os .path .isdir (python ):
78
+ # Do the directory check first because directories can be executable
79
+ if os .path .isdir (python ):
80
+ # bin/python for Unix, Scripts/python.exe for Windows
81
+ # Try both in case of odd cases like cygwin.
82
+ for exe in ("bin/python" , "Scripts/python.exe" ):
83
+ py = os .path .join (python , exe )
84
+ if os .path .exists (py ):
85
+ return py
86
+ elif os .access (python , os .X_OK ):
79
87
return python
80
- # Might be a virtual environment
81
- for exe in ("bin/python" , "Scripts/python.exe" ):
82
- py = os .path .join (python , exe )
83
- if os .path .exists (py ):
84
- return py
85
88
86
89
# Could not find the interpreter specified
87
90
return None
You can’t perform that action at this time.
0 commit comments