PY-66252 Introduce a new registry key "disable.python.cache.update" to conditionally disable automatic updating of PyPI package cache and ranking on project startup.

Delete unnecessary checks of project-level python.

(cherry picked from commit 7b38138885ac7036895ff6c4dcb9f86358d1ecd5)

IJ-MR-148661

GitOrigin-RevId: 7bb045be17944f51224fd774b3db67f21a510a51
This commit is contained in:
Timur Malanin
2024-11-07 23:40:34 +00:00
committed by intellij-monorepo-bot
parent 9a50d834e7
commit 329fa5cf88
3 changed files with 12 additions and 25 deletions

View File

@@ -639,6 +639,11 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
defaultValue="[IN_EXPERIMENT*|ENABLED|DISABLED]"
description="Enable ML ranking in quick fix for missing imports"/>
<registryKey key="disable.python.cache.update"
defaultValue="false"
restartRequired="false"
description="Disables automatic updating of PyPI package cache and ranking on project startup."/>
<feedback.idleFeedbackSurvey implementation="com.jetbrains.python.statistics.feedback.PythonJobSurvey"/>
<statistics.counterUsagesCollector implementationClass="com.jetbrains.python.statistics.feedback.PythonJobStatisticsCollector"/>
<backgroundPostStartupActivity implementation="com.jetbrains.python.statistics.feedback.PythonFirstLaunchChecker"/>
@@ -1020,4 +1025,5 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
<numericContainerPopupCustomizer implementation="com.jetbrains.python.debugger.pydev.tables.PyNumericContainerPopupCustomizerDefault"/>
<pyDebugAsyncioCustomizer implementation="com.jetbrains.python.debugger.PyDebugAsyncioCustomizerDefault"/>
</extensions>
</idea-plugin>

View File

@@ -3,16 +3,11 @@ package com.jetbrains.python.packaging;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.startup.StartupActivity;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import com.intellij.openapi.util.registry.Registry;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
@@ -29,9 +24,7 @@ final class PyPackagesUpdater implements StartupActivity, DumbAware {
@Override
public void runActivity(@NotNull Project project) {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
if (!checkNeeded(project)) return;
if (ApplicationManager.getApplication().isUnitTestMode() || Registry.is("disable.python.cache.update") || !checkNeeded()) return;
try {
PyPIPackageUtil.INSTANCE.updatePyPICache();
@@ -41,18 +34,7 @@ final class PyPackagesUpdater implements StartupActivity, DumbAware {
}
}
private static boolean hasPython(Project project) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
Sdk sdk = PythonSdkUtil.findPythonSdk(module);
if (sdk != null && sdk.getSdkType() instanceof PythonSdkType) {
return true;
}
}
return false;
}
private static boolean checkNeeded(Project project) {
if (!hasPython(project)) return false;
private static boolean checkNeeded() {
PyPackageService service = PyPackageService.getInstance();
if (service.PYPI_REMOVED) return false;
try {

View File

@@ -6,7 +6,7 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.jetbrains.python.extensions.hasPython
import com.intellij.openapi.util.registry.Registry
import com.jetbrains.python.packaging.PyPIPackageRanking
import com.jetbrains.python.packaging.pip.PypiPackageCache
import kotlinx.coroutines.Dispatchers
@@ -15,12 +15,11 @@ import kotlinx.coroutines.withContext
class PythonPackagesUpdater : ProjectActivity {
override suspend fun execute(project: Project) {
if (ApplicationManager.getApplication().isUnitTestMode || !project.hasPython) return
if (ApplicationManager.getApplication().isUnitTestMode || Registry.`is`("disable.python.cache.update")) return
withContext(Dispatchers.IO) {
thisLogger().debug("Updating PyPI cache and ranking")
service<PyPIPackageRanking>().reload()
service<PypiPackageCache>().loadCache()
}
}
}
}