Skip to content

Commit 5d5896a

Browse files
tamarinvs19denis-fokin
authored andcommitted
Remove builtins modules from sys.path (#1574)
(cherry picked from commit 7402d71)
1 parent ea91440 commit 5d5896a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,18 @@ fun getDirectoriesForSysPath(
286286
if (element != null) {
287287
val directory = element.parent
288288
if (directory is PsiDirectory) {
289-
sources.add(directory.virtualFile)
289+
if (sources.any { source ->
290+
val sourcePath = source.canonicalPath
291+
if (source.isDirectory && sourcePath != null) {
292+
directory.virtualFile.canonicalPath?.startsWith(sourcePath) ?: false
293+
} else {
294+
false
295+
}
296+
}) {
297+
sources.add(directory.virtualFile)
298+
}
290299
}
291300
}
292-
293301
}
294302
}
295303

@@ -298,7 +306,7 @@ fun getDirectoriesForSysPath(
298306
importPath += "."
299307

300308
return Pair(
301-
sources.map { it.path }.toSet(),
309+
sources.map { it.path.replace("\\", "\\\\") }.toSet(),
302310
"${importPath}${file.name}".removeSuffix(".py").toPath().joinToString(".").replace("/", File.separator)
303311
)
304312
}

utbot-python/src/main/kotlin/org/utbot/python/utils/TemporaryFileManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object TemporaryFileManager {
1515
}
1616

1717
fun assignTemporaryFile(fileName_: String? = null, tag: String? = null, addToCleaner: Boolean = true): File {
18-
val fileName = fileName_ ?: ("${nextId++}_" + (tag ?: ""))
18+
val fileName = fileName_ ?: ("tmp_${nextId++}_" + (tag ?: ""))
1919
val fullpath = Paths.get(tmpDirectory.toString(), fileName)
2020
val result = fullpath.toFile()
2121
if (addToCleaner)

0 commit comments

Comments
 (0)