Poetry: Cleanup

Add general service for running coroutines in com.jetbrains.python.sdk.
Delete PoetryConfigLoader.kt and PoetryConfigService.kt.


Merge-request: IJ-MR-145094
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: 474bbee10812bbe4ce5fd2db96602f12e9fa023b
This commit is contained in:
Egor Eliseev
2024-09-19 13:44:34 +00:00
committed by intellij-monorepo-bot
parent ab29832b0d
commit bffe31025a
7 changed files with 14 additions and 70 deletions

View File

@@ -548,8 +548,6 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
<!-- Poetry -->
<editorFactoryListener implementation="com.jetbrains.python.sdk.poetry.PyProjectTomlWatcher"/>
<backgroundPostStartupActivity implementation="com.jetbrains.python.sdk.poetry.PoetryConfigLoader" order="last"/>
<!-- Targets API -->
<registryKey key="enable.conda.on.targets" defaultValue="false" description="Enables Conda configuration on targets."/>
<registryKey key="python.packaging.tool.use.project.location.as.working.dir" defaultValue="false"

View File

@@ -5,14 +5,12 @@ import com.intellij.execution.RunCanceledByUserException
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.CapturingProcessHandler
import com.intellij.execution.process.ProcessOutput
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.util.NlsContexts
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
import com.jetbrains.python.packaging.IndicatedProcessOutputListener
import com.jetbrains.python.packaging.PyExecutionException
import kotlinx.coroutines.CoroutineScope
import java.nio.file.Path
import kotlin.io.path.absolutePathString
import kotlin.io.path.pathString
@@ -21,12 +19,6 @@ internal object Logger {
val LOG = logger<Logger>()
}
/**
* Used for CoroutineScope in com.jetbrains.python.sdk
*/
@Service(Service.Level.PROJECT)
internal class PythonSdkRunCommandService(val cs: CoroutineScope)
/**
* Runs a command line operation in a background thread.
*

View File

@@ -0,0 +1,11 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.sdk
import com.intellij.openapi.components.Service
import kotlinx.coroutines.CoroutineScope
/**
* Used for CoroutineScope in com.jetbrains.python.sdk
*/
@Service(Service.Level.APP)
internal class PythonSdkCoroutineService(val cs: CoroutineScope)

View File

@@ -145,7 +145,7 @@ private fun runCommand(projectPath: Path, command: String, vararg args: String):
}
internal fun runPoetryInBackground(module: Module, args: List<String>, @NlsSafe description: String) {
module.project.service<PythonSdkRunCommandService>().cs.launch {
service<PythonSdkCoroutineService>().cs.launch {
withBackgroundProgress(module.project, "$description...", true) {
val sdk = module.pythonSdk ?: return@withBackgroundProgress
try {

View File

@@ -1,23 +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.poetry
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.smartReadAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.jetbrains.python.statistics.sdks
class PoetryConfigLoader : ProjectActivity {
override suspend fun execute(project: Project) {
if (ApplicationManager.getApplication().isUnitTestMode) return
if (project.isDisposed) return
smartReadAction(project) {
project.sdks
.filterNot { it.isPoetry }
.filter { PoetryConfigService.getInstance(project).poetryVirtualenvPaths.contains(it.homePath) }
.forEach { it.isPoetry = true }
}
}
}

View File

@@ -1,34 +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.poetry
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.project.Project
import com.intellij.util.xmlb.XmlSerializerUtil
/**
* This source code is edited by @koxudaxi Koudai Aono <koxudaxi@gmail.com>
*/
@Service(Service.Level.PROJECT)
@State(name = "PoetryConfigService", storages = [Storage("poetry.xml")])
class PoetryConfigService : PersistentStateComponent<PoetryConfigService> {
var poetryVirtualenvPaths = mutableSetOf<String>()
override fun getState(): PoetryConfigService {
return this
}
override fun loadState(config: PoetryConfigService) {
XmlSerializerUtil.copyBean(config, this)
}
companion object {
fun getInstance(project: Project): PoetryConfigService {
return project.getService(PoetryConfigService::class.java)
}
}
}

View File

@@ -35,7 +35,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiElementFilter
import com.intellij.psi.util.PsiTreeUtil
import com.jetbrains.python.psi.LanguageLevel
import com.jetbrains.python.sdk.PythonSdkRunCommandService
import com.jetbrains.python.sdk.PythonSdkCoroutineService
import com.jetbrains.python.sdk.PythonSdkUpdater
import com.jetbrains.python.sdk.add.v2.PythonSelectableInterpreter
import com.jetbrains.python.sdk.poetry.VersionType.Companion.getVersionType
@@ -210,7 +210,7 @@ private class PyProjectTomlPostStartupActivity : ProjectActivity {
readAction {
tomlFile.findDocument()?.addDocumentListener(object : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
project.service<PythonSdkRunCommandService>().cs.launch {
service<PythonSdkCoroutineService>().cs.launch {
val newVersion = findPythonVersion(tomlFile, project) ?: return@launch
val oldVersion = PyProjectTomlPythonVersionsService.instance.getVersionString(module)
if (oldVersion != newVersion) {