From 376cb69c39e367648f7a3bc247720a9cbdae33ce Mon Sep 17 00:00:00 2001 From: Morgan Bartholomew Date: Tue, 17 Jun 2025 13:22:32 +0200 Subject: [PATCH] [python] PY-81866 don't spam stub notifications while it's installing GitOrigin-RevId: 5f8374cc36bff759e1a0a6a01917d71b8b15d836 --- .../typing/PyStubPackagesAdvertiser.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/typing/PyStubPackagesAdvertiser.kt b/python/src/com/jetbrains/python/codeInsight/typing/PyStubPackagesAdvertiser.kt index 4959d5ba5918..883ab66611ef 100644 --- a/python/src/com/jetbrains/python/codeInsight/typing/PyStubPackagesAdvertiser.kt +++ b/python/src/com/jetbrains/python/codeInsight/typing/PyStubPackagesAdvertiser.kt @@ -13,6 +13,7 @@ import com.intellij.notification.NotificationAction import com.intellij.notification.NotificationGroupManager import com.intellij.notification.NotificationType import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.components.ComponentManager import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleUtilCore import com.intellij.openapi.project.Project @@ -27,6 +28,7 @@ import com.jetbrains.python.codeInsight.typing.PyStubPackagesAdvertiserCache.Com import com.jetbrains.python.inspections.PyInspection import com.jetbrains.python.inspections.PyInspectionVisitor import com.jetbrains.python.inspections.quickfix.PyInstallRequirementsFix +import com.jetbrains.python.inspections.requirement.RunningPackagingTasksListener import com.jetbrains.python.packaging.* import com.jetbrains.python.packaging.requirement.PyRequirementRelation import com.jetbrains.python.psi.PyFile @@ -111,7 +113,7 @@ private class PyStubPackagesAdvertiser : PyInspection() { if (availablePackages.isEmpty()) return val ignoredStubPackages = (IGNORE + ignoredPackages).mapNotNull { PyRequirementParser.fromLine(it) } - val cache = ApplicationManager.getApplication().getService(PyStubPackagesAdvertiserCache::class.java).forSdk(sdk) + val cache = ApplicationManager.getApplication().getService().forSdk(sdk) val forcedToLoad = processForcedPackages(file, sources, module, sdk, packageManager, ignoredStubPackages, cache) val checkedToLoad = processCheckedPackages(file, sources, module, sdk, packageManager, ignoredStubPackages, cache) @@ -161,7 +163,12 @@ private class PyStubPackagesAdvertiser : PyInspection() { val (sourcesToLoad, cached) = splitIntoNotCachedAndCached(checkedSourcesToProcess(sources), cache) - val (reqs, args) = toRequirementsAndExtraArgs(cached, ignoredStubPackages) + val (unfilteredReqs, args) = toRequirementsAndExtraArgs(cached, ignoredStubPackages) + + val status = file.project.getService() + + val reqs = unfilteredReqs.filterNot { status.markedAsInstalling(it.name) } + if (reqs.isNotEmpty()) { val plural = reqs.size > 1 val reqsToString = PyPackageUtil.requirementsToString(reqs) @@ -272,13 +279,13 @@ private class PyStubPackagesAdvertiser : PyInspection() { val project = module.project val stubPkgNamesToInstall = reqs.mapTo(mutableSetOf()) { it.name } - object : PyPackageManagerUI.Listener { + val installationListener = object : RunningPackagingTasksListener(module) { override fun started() { - project.getService(PyStubPackagesInstallingStatus::class.java).markAsInstalling(stubPkgNamesToInstall) + project.getService().markAsInstalling(stubPkgNamesToInstall) } - override fun finished(exceptions: MutableList?) { - val status = project.getService(PyStubPackagesInstallingStatus::class.java) + override fun finished(exceptions: List) { + val status = project.getService() val stubPkgsToUninstall = PyStubPackagesCompatibilityInspection .findIncompatibleRuntimeToStubPackages(sdk) { it.name in stubPkgNamesToInstall } @@ -311,7 +318,7 @@ private class PyStubPackagesAdvertiser : PyInspection() { } val name = PyBundle.message("code.insight.stub.packages.install.requirements.fix.name", reqs.size) - return PyInstallRequirementsFix(name, sdk, reqs, args) + return PyInstallRequirementsFix(name, sdk, reqs, args, installationListener) } private fun createIgnorePackagesQuickFix(reqs: List): LocalQuickFix {