Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/com/github/pyvenvmanage/VenvUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ object VenvUtils {
}

@JvmStatic
fun getPythonVersionFromPyVenv(pyvenvCfgPath: Path): String {
val unknownVersion = "unknown"

fun getPythonVersionFromPyVenv(pyvenvCfgPath: Path): String? {
val props = Properties()

try {
Files.newBufferedReader(pyvenvCfgPath, StandardCharsets.UTF_8).use { reader ->
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
}
}
Loading