Revert "[python] Allow modification of python SDK in headless mode through environment keys"

This reverts commit 3a202c64

GitOrigin-RevId: f6d6b26c10ba253c1a180a63d4939f4bd5e8f7a0
This commit is contained in:
Konstantin Nisht
2023-10-19 16:23:08 +00:00
committed by intellij-monorepo-bot
parent 1e1f6191f7
commit 87722de8ea
8 changed files with 4 additions and 123 deletions
@@ -1,5 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("ObservationUtil")
package com.intellij.ide.observation
import com.intellij.configurationStore.saveProjectsAndApp
@@ -54,10 +54,8 @@ class GradleHeadlessLoggingProjectActivity(val scope: CoroutineScope) : ProjectA
private fun addStateNotificationListener(project: Project, progressManager: ExternalSystemProgressNotificationManager) {
val notificationListener = GradleWarmupConfigurator.StateNotificationListener(project, scope)
progressManager.addNotificationListener(notificationListener)
scope.launch {
awaitCancellationAndInvoke {
progressManager.removeNotificationListener(notificationListener)
}
scope.awaitCancellationAndInvoke {
progressManager.removeNotificationListener(notificationListener)
}
}
@@ -66,10 +64,8 @@ class GradleHeadlessLoggingProjectActivity(val scope: CoroutineScope) : ProjectA
val externalAnnotationsProgressListener = GradleWarmupConfigurator.StateExternalAnnotationNotificationListener()
externalAnnotationsNotificationManager.addNotificationListener(externalAnnotationsProgressListener)
scope.launch {
awaitCancellationAndInvoke {
externalAnnotationsNotificationManager.removeNotificationListener(externalAnnotationsProgressListener)
}
scope.awaitCancellationAndInvoke {
externalAnnotationsNotificationManager.removeNotificationListener(externalAnnotationsProgressListener)
}
}
}
@@ -1183,9 +1183,6 @@ python.add.sdk.panel.name.virtualenv.environment=Virtualenv environment
python.add.sdk.conda.executable.path.is.empty=Conda executable path is empty
environment.key.description.python.interpreter.path=Absolute path to python interpreter.\n\
If missing, then no python interpreter will be configured for a project.
python.requirements.version.label=Version in requirements:
python.requirements.version.separator.no.version=Don't specify version
python.requirements.version.separator.strong.eq=Strong equality
@@ -44,9 +44,6 @@
<extensionPoint qualifiedName="Pythonid.pythonDocumentationQuickInfoProvider"
interface="com.jetbrains.python.documentation.PythonDocumentationQuickInfoProvider"
dynamic="true"/>
<extensionPoint qualifiedName="Pythonid.pythonHeadlessSdkModifier"
interface="com.jetbrains.python.sdk.headless.PythonHeadlessSdkModifier"
dynamic="true"/>
</extensionPoints>
<extensions defaultExtensionNs="com.intellij">
<projectService serviceInterface="com.jetbrains.python.psi.types.TypeEvalContextCache"
@@ -341,8 +341,6 @@
<projectService serviceImplementation="com.jetbrains.python.console.PythonConsoleToolWindow"/>
<toolWindowExtractorMode id="Python Console" mode="mirror"/>
<environmentKeyProvider implementation="com.jetbrains.python.sdk.headless.PythonEnvironmentKeyProvider"/>
<postStartupActivity implementation="com.jetbrains.python.sdk.headless.PythonHeadlessSdkProjectActivity"/>
<activityInProgressPredicate implementation="com.jetbrains.python.sdk.headless.PythonInProgressPredicate"/>
<projectConfigurable groupId="build" groupWeight="119" id="reference.idesettings.debugger.python"
@@ -1,19 +0,0 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.sdk.headless
import com.intellij.ide.environment.EnvironmentKey
import com.intellij.ide.environment.EnvironmentKeyProvider
import com.intellij.openapi.project.Project
import com.jetbrains.python.PyBundle
import java.util.function.Supplier
class PythonEnvironmentKeyProvider : EnvironmentKeyProvider {
object Keys {
val sdkKey: EnvironmentKey = EnvironmentKey.create("python.interpreter.path")
}
override val knownKeys: Map<EnvironmentKey, Supplier<String>> =
mapOf(Keys.sdkKey to PyBundle.messagePointer("environment.key.description.python.interpreter.path"))
override suspend fun getRequiredKeys(project: Project): List<EnvironmentKey> = emptyList()
}
@@ -1,25 +0,0 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.sdk.headless
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import org.jetbrains.annotations.ApiStatus
/**
* Allows to modify the used python SDK for a project.
* The motivation here is that SDK is handled differently depending on the distribution of the IDE:
* In IDEA, Python SDK is added via the facet machinery, whereas in PyCharm it is simply a module SDK.
*/
@ApiStatus.Internal
interface PythonHeadlessSdkModifier {
companion object {
val EP_NAME: ExtensionPointName<PythonHeadlessSdkModifier> = ExtensionPointName("Pythonid.pythonHeadlessSdkModifier")
}
/**
* @return if this extension managed to modify SDK. If `false`, default PyCharm logic will be used, which sets the SDK on module level.
*/
fun setSdk(project: Project, sdk: Sdk) : Boolean
}
@@ -1,62 +0,0 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.sdk.headless
import com.intellij.ide.environment.EnvironmentService
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.components.serviceAsync
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.util.registry.Registry
import com.jetbrains.python.sdk.PyDetectedSdk
import com.jetbrains.python.sdk.findAllPythonSdks
import com.jetbrains.python.sdk.pythonSdk
import com.jetbrains.python.sdk.setup
class PythonHeadlessSdkProjectActivity : ProjectActivity {
override suspend fun execute(project: Project) = project.serviceAsync<PythonInProgressService>().trackConfigurationActivity {
setupPythonSdk(project)
}
private suspend fun setupPythonSdk(project: Project) {
if (!ApplicationManager.getApplication().isHeadlessEnvironment) {
return
}
if (!Registry.`is`("ide.warmup.use.predicates")) {
return
}
val interpreterPath = serviceAsync<EnvironmentService>().getEnvironmentValue(PythonEnvironmentKeyProvider.Keys.sdkKey, "")
if (interpreterPath == "") {
thisLogger().info("No interpreter is configured for python files")
return
}
val modules = ModuleManager.getInstance(project).modules
if (modules.any { it.pythonSdk != null }) {
return
}
val baseDir = project.guessProjectDir() ?: return
val pythonSdk = when (val preliminarySdk = findAllPythonSdks(baseDir.toNioPath()).find { it.homePath == interpreterPath }) {
is PyDetectedSdk -> preliminarySdk.setup(listOf(*ProjectJdkTable.getInstance().getAllJdks()))
else -> preliminarySdk
} ?: return
try {
writeAction {
ProjectJdkTable.getInstance().addJdk(pythonSdk)
}
} catch (e : IllegalStateException) {
// sdk is already there.
}
for (pythonHeadlessSdkModifier in PythonHeadlessSdkModifier.EP_NAME.extensionList) {
if (pythonHeadlessSdkModifier.setSdk(project, pythonSdk)) {
return
}
}
for (module in ModuleManager.getInstance(project).modules) {
module.pythonSdk = pythonSdk
}
}
}