feat(python): default to home enabled and environment

resolves #1104
This commit is contained in:
Jan De Dobbeleer 2021-10-24 19:04:18 +02:00 committed by Jan De Dobbeleer
parent eca24bebcc
commit 7e5b9fa725
3 changed files with 21 additions and 12 deletions

View file

@ -71,6 +71,8 @@ type language struct {
loadContext loadContext
inContext inContext
matchesVersionFile matchesVersionFile
homeEnabled bool
displayMode string
}
const (
@ -121,13 +123,16 @@ func (l *language) enabled() bool {
inHomeDir := func() bool {
return l.env.getcwd() == l.env.homeDir()
}
homeEnabled := l.props.getBool(HomeEnabled, false)
homeEnabled := l.props.getBool(HomeEnabled, l.homeEnabled)
if inHomeDir() && !homeEnabled {
return false
}
displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
// set default mode when not set
if len(l.displayMode) == 0 {
l.displayMode = l.props.getString(DisplayMode, DisplayModeFiles)
}
l.loadLanguageContext()
switch displayMode {
switch l.displayMode {
case DisplayModeAlways:
return true
case DisplayModeEnvironment:

View file

@ -43,6 +43,8 @@ func (p *python) init(props *properties, env environmentInfo) {
},
},
versionURLTemplate: "[%s](https://www.python.org/downloads/release/python-%s%s%s/)",
displayMode: props.getString(DisplayMode, DisplayModeEnvironment),
homeEnabled: props.getBool(HomeEnabled, true),
}
}

View file

@ -8,7 +8,9 @@ import (
func TestPythonVirtualEnv(t *testing.T) {
cases := []struct {
Case string
Expected string
ExpectedDisabled bool
VirtualEnvName string
CondaEnvName string
CondaDefaultEnvName string
@ -16,13 +18,13 @@ func TestPythonVirtualEnv(t *testing.T) {
DisplayVersion bool
DisplayDefault bool
}{
{Expected: "VENV", VirtualEnvName: "VENV"},
{Expected: "CONDA", CondaEnvName: "CONDA"},
{Expected: "CONDA", CondaDefaultEnvName: "CONDA"},
{Expected: "", CondaDefaultEnvName: "base"},
{Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true},
{Expected: "PYENV", PyEnvName: "PYENV"},
{Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true},
{Case: "VENV", Expected: "VENV", VirtualEnvName: "VENV"},
{Case: "CONDA", Expected: "CONDA", CondaEnvName: "CONDA"},
{Case: "CONDA default", Expected: "CONDA", CondaDefaultEnvName: "CONDA"},
{Case: "Display Base", Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true},
{Case: "Hide base", Expected: "", CondaDefaultEnvName: "base", ExpectedDisabled: true},
{Case: "PYENV", Expected: "PYENV", PyEnvName: "PYENV"},
{Case: "PYENV Version", Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true},
}
for _, tc := range cases {
@ -46,8 +48,8 @@ func TestPythonVirtualEnv(t *testing.T) {
}
python := &python{}
python.init(props, env)
assert.True(t, python.enabled())
assert.Equal(t, tc.Expected, python.string())
assert.Equal(t, !tc.ExpectedDisabled, python.enabled(), tc.Case)
assert.Equal(t, tc.Expected, python.string(), tc.Case)
}
}