From 1dd6832a15a10dde8cad419cbdc1c1edfc22f940 Mon Sep 17 00:00:00 2001 From: Andras Kovi Date: Thu, 23 Oct 2025 11:18:07 +0200 Subject: [PATCH] Fix python version display (#76) --- .../pyvenvmanage/VenvProjectViewNodeDecorator.kt | 10 ++++++---- src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt | 10 ++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/github/pyvenvmanage/VenvProjectViewNodeDecorator.kt b/src/main/kotlin/com/github/pyvenvmanage/VenvProjectViewNodeDecorator.kt index 9d67d5e..2f928d4 100644 --- a/src/main/kotlin/com/github/pyvenvmanage/VenvProjectViewNodeDecorator.kt +++ b/src/main/kotlin/com/github/pyvenvmanage/VenvProjectViewNodeDecorator.kt @@ -15,10 +15,12 @@ class VenvProjectViewNodeDecorator : ProjectViewNodeDecorator { val pyVenvCfgPath = VenvUtils.getPyVenvCfg(node.getVirtualFile()) if (pyVenvCfgPath != null) { val pythonVersion = VenvUtils.getPythonVersionFromPyVenv(pyvenvCfgPath = pyVenvCfgPath) - val fileName: String? = data.getPresentableText() - data.clearText() - data.addText(fileName, SimpleTextAttributes.REGULAR_ATTRIBUTES) - data.addText(" [" + pythonVersion + "]", SimpleTextAttributes.GRAY_ATTRIBUTES) + if (pythonVersion != null) { + val fileName: String? = data.getPresentableText() + data.clearText() + data.addText(fileName, SimpleTextAttributes.REGULAR_ATTRIBUTES) + data.addText(" [$pythonVersion]", SimpleTextAttributes.GRAY_ATTRIBUTES) + } data.setIcon(Virtualenv) } } diff --git a/src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt b/src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt index f4be217..c539904 100644 --- a/src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt +++ b/src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt @@ -27,9 +27,7 @@ object VenvUtils { } @JvmStatic - fun getPythonVersionFromPyVenv(pyvenvCfgPath: Path): String { - val unknownVersion = "unknown" - + fun getPythonVersionFromPyVenv(pyvenvCfgPath: Path): String? { val props = Properties() try { @@ -37,14 +35,14 @@ object VenvUtils { props.load(reader) } } catch (e: IOException) { - return unknownVersion // file could not be read + return null // file could not be read } - val version = props.getProperty("version_info") + val version = props.getProperty("version") if (version != null) { return version.trim { it <= ' ' } } - return unknownVersion + return null } }