Skip to content

Commit 5ffcfa4

Browse files
committed
feat(python): add Python build system provider #308
1 parent 44ae52a commit 5ffcfa4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cc.unitmesh.python.provider
2+
3+
import cc.unitmesh.devti.provider.BuildSystemProvider
4+
import cc.unitmesh.devti.provider.DevPackage
5+
import cc.unitmesh.devti.template.context.DockerfileContext
6+
import com.intellij.openapi.project.Project
7+
import com.intellij.psi.PsiFile
8+
import com.jetbrains.python.packaging.PyRequirement
9+
import com.jetbrains.python.packaging.PyRequirementParser
10+
11+
class PythonBuildSystemProvider : BuildSystemProvider() {
12+
override fun collect(project: Project): DockerfileContext? = null
13+
14+
override fun collectDependencies(project: Project, psiFile: PsiFile): List<DevPackage> {
15+
if (psiFile.language.id != "Python") {
16+
return emptyList()
17+
}
18+
19+
val reqs: List<PyRequirement> = PyRequirementParser.fromFile(psiFile.virtualFile)
20+
21+
return reqs.map {
22+
DevPackage(
23+
type = "Python",
24+
name = it.name,
25+
version = it.versionSpecs.firstOrNull()?.version ?: ""
26+
)
27+
}
28+
}
29+
}

pycharm/src/main/resources/cc.unitmesh.pycharm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
<chatContextProvider implementation="cc.unitmesh.python.PythonFrameworkContextProvider"/>
2121

22+
<buildSystemProvider implementation="cc.unitmesh.python.provider.PythonBuildSystemProvider"/>
23+
2224
<!-- <devFlowProvider-->
2325
<!-- language="Python"-->
2426
<!-- implementation="cc.unitmesh.python.provider.PythonAutoDevFlow"/>-->

0 commit comments

Comments
 (0)