44 "context"
55 "errors"
66 "fmt"
7+ "io/fs"
78 "os"
89 "path/filepath"
910 "sort"
@@ -16,11 +17,11 @@ import (
1617
1718type Interpreter struct {
1819 Version string
19- Binary string
20+ Path string
2021}
2122
2223func (i Interpreter ) String () string {
23- return fmt .Sprintf ("%s (%s)" , i .Version , i .Binary )
24+ return fmt .Sprintf ("%s (%s)" , i .Version , i .Path )
2425}
2526
2627type allInterpreters []Interpreter
@@ -52,10 +53,14 @@ func DetectInterpreters(ctx context.Context) (allInterpreters, error) {
5253 seen := map [string ]bool {}
5354 for _ , prefix := range paths {
5455 entries , err := os .ReadDir (prefix )
55- if os . IsNotExist (err ) {
56+ if errors . Is (err , fs . ErrNotExist ) {
5657 // some directories in $PATH may not exist
5758 continue
5859 }
60+ if errors .Is (err , fs .ErrPermission ) {
61+ // some directories we cannot list
62+ continue
63+ }
5964 if err != nil {
6065 return nil , fmt .Errorf ("listing %s: %w" , prefix , err )
6166 }
@@ -92,12 +97,11 @@ func DetectInterpreters(ctx context.Context) (allInterpreters, error) {
9297 // and parsing the output.
9398 out , err := process .Background (ctx , []string {resolved , "--version" })
9499 if err != nil {
95- // TODO: skip-and-log or return?
96100 log .Debugf (ctx , "failed to check version for %s: %s" , resolved , err )
97101 continue
98102 }
99103
100- words := strings .Split (out , " " )
104+ words := strings .Split (strings . TrimSpace ( out ) , " " )
101105 // The Python distribution from the Windows Store is available in $PATH as `python.exe`
102106 // and `python3.exe`, even though it symlinks to a real file packaged with some versions of Windows:
103107 // /c/Program Files/WindowsApps/Microsoft.DesktopAppInstaller_.../AppInstallerPythonRedirector.exe.
@@ -126,7 +130,7 @@ func DetectInterpreters(ctx context.Context) (allInterpreters, error) {
126130 }
127131 found = append (found , Interpreter {
128132 Version : version ,
129- Binary : resolved ,
133+ Path : resolved ,
130134 })
131135 }
132136 }
0 commit comments