From dc30ce0161c5d4b83339fc99bf1f679274dafc52 Mon Sep 17 00:00:00 2001 From: eblack <302387+elebertus@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:52:03 -0700 Subject: [PATCH 1/2] fixing pyvenv.cfg parsing --- segment-virtualenv.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/segment-virtualenv.go b/segment-virtualenv.go index dd21b385..edc5973a 100644 --- a/segment-virtualenv.go +++ b/segment-virtualenv.go @@ -16,7 +16,14 @@ func segmentVirtualEnv(p *powerline) []pwl.Segment { if env != "" { cfg, err := ini.Load(path.Join(env, "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(); len(pyEnv) > 0 { + env = pyEnv + } } } } From 03a5376425ccdb6276e4f75003e9a18794104ed5 Mon Sep 17 00:00:00 2001 From: elebertus <302387+elebertus@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:19:22 -0800 Subject: [PATCH 2/2] Update segment-virtualenv.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zero length string comparison Co-authored-by: Ville Skyttä --- segment-virtualenv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/segment-virtualenv.go b/segment-virtualenv.go index edc5973a..11182287 100644 --- a/segment-virtualenv.go +++ b/segment-virtualenv.go @@ -21,7 +21,7 @@ func segmentVirtualEnv(p *powerline) []pwl.Segment { // 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(); len(pyEnv) > 0 { + if pyEnv := cfg.Section("").Key("prompt").String(); pyEnv != "" { env = pyEnv } }