Skip to content

Commit

Permalink
Add minimal version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
tamarinvs19 committed Nov 10, 2023
1 parent 0e7dbea commit 6c8372e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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 java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import kotlin.io.path.Path
Expand Down Expand Up @@ -124,16 +125,24 @@ object PythonDialogProcessor {
title = "Python test generation error"
)
} else {
val dialog = createDialog(
project,
elementsToShow,
focusedElement,
pythonPath,
)
if (!dialog.showAndGet()) {
return
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)
}
createTests(project, dialog.model)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.utbot.python.utils

object PythonVersionChecker {
private val minimalPythonVersion = Triple(3, 10, 0)

fun checkPythonVersion(pythonPath: String): Boolean {
try {
val version = runCommand(listOf(
pythonPath,
"-c",
"\"import sys; print('.'.join(map(str, sys.version_info[:3])))\""
))
if (version.exitValue == 0) {
val (major, minor, patch) = version.stdout.split(".")
return (major.toInt() >= minimalPythonVersion.first && minor.toInt() >= minimalPythonVersion.second && patch.toInt() >= minimalPythonVersion.third)
}
return false
} catch (_: Exception) {
return false
}
}
}

0 comments on commit 6c8372e

Please sign in to comment.