diff --git a/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt b/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt index c379bc1886d58..138634bef0925 100644 --- a/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt +++ b/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt @@ -16,6 +16,7 @@ import com.intellij.platform.ide.progress.withBackgroundProgress import com.intellij.util.SystemProperties import com.jetbrains.python.PyBundle import com.jetbrains.python.packaging.PyPackageManager +import com.jetbrains.python.packaging.common.PythonPackage import com.jetbrains.python.packaging.management.PythonPackageManager import com.jetbrains.python.pathValidation.PlatformAndRoot import com.jetbrains.python.pathValidation.ValidationRequest @@ -182,10 +183,25 @@ suspend fun poetryInstallPackage(sdk: Sdk, pkg: String, extraArgs: List) suspend fun poetryUninstallPackage(sdk: Sdk, pkg: String): Result = runPoetryWithSdk(sdk, "remove", pkg) @Internal -suspend fun poetryReloadPackages(sdk: Sdk): Result { - runPoetryWithSdk(sdk, "update").onFailure { return Result.failure(it) } - runPoetryWithSdk(sdk, "install", "--no-root").onFailure { return Result.failure(it) } - return runPoetryWithSdk(sdk, "show") +suspend fun poetryShowPackages(sdk: Sdk): Result> { + val output = runPoetryWithSdk(sdk, "show").getOrElse { + return Result.failure(it) + } + + return parsePoetryShow(output).let { Result.success(it) } +} + +@Internal +fun parsePoetryShow(input: String): List { + val result = mutableListOf() + input.split("\n").forEach { line -> + if (line.isNotBlank()) { + val packageInfo = line.trim().split(" ").map { it.trim() }.filter { it.isNotBlank() && it != "(!)"} + result.add(PythonPackage(packageInfo[0], packageInfo[1], false)) + } + } + + return result } /** diff --git a/python/src/com/jetbrains/python/sdk/poetry/PoetryPackageManager.kt b/python/src/com/jetbrains/python/sdk/poetry/PoetryPackageManager.kt index 0950c8e89c983..814c1ca22f96f 100644 --- a/python/src/com/jetbrains/python/sdk/poetry/PoetryPackageManager.kt +++ b/python/src/com/jetbrains/python/sdk/poetry/PoetryPackageManager.kt @@ -27,8 +27,7 @@ class PoetryPackageManager(project: Project, sdk: Sdk) : PythonPackageManager(pr override suspend fun uninstallPackageCommand(pkg: PythonPackage): Result = poetryUninstallPackage(sdk, pkg.name) override suspend fun reloadPackagesCommand(): Result> { - val output = poetryReloadPackages(sdk).getOrElse { return Result.failure(it) } - return Result.success(parsePoetryShow(output)) + return poetryShowPackages(sdk) } override suspend fun reloadPackages(): Result> { @@ -57,21 +56,6 @@ class PoetryPackageManager(project: Project, sdk: Sdk) : PythonPackageManager(pr /** * Parses the output of `poetry show` into a list of packages. */ -private fun parsePoetryShow(input: String): List { - val result = mutableListOf() - input.split("\n").forEach { line -> - if (line.isNotBlank()) { - val packageInfo = line.trim().split(" ").map { it.trim() }.filter { it.isNotBlank() } - result.add(PythonPackage(packageInfo[0], packageInfo[1], false)) - } - } - return result -} - -@TestOnly -fun parsePoetryShowTest(input: String): List { - return parsePoetryShow(input) -} @TestOnly fun parsePoetryShowOutdatedTest(input: String): Map {