refactor(python): add log statements

This commit is contained in:
Jan De Dobbeleer 2024-12-12 13:19:23 +01:00 committed by Jan De Dobbeleer
parent bda70f0612
commit b0ecd21ce7

View file

@ -7,6 +7,7 @@ import (
"slices" "slices"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/log"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime/path" "github.com/jandedobbeleer/oh-my-posh/src/runtime/path"
) )
@ -68,6 +69,7 @@ func (p *Python) loadContext() {
p.Venv = prompt p.Venv = prompt
return return
} }
venvVars := []string{ venvVars := []string{
"VIRTUAL_ENV", "VIRTUAL_ENV",
"CONDA_ENV_PATH", "CONDA_ENV_PATH",
@ -88,9 +90,11 @@ func (p *Python) loadContext() {
} }
name := path.Base(venv) name := path.Base(venv)
log.Debugf("virtual env name: %s", name)
if folderNameFallback && slices.Contains(defaultVenvNames, name) { if folderNameFallback && slices.Contains(defaultVenvNames, name) {
venv = strings.TrimSuffix(venv, name) venv = strings.TrimSuffix(venv, name)
name = path.Base(venv) name = path.Base(venv)
log.Debugf("virtual env name (fallback): %s", name)
} }
if p.canUseVenvName(name) { if p.canUseVenvName(name) {
@ -108,12 +112,15 @@ func (p *Python) canUseVenvName(name string) bool {
if p.language.props.GetBool(properties.DisplayDefault, true) { if p.language.props.GetBool(properties.DisplayDefault, true) {
return true return true
} }
invalidNames := [2]string{"system", "base"} invalidNames := [2]string{"system", "base"}
for _, a := range invalidNames { for _, a := range invalidNames {
if a == name { if a == name {
log.Debugf("virtual env name %s is invalid", name)
return false return false
} }
} }
return true return true
} }
@ -193,6 +200,7 @@ func (p *Python) pyvenvCfgPrompt() string {
if len(lineSplit) != 2 { if len(lineSplit) != 2 {
continue continue
} }
key := strings.TrimSpace(lineSplit[0]) key := strings.TrimSpace(lineSplit[0])
if key == "prompt" { if key == "prompt" {
value := strings.TrimSpace(lineSplit[1]) value := strings.TrimSpace(lineSplit[1])