mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(python): make folder fallback env names customizable
This commit is contained in:
parent
9186d931f8
commit
daea52598c
|
@ -22,6 +22,7 @@ const (
|
||||||
FetchVirtualEnv properties.Property = "fetch_virtual_env"
|
FetchVirtualEnv properties.Property = "fetch_virtual_env"
|
||||||
UsePythonVersionFile properties.Property = "use_python_version_file"
|
UsePythonVersionFile properties.Property = "use_python_version_file"
|
||||||
FolderNameFallback properties.Property = "folder_name_fallback"
|
FolderNameFallback properties.Property = "folder_name_fallback"
|
||||||
|
FallbackNames properties.Property = "fallback_names"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Python) Template() string {
|
func (p *Python) Template() string {
|
||||||
|
@ -81,10 +82,10 @@ func (p *Python) loadContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
folderNameFallback := p.language.props.GetBool(FolderNameFallback, true)
|
folderNameFallback := p.language.props.GetBool(FolderNameFallback, true)
|
||||||
defaultVenvNames := []string{
|
defaultVenvNames := p.language.props.GetStringArray(FallbackNames, []string{
|
||||||
".venv",
|
".venv",
|
||||||
"venv",
|
"venv",
|
||||||
}
|
})
|
||||||
|
|
||||||
var venv string
|
var venv string
|
||||||
for _, venvVar := range venvVars {
|
for _, venvVar := range venvVars {
|
||||||
|
|
|
@ -198,3 +198,48 @@ func TestPythonVirtualEnvIgnoreDefaultVenvNames(t *testing.T) {
|
||||||
assert.Equal(t, tc.Expected, python.Venv)
|
assert.Equal(t, tc.Expected, python.Venv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPythonVirtualEnvIgnoreCustomVenvNames(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Expected string
|
||||||
|
FolderNameFallback bool
|
||||||
|
FallbackNames []string
|
||||||
|
VirtualEnvName string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Expected: "folder",
|
||||||
|
FolderNameFallback: true,
|
||||||
|
FallbackNames: []string{"env"},
|
||||||
|
VirtualEnvName: "/path/to/folder/env",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Expected: "venv",
|
||||||
|
FolderNameFallback: true,
|
||||||
|
FallbackNames: []string{"env"},
|
||||||
|
VirtualEnvName: "/path/to/folder/venv",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
|
||||||
|
env.On("GOOS").Return("")
|
||||||
|
env.On("PathSeparator").Return("/")
|
||||||
|
env.On("CommandPath", testify_.Anything).Return("")
|
||||||
|
env.On("HasFilesInDir", testify_.Anything, "pyvenv.cfg").Return(false)
|
||||||
|
env.On("Getenv", "VIRTUAL_ENV").Return(tc.VirtualEnvName)
|
||||||
|
env.On("Getenv", "CONDA_ENV_PATH").Return("")
|
||||||
|
env.On("Getenv", "CONDA_DEFAULT_ENV").Return("")
|
||||||
|
env.On("Getenv", "PYENV_VERSION").Return("")
|
||||||
|
env.On("HasParentFilePath", ".python-version", false).Return(&runtime.FileInfo{}, errors.New("no match at root level"))
|
||||||
|
|
||||||
|
props[FolderNameFallback] = tc.FolderNameFallback
|
||||||
|
props[FallbackNames] = tc.FallbackNames
|
||||||
|
|
||||||
|
python := &Python{}
|
||||||
|
python.Init(props, env)
|
||||||
|
python.loadContext()
|
||||||
|
assert.Equal(t, tc.Expected, python.Venv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2653,6 +2653,24 @@
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"folder_name_fallback": {
|
||||||
|
"type": "boolean",
|
||||||
|
"title": "Folder Name Fallback",
|
||||||
|
"description": "Replace virtual environment names in fallback_names list with parent folder name",
|
||||||
|
"default": "true"
|
||||||
|
},
|
||||||
|
"fallback_names": {
|
||||||
|
"type": "array",
|
||||||
|
"title": "Fallback Names",
|
||||||
|
"description": "Names to replace when folder_name_fallback is true",
|
||||||
|
"default": [
|
||||||
|
".venv",
|
||||||
|
"venv"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ import Config from "@site/src/components/Config.js";
|
||||||
| `extensions` | `[]string` | `*.py, *.ipynb, pyproject.toml, venv.bak` | allows to override the default list of file extensions to validate |
|
| `extensions` | `[]string` | `*.py, *.ipynb, pyproject.toml, venv.bak` | allows to override the default list of file extensions to validate |
|
||||||
| `folders` | `[]string` | | allows to override the list of folder names to validate |
|
| `folders` | `[]string` | | allows to override the list of folder names to validate |
|
||||||
| `cache_version` | `boolean` | `false` | cache the executable's version or not |
|
| `cache_version` | `boolean` | `false` | cache the executable's version or not |
|
||||||
| `folder_name_fallback` | `boolean` | `true` | instead of `venv` or `.venv` (case sensitive), use the parent folder name as the virtual environment's name or not |
|
| `folder_name_fallback` | `boolean` | `true` | instead of `fallback_names` (case sensitive), use the parent folder name as the virtual environment's name or not |
|
||||||
|
| `fallback_names` | `[]string` | `.venv, venv` | allows to override the list of environment's name replaced when `folder_name_fallback` is `true` |
|
||||||
|
|
||||||
## Template ([info][templates])
|
## Template ([info][templates])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue