Skip to content

Commit

Permalink
Merge pull request #387 from elebertus/main
Browse files Browse the repository at this point in the history
Fix for empty string value from pyvenv.cfg parsing
  • Loading branch information
justjanne authored Jun 17, 2024
2 parents f5424ea + 03a5376 commit 059f7f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion segment-virtualenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ func segmentVirtualEnv(p *powerline) []pwl.Segment {
if venv != "" {
cfg, err := ini.Load(path.Join(venv, "pyvenv.cfg"))
if err == nil {
env = cfg.Section("").Key("prompt").String()
// python >= 3.6 the venv module will not insert a prompt
// key unless the `--prompt` flag is passed to the module
// or if calling with the prompt arg EnvBuilder
// otherwise env evaluates to an empty string, per return
// of ini.File.Section.Key
if pyEnv := cfg.Section("").Key("prompt").String(); pyEnv != "" {
env = pyEnv
}
}
if env == "" {
env = venv
Expand Down

0 comments on commit 059f7f2

Please sign in to comment.