Skip to content

Remove builtins modules from sys.path #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,18 @@ fun getDirectoriesForSysPath(
if (element != null) {
val directory = element.parent
if (directory is PsiDirectory) {
sources.add(directory.virtualFile)
if (sources.any { source ->
val sourcePath = source.canonicalPath
if (source.isDirectory && sourcePath != null) {
directory.virtualFile.canonicalPath?.startsWith(sourcePath) ?: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider improving the code

} else {
false
}
}) {
sources.add(directory.virtualFile)
}
}
}

}
}

Expand All @@ -298,7 +306,7 @@ fun getDirectoriesForSysPath(
importPath += "."

return Pair(
sources.map { it.path }.toSet(),
sources.map { it.path.replace("\\", "\\\\") }.toSet(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract such things as a utility function. And consider situations when we are already have two back slashes in the path.

"${importPath}${file.name}".removeSuffix(".py").toPath().joinToString(".").replace("/", File.separator)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object TemporaryFileManager {
}

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