Skip to content

Commit 4ad0b4e

Browse files
authored
Fix python version display (#77)
1 parent fe3e19d commit 4ad0b4e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/main/kotlin/com/github/pyvenvmanage/VenvProjectViewNodeDecorator.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class VenvProjectViewNodeDecorator : ProjectViewNodeDecorator {
1515
val pyVenvCfgPath = VenvUtils.getPyVenvCfg(node.getVirtualFile())
1616
if (pyVenvCfgPath != null) {
1717
val pythonVersion = VenvUtils.getPythonVersionFromPyVenv(pyvenvCfgPath = pyVenvCfgPath)
18-
val fileName: String? = data.getPresentableText()
19-
data.clearText()
20-
data.addText(fileName, SimpleTextAttributes.REGULAR_ATTRIBUTES)
21-
data.addText(" [" + pythonVersion + "]", SimpleTextAttributes.GRAY_ATTRIBUTES)
18+
if (pythonVersion != null) {
19+
val fileName: String? = data.getPresentableText()
20+
data.clearText()
21+
data.addText(fileName, SimpleTextAttributes.REGULAR_ATTRIBUTES)
22+
data.addText(" [$pythonVersion]", SimpleTextAttributes.GRAY_ATTRIBUTES)
23+
}
2224
data.setIcon(Virtualenv)
2325
}
2426
}

src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ object VenvUtils {
2727
}
2828

2929
@JvmStatic
30-
fun getPythonVersionFromPyVenv(pyvenvCfgPath: Path): String {
31-
val unknownVersion = "unknown"
32-
30+
fun getPythonVersionFromPyVenv(pyvenvCfgPath: Path): String? {
3331
val props = Properties()
3432

3533
try {
3634
Files.newBufferedReader(pyvenvCfgPath, StandardCharsets.UTF_8).use { reader ->
3735
props.load(reader)
3836
}
3937
} catch (e: IOException) {
40-
return unknownVersion // file could not be read
38+
return null // file could not be read
4139
}
4240

43-
val version = props.getProperty("version_info")
41+
val version = props.getProperty("version")
4442
if (version != null) {
4543
return version.trim { it <= ' ' }
4644
}
4745

48-
return unknownVersion
46+
return null
4947
}
5048
}

0 commit comments

Comments
 (0)