fix(python): do not validate empty env

This commit is contained in:
Jan De Dobbeleer 2022-10-05 08:03:43 +02:00 committed by Jan De Dobbeleer
parent 6c45afa89a
commit 266fc5671f
2 changed files with 4 additions and 4 deletions

View file

@ -70,6 +70,9 @@ func (p *Python) loadContext() {
var venv string var venv string
for _, venvVar := range venvVars { for _, venvVar := range venvVars {
venv = p.language.env.Getenv(venvVar) venv = p.language.env.Getenv(venvVar)
if len(venv) == 0 {
continue
}
name := environment.Base(p.language.env, venv) name := environment.Base(p.language.env, venv)
if p.canUseVenvName(name) { if p.canUseVenvName(name) {
p.Venv = name p.Venv = name
@ -83,9 +86,6 @@ func (p *Python) inContext() bool {
} }
func (p *Python) canUseVenvName(name string) bool { func (p *Python) canUseVenvName(name string) bool {
if name == "" || name == "." {
return false
}
if p.language.props.GetBool(properties.DisplayDefault, true) { if p.language.props.GetBool(properties.DisplayDefault, true) {
return true return true
} }

View file

@ -121,7 +121,7 @@ func TestPythonPythonInContext(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := new(mock.MockedEnvironment) env := new(mock.MockedEnvironment)
env.On("GOOS").Return("") env.On("GOOS").Return("")
env.On("PathSeparator").Return("") env.On("PathSeparator").Return("/")
env.On("Getenv", "VIRTUAL_ENV").Return(tc.VirtualEnvName) env.On("Getenv", "VIRTUAL_ENV").Return(tc.VirtualEnvName)
env.On("Getenv", "CONDA_ENV_PATH").Return("") env.On("Getenv", "CONDA_ENV_PATH").Return("")
env.On("Getenv", "CONDA_DEFAULT_ENV").Return("") env.On("Getenv", "CONDA_DEFAULT_ENV").Return("")