File tree Expand file tree Collapse file tree 5 files changed +79
-41
lines changed
kotlin/com/github/pyvenvmanage Expand file tree Collapse file tree 5 files changed +79
-41
lines changed Original file line number Diff line number Diff line change 1
1
.gradle
2
2
.idea
3
3
.intellijPlatform
4
+ .kotlin
4
5
build
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package com.github.pyvenvmanage
2
+
3
+ import com.intellij.ide.projectView.PresentationData
4
+ import com.intellij.ide.projectView.ProjectViewNode
5
+ import com.intellij.ide.projectView.ProjectViewNodeDecorator
6
+ import com.intellij.ui.SimpleTextAttributes
7
+
8
+ import com.jetbrains.python.icons.PythonIcons.Python.Virtualenv
9
+
10
+ class VenvProjectViewNodeDecorator : ProjectViewNodeDecorator {
11
+ override fun decorate (
12
+ node : ProjectViewNode <* >,
13
+ data : PresentationData ,
14
+ ) {
15
+ val pyVenvCfgPath = VenvUtils .getPyVenvCfg(node.getVirtualFile())
16
+ if (pyVenvCfgPath != null ) {
17
+ 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 )
22
+ data.setIcon(Virtualenv )
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ package com.github.pyvenvmanage
2
+
3
+ import java.io.IOException
4
+ import java.nio.charset.StandardCharsets
5
+ import java.nio.file.Files
6
+ import java.nio.file.Path
7
+ import java.util.Properties
8
+
9
+ import com.intellij.openapi.vfs.VirtualFile
10
+
11
+ import com.jetbrains.python.sdk.PythonSdkUtil
12
+
13
+ object VenvUtils {
14
+ @JvmStatic
15
+ fun getPyVenvCfg (file : VirtualFile ? ): Path ? {
16
+ if (file != null && file.isDirectory()) {
17
+ val venvRootPath = file.getPath()
18
+ val pythonExecutable = PythonSdkUtil .getPythonExecutable(venvRootPath)
19
+ if (pythonExecutable != null ) {
20
+ val pyvenvFile = file.findChild(" pyvenv.cfg" )
21
+ if (pyvenvFile != null ) {
22
+ return Path .of(pyvenvFile.getPath())
23
+ }
24
+ }
25
+ }
26
+ return null
27
+ }
28
+
29
+ @JvmStatic
30
+ fun getPythonVersionFromPyVenv (pyvenvCfgPath : Path ): String {
31
+ val unknownVersion = " unknown"
32
+
33
+ val props = Properties ()
34
+
35
+ try {
36
+ Files .newBufferedReader(pyvenvCfgPath, StandardCharsets .UTF_8 ).use { reader ->
37
+ props.load(reader)
38
+ }
39
+ } catch (e: IOException ) {
40
+ return unknownVersion // file could not be read
41
+ }
42
+
43
+ val version = props.getProperty(" version_info" )
44
+ if (version != null ) {
45
+ return version.trim { it <= ' ' }
46
+ }
47
+
48
+ return unknownVersion
49
+ }
50
+ }
Original file line number Diff line number Diff line change 7
7
<depends >com.intellij.modules.platform</depends >
8
8
9
9
<extensions defaultExtensionNs =" com.intellij" >
10
- <notificationGroup id =" Python SDK change " displayType = " BALLOON " />
11
- < iconProvider implementation = " com.github.pyvenvmanage.VenvIconProvider " />
12
- <iconLayerProvider implementation =" com.github.pyvenvmanage.VenvIconProvider " />
10
+ <notificationGroup id =" SDK changed notification "
11
+ displayType = " BALLOON " />
12
+ <projectViewNodeDecorator implementation =" com.github.pyvenvmanage.VenvProjectViewNodeDecorator " />
13
13
</extensions >
14
14
15
15
<actions >
You can’t perform that action at this time.
0 commit comments