mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
PY-79950 PyPackage: Improve performance of install packages.txt blockng EDT
GitOrigin-RevId: 6e882837949fc3ce5880645fd1ac9dea2450f811
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fff43d0cd0
commit
12b15f5c9e
@@ -21,6 +21,7 @@ import com.jetbrains.python.packaging.common.runPackagingOperationOrShowErrorDia
|
||||
import com.jetbrains.python.sdk.PythonSdkUpdater
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@ApiStatus.Experimental
|
||||
@@ -37,7 +38,9 @@ abstract class PythonPackageManager(val project: Project, val sdk: Sdk) {
|
||||
suspend fun installPackagesWithDialogOnError(packages: List<PythonPackageSpecification>, options: List<String>): Result<List<PythonPackage>> {
|
||||
packages.forEach { specification ->
|
||||
runPackagingOperationOrShowErrorDialog(sdk, PyBundle.message("python.new.project.install.failed.title", specification.name), specification.name) {
|
||||
installPackageCommand(specification, options)
|
||||
withContext(Dispatchers.IO) {
|
||||
installPackageCommand(specification, options)
|
||||
}
|
||||
}.onFailure {
|
||||
return Result.failure(it)
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ fun PythonRepositoryManager.createSpecification(
|
||||
name: String,
|
||||
versionSpec: String? = null,
|
||||
): PythonPackageSpecification? {
|
||||
val repository = packagesByRepository().firstOrNull { it.second.any { pkg -> normalizePackageName(pkg) == normalizePackageName(name) } }?.first
|
||||
val normalizePackageName = normalizePackageName(name)
|
||||
val repository = packagesByRepository().firstOrNull { it.second.contains(normalizePackageName) }?.first
|
||||
return repository?.createForcedSpecPackageSpecification(name, versionSpec)
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.intellij.codeInspection.util.IntentionFamilyName
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.module.Module
|
||||
@@ -146,16 +147,28 @@ private class InstallRequirementQuickFix(requirement: Requirement) : LocalQuickF
|
||||
|
||||
fun installPackages(project: Project, descriptor: ProblemDescriptor, requirements: List<Requirement>) {
|
||||
val file = descriptor.psiElement.containingFile ?: return
|
||||
val sdk = getPythonSdk(file) ?: return
|
||||
val manager = PythonPackageManager.forSdk(project, sdk)
|
||||
|
||||
val specifications = requirements.mapNotNull { requirement ->
|
||||
val versionSpec = if (requirement is NameReq) requirement.versionspec?.text else ""
|
||||
val name = requirement.displayName
|
||||
manager.repositoryManager.createSpecification(name, versionSpec)
|
||||
}
|
||||
val serviceScope = project.service<PyPackagingToolWindowService>().serviceScope
|
||||
serviceScope.launch(Dispatchers.Default) {
|
||||
val sdk = getPythonSdk(file) ?: return@launch
|
||||
|
||||
val nameVersions = readAction {
|
||||
requirements.map { requirement ->
|
||||
val versionSpec = if (requirement is NameReq) requirement.versionspec?.text else ""
|
||||
val name = requirement.displayName
|
||||
name to versionSpec
|
||||
}
|
||||
}
|
||||
|
||||
val manager = PythonPackageManager.forSdk(project, sdk)
|
||||
|
||||
val specifications = nameVersions.mapNotNull { (name, versionSpec) ->
|
||||
manager.repositoryManager.createSpecification(name, versionSpec)
|
||||
}
|
||||
|
||||
if (specifications.isEmpty())
|
||||
return@launch
|
||||
|
||||
project.service<PyPackagingToolWindowService>().serviceScope.launch(Dispatchers.IO) {
|
||||
manager.installPackagesWithDialogOnError(specifications, emptyList())
|
||||
DaemonCodeAnalyzer.getInstance(project).restart(file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user