@@ -25,7 +25,6 @@ import kotlinx.coroutines.runBlocking
2525import org.jetbrains.kotlin.idea.util.application.runWriteAction
2626import org.jetbrains.kotlin.idea.util.module
2727import org.jetbrains.kotlin.idea.util.projectStructure.sdk
28- import org.jetbrains.kotlin.konan.file.File
2928import org.utbot.common.PathUtil.toPath
3029import org.utbot.common.appendHtmlLine
3130import org.utbot.framework.UtSettings
@@ -335,7 +334,8 @@ fun getDirectoriesForSysPath(
335334 file.fromImports.forEach { importTarget ->
336335 importTarget.resolveImportSourceCandidates().forEach {
337336 val directory = it.parent
338- if (directory is PsiDirectory ) {
337+ val isRelativeImport = importTarget.relativeLevel > 0 // If we have `from . import a` we don't need to add syspath
338+ if (directory is PsiDirectory && ! isRelativeImport) {
339339 // If we have `from a.b.c import d` we need to add syspath to module `a` only
340340 val additionalLevel = importTarget.importSourceQName?.componentCount?.dec() ? : 0
341341 directory.topParent(additionalLevel)?.let { dir ->
@@ -347,7 +347,9 @@ fun getDirectoriesForSysPath(
347347
348348 // Select modules only from this project but not from installation directory
349349 importedPaths.forEach {
350- if (it.isProjectSubmodule(ancestor) && ! it.path.split(File .separator).contains(" site-packages" )) {
350+ val path = it.toNioPath()
351+ val hasSitePackages = (0 until(path.nameCount)).any { i -> path.subpath(i, i+ 1 ).toString() == " site-packages" }
352+ if (it.isProjectSubmodule(ancestor) && ! hasSitePackages) {
351353 sources.add(it)
352354 }
353355 }
0 commit comments