Skip to content

Commit

Permalink
Fix problem with Pycharm plugin #2720 (#2721)
Browse files Browse the repository at this point in the history
* Create new module for Pycharm plugin

* Change github script publish-plugin-from-branch.yml
  • Loading branch information
tamarinvs19 authored Dec 14, 2023
1 parent e66620d commit 7f46841
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-plugin-from-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
directory: utbot-intellij-main
- plugin_type: PY
extra_options: "-PideType=PY -PprojectType=Ultimate"
directory: utbot-intellij-python
directory: utbot-python-pycharm
runs-on: ubuntu-20.04
container: unittestbot/java-env:java17-zulu-jdk-gradle7.6.1-kotlinc1.8.0
steps:
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ golandVersion=2023.2
# ALL, NOJS
buildType=NOJS

# IDE types that supports appropriate language
javaIde=IC,IU
pythonIde=IC,IU,PC,PY
jsIde=IU,PY
jsBuild=ALL
goIde=IU,GO

# IDE types that require Pycharm plugin
pycharmIdeType=PC,PY

# In order to run Android Studio instead of IntelliJ Community, specify the path to your Android Studio installation
#androidStudioPath=your_path_to_android_studio

Expand Down
8 changes: 7 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ val ultimateEdition: String by settings

val ideType: String by settings
val buildType: String by settings
val pycharmIdeType: String by settings

val javaIde: String by settings
val pythonIde: String by settings
Expand Down Expand Up @@ -65,6 +66,12 @@ include("utbot-spring-analyzer")
include("utbot-spring-sample")
include("utbot-spring-test")

if (pycharmIdeType.split(",").contains(ideType)) {
include("utbot-python-pycharm")
} else {
include("utbot-intellij-main")
}

if (javaIde.split(",").contains(ideType)) {
include("utbot-intellij")
}
Expand Down Expand Up @@ -93,4 +100,3 @@ if (projectType == ultimateEdition) {
}

include("utbot-light")
include("utbot-intellij-main")
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ import org.utbot.intellij.plugin.settings.Settings
import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater
import org.utbot.python.PythonMethodHeader
import org.utbot.python.PythonTestGenerationConfig
import org.utbot.python.utils.RequirementsInstaller
import org.utbot.python.TestFileInformation
import org.utbot.python.framework.api.python.PythonClassId
import org.utbot.python.framework.codegen.PythonCgLanguageAssistant
import org.utbot.python.newtyping.mypy.dropInitFile
import org.utbot.python.utils.PythonVersionChecker
import org.utbot.python.utils.RequirementsInstaller
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import kotlin.io.path.Path
Expand Down Expand Up @@ -125,24 +124,16 @@ object PythonDialogProcessor {
title = "Python test generation error"
)
} else {
if (!PythonVersionChecker.checkPythonVersion(pythonPath)) {
showErrorDialogLater(
project,
message = "Please use Python 3.10 or newer",
title = "Python test generation error"
)
} else {
val dialog = createDialog(
project,
elementsToShow,
focusedElement,
pythonPath,
)
if (!dialog.showAndGet()) {
return
}
createTests(project, dialog.model)
val dialog = createDialog(
project,
elementsToShow,
focusedElement,
pythonPath,
)
if (!dialog.showAndGet()) {
return
}
createTests(project, dialog.model)
}
}

Expand Down
123 changes: 123 additions & 0 deletions utbot-python-pycharm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
val semVer: String? by rootProject
val kotlinLoggingVersion: String? by rootProject

// === IDE settings ===
val projectType: String by rootProject
val communityEdition: String by rootProject
val ultimateEdition: String by rootProject

val ideType: String by rootProject
val androidStudioPath: String? by rootProject

val ideaVersion: String? by rootProject
val pycharmVersion: String? by rootProject
val golandVersion: String? by rootProject

val javaIde: String? by rootProject
val pythonIde: String? by rootProject
val jsIde: String? by rootProject
val goIde: String? by rootProject

val ideVersion = when(ideType) {
"PC", "PY" -> pycharmVersion
"GO" -> golandVersion
else -> ideaVersion
}

val pythonCommunityPluginVersion: String? by rootProject
val pythonUltimatePluginVersion: String? by rootProject
val goPluginVersion: String? by rootProject

// https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-pluginxml-file
val ideTypeOrAndroidStudio = if (androidStudioPath == null) ideType else "IC"

project.tasks.asMap["runIde"]?.enabled = false
// === IDE settings ===

plugins {
id("org.jetbrains.intellij") version "1.13.1"
}

tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = freeCompilerArgs + listOf("-Xallow-result-return-type", "-Xsam-conversions=class")
allWarningsAsErrors = false
}
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

patchPluginXml {
sinceBuild.set("223")
untilBuild.set("232.*")
version.set(semVer)
}
}

dependencies {
implementation(group = "io.github.microutils", name = "kotlin-logging", version = kotlinLoggingVersion)
implementation(project(":utbot-ui-commons"))

//Family
implementation(project(":utbot-intellij-python"))
}

intellij {

val androidPlugins = listOf("org.jetbrains.android")

val jvmPlugins = mutableListOf(
"java"
)

val kotlinPlugins = listOf(
"org.jetbrains.kotlin"
)

androidStudioPath?.let { jvmPlugins += androidPlugins }

val pythonCommunityPlugins = listOf(
"PythonCore:${pythonCommunityPluginVersion}"
)

val pythonUltimatePlugins = listOf(
"Pythonid:${pythonUltimatePluginVersion}"
)

val jsPlugins = listOf(
"JavaScript"
)

val goPlugins = listOf(
"org.jetbrains.plugins.go:${goPluginVersion}"
)

val mavenUtilsPlugins = listOf(
"org.jetbrains.idea.maven"
)

val basePluginSet = jvmPlugins + kotlinPlugins + mavenUtilsPlugins + androidPlugins

plugins.set(
when (projectType) {
communityEdition -> basePluginSet + pythonCommunityPlugins
ultimateEdition -> when (ideType) {
"IC" -> basePluginSet + pythonCommunityPlugins
"IU" -> basePluginSet + pythonUltimatePlugins + jsPlugins + goPlugins
"PC" -> pythonCommunityPlugins
"PY" -> pythonUltimatePlugins + jsPlugins
"GO" -> goPlugins
else -> basePluginSet
}
else -> basePluginSet
}
)

version.set(ideVersion)
type.set(ideType)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package org.utbot.intellij.plugin.python.ui.actions
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import org.utbot.intellij.plugin.language.agnostic.LanguageAssistant
import org.utbot.intellij.plugin.settings.Settings

class GenerateTestsAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
Expand Down

0 comments on commit 7f46841

Please sign in to comment.