Skip to content

Commit

Permalink
fix(pyenv): identify shims correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Mar 4, 2025
1 parent 58670c5 commit 5ef8065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/segments/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ func (l *language) setVersion() error {
for _, command := range l.commands {
versionStr, err := l.runCommand(command)
if err != nil {
log.Error(err)
lastError = err
continue
}

version, err := command.parse(versionStr)
if err != nil {
log.Error(err)
lastError = fmt.Errorf("err parsing info from %s with %s", command.executable, versionStr)
continue
}
Expand Down Expand Up @@ -271,8 +273,12 @@ func (l *language) runCommand(command *cmd) (string, error) {
}

versionStr, err := command.getVersion()
if err != nil || versionStr == "" {
return "", errors.New("cannot get version")
if err != nil {
return "", err
}

if len(versionStr) == 0 {
return "", errors.New("no version found")
}

return versionStr, nil
Expand Down
3 changes: 1 addition & 2 deletions src/segments/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func (p *Python) pyenvVersion() (string, error) {
}

pyEnvRoot := p.env.Getenv("PYENV_ROOT")
// TODO: pyenv-win has this at $PYENV_ROOT/pyenv-win/shims
if cmdPath != filepath.Join(pyEnvRoot, "shims", "python") {
if !strings.HasPrefix(cmdPath, pyEnvRoot) {
return "", fmt.Errorf("executable at %s is not a pyenv shim", cmdPath)
}

Expand Down

0 comments on commit 5ef8065

Please sign in to comment.