mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 09:12:22 +07:00
remove code duplication for poetry; PY-75983
(cherry picked from commit 3498c4b1da0f2f791940bd8f476e24701edd199c) GitOrigin-RevId: 30e7d12a822031722d20373bef86d20d1d2ed95d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
42af44caf9
commit
dc79f6b09c
@@ -31,8 +31,8 @@ open class PythonPackage(val name: String, val version: String, val isEditableMo
|
||||
}
|
||||
}
|
||||
|
||||
open class PythonOutdatedPackage(name: String, version: String, isEditableMode: Boolean, val latestVersion: String)
|
||||
: PythonPackage(name, version, isEditableMode)
|
||||
open class PythonOutdatedPackage(name: String, version: String, val latestVersion: String)
|
||||
: PythonPackage(name, version, false)
|
||||
{}
|
||||
|
||||
interface PythonPackageDetails {
|
||||
|
||||
@@ -3,11 +3,11 @@ package com.jetbrains.python.sdk.poetry
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.jetbrains.python.packaging.common.PythonOutdatedPackage
|
||||
import com.jetbrains.python.packaging.common.PythonPackage
|
||||
import com.jetbrains.python.packaging.common.PythonPackageSpecification
|
||||
import com.jetbrains.python.packaging.management.PythonPackageManager
|
||||
import com.jetbrains.python.packaging.pip.PipRepositoryManager
|
||||
import java.util.regex.Pattern
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
|
||||
class PoetryPackageManager(project: Project, sdk: Sdk) : PythonPackageManager(project, sdk) {
|
||||
@@ -16,7 +16,7 @@ class PoetryPackageManager(project: Project, sdk: Sdk) : PythonPackageManager(pr
|
||||
override val repositoryManager: PipRepositoryManager = PipRepositoryManager(project, sdk)
|
||||
|
||||
@Volatile
|
||||
private var outdatedPackages: Map<String, PoetryOutdatedVersion> = emptyMap()
|
||||
private var outdatedPackages: Map<String, PythonOutdatedPackage> = emptyMap()
|
||||
|
||||
override suspend fun installPackageCommand(specification: PythonPackageSpecification, options: List<String>): Result<String> =
|
||||
poetryInstallPackage(sdk, specification.getVersionForPoetry(), options)
|
||||
@@ -36,7 +36,7 @@ class PoetryPackageManager(project: Project, sdk: Sdk) : PythonPackageManager(pr
|
||||
return super.reloadPackages()
|
||||
}
|
||||
|
||||
internal fun getOutdatedPackages(): Map<String, PoetryOutdatedVersion> = outdatedPackages
|
||||
internal fun getOutdatedPackages(): Map<String, PythonOutdatedPackage> = outdatedPackages
|
||||
|
||||
/**
|
||||
* Updates the list of outdated packages by running the Poetry command
|
||||
@@ -68,21 +68,12 @@ private fun parsePoetryShow(input: String): List<PythonPackage> {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the output of `poetry show --outdated` into a list of packages.
|
||||
*/
|
||||
private fun parsePoetryShowOutdated(input: String): Map<String, PoetryOutdatedVersion> =
|
||||
input
|
||||
.lines()
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
.mapNotNull { line ->
|
||||
line.split(Pattern.compile(" +"))
|
||||
.takeIf { it.size > 3 }?.let { it[0] to PoetryOutdatedVersion(it[1], it[2]) }
|
||||
}.toMap()
|
||||
@TestOnly
|
||||
fun parsePoetryShowTest(input: String): List<PythonPackage> {
|
||||
return parsePoetryShow(input)
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
fun parsePoetryShowTest(input: String): List<PythonPackage> = parsePoetryShow(input)
|
||||
|
||||
@TestOnly
|
||||
fun parsePoetryShowOutdatedTest(input: String): Map<String, PoetryOutdatedVersion> = parsePoetryShowOutdated(input)
|
||||
fun parsePoetryShowOutdatedTest(input: String): Map<String, PythonOutdatedPackage> {
|
||||
return parsePoetryShowOutdated(input)
|
||||
}
|
||||
@@ -61,9 +61,9 @@ internal class PoetryPackageVersionsInspection : LocalInspectionTool() {
|
||||
val packageName = keyValue.key.text
|
||||
val outdatedVersion = (PythonPackageManager.forSdk(
|
||||
module.project, sdk) as? PoetryPackageManager)?.let { it.getOutdatedPackages()[packageName] }
|
||||
if (outdatedVersion is PoetryOutdatedVersion) {
|
||||
if (outdatedVersion != null) {
|
||||
val message = PyBundle.message("python.sdk.inspection.message.version.outdated.latest",
|
||||
packageName, outdatedVersion.currentVersion, outdatedVersion.latestVersion)
|
||||
packageName, outdatedVersion.version, outdatedVersion.latestVersion)
|
||||
holder.registerProblem(keyValue, message, ProblemHighlightType.WARNING)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// 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.poetry
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.intellij.execution.ExecutionException
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.module.Module
|
||||
@@ -12,18 +11,9 @@ import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.jetbrains.python.PyBundle
|
||||
import com.jetbrains.python.packaging.*
|
||||
import com.jetbrains.python.packaging.common.PythonOutdatedPackage
|
||||
import com.jetbrains.python.sdk.PythonSdkType
|
||||
import com.jetbrains.python.sdk.associatedModuleDir
|
||||
import java.util.regex.Pattern
|
||||
|
||||
|
||||
/**
|
||||
* This source code is edited by @koxudaxi Koudai Aono <koxudaxi@gmail.com>
|
||||
*/
|
||||
|
||||
data class PoetryOutdatedVersion(
|
||||
@SerializedName("currentVersion") var currentVersion: String,
|
||||
@SerializedName("latestVersion") var latestVersion: String)
|
||||
|
||||
|
||||
class PyPoetryPackageManager(sdk: Sdk) : PyPackageManager(sdk) {
|
||||
@@ -34,7 +24,7 @@ class PyPoetryPackageManager(sdk: Sdk) : PyPackageManager(sdk) {
|
||||
|
||||
private var requirements: List<PyRequirement>? = null
|
||||
|
||||
private var outdatedPackages: Map<String, PoetryOutdatedVersion> = emptyMap()
|
||||
private var outdatedPackages: Map<String, PythonOutdatedPackage> = emptyMap()
|
||||
|
||||
override fun installManagement() {}
|
||||
|
||||
@@ -178,16 +168,4 @@ class PyPoetryPackageManager(sdk: Sdk) : PyPackageManager(sdk) {
|
||||
}
|
||||
return Pair(pyPackages.distinct().toList(), pyRequirements.distinct().toList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the output of `poetry show --outdated` into a list of packages.
|
||||
*/
|
||||
private fun parsePoetryShowOutdated(input: String): Map<String, PoetryOutdatedVersion> {
|
||||
return input
|
||||
.lines()
|
||||
.mapNotNull { line ->
|
||||
line.split(Pattern.compile(" +"))
|
||||
.takeIf { it.size > 3 }?.let { it[0] to PoetryOutdatedVersion(it[1], it[2]) }
|
||||
}.toMap()
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,13 @@ import com.jetbrains.python.PyBundle
|
||||
import com.jetbrains.python.PythonModuleTypeBase
|
||||
import com.jetbrains.python.sdk.*
|
||||
import com.jetbrains.python.icons.PythonIcons
|
||||
import com.jetbrains.python.packaging.common.PythonOutdatedPackage
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import java.io.FileNotFoundException
|
||||
import java.nio.file.Path
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
// TODO: Provide a special icon for poetry
|
||||
@@ -86,4 +88,15 @@ private suspend fun setUpPoetry(projectPathString: String, python: String?, inst
|
||||
}
|
||||
|
||||
return Result.success(Path.of(getPythonExecutable(poetryExecutablePathString)))
|
||||
}
|
||||
|
||||
fun parsePoetryShowOutdated(input: String): Map<String, PythonOutdatedPackage> {
|
||||
return input
|
||||
.lines()
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
.mapNotNull { line ->
|
||||
line.split(Pattern.compile(" +"))
|
||||
.takeIf { it.size > 3 }?.let { it[0] to PythonOutdatedPackage(it[0], it[1], it[2]) }
|
||||
}.toMap()
|
||||
}
|
||||
@@ -14,12 +14,10 @@ import com.jetbrains.python.sdk.uv.impl.createUvCli
|
||||
import com.jetbrains.python.sdk.uv.impl.createUvLowLevel
|
||||
import java.nio.file.Path
|
||||
|
||||
internal class UvPackageManager(project: Project, sdk: Sdk) : PythonPackageManager(project, sdk) {
|
||||
internal class UvPackageManager(project: Project, sdk: Sdk, val uv: UvLowLevel) : PythonPackageManager(project, sdk) {
|
||||
override var installedPackages: List<PythonPackage> = emptyList()
|
||||
override val repositoryManager: PythonRepositoryManager = PipRepositoryManager(project, sdk)
|
||||
|
||||
private val uv: UvLowLevel = createUvLowLevel(Path.of(project.basePath!!), createUvCli())
|
||||
|
||||
@Volatile
|
||||
var outdatedPackages: Map<String, PythonOutdatedPackage> = emptyMap()
|
||||
|
||||
@@ -62,6 +60,11 @@ internal class UvPackageManager(project: Project, sdk: Sdk) : PythonPackageManag
|
||||
|
||||
class UvPackageManagerProvider : PythonPackageManagerProvider {
|
||||
override fun createPackageManagerForSdk(project: Project, sdk: Sdk): PythonPackageManager? {
|
||||
return if (sdk.isUv) UvPackageManager(project, sdk) else null
|
||||
if (!sdk.isUv) {
|
||||
return null
|
||||
}
|
||||
|
||||
val uv = createUvLowLevel(Path.of(project.basePath!!), createUvCli())
|
||||
return UvPackageManager(project, sdk, uv)
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ internal class UvLowLevelImpl(val cwd: Path, val uvCli: UvCli) : UvLowLevel {
|
||||
val mapper = jacksonObjectMapper()
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
val packages = mapper.readValue<List<OutdatedPackageInfo>>(out).map {
|
||||
PythonOutdatedPackage(it.name, it.version, true, it.latest_version)
|
||||
PythonOutdatedPackage(it.name, it.version, it.latest_version)
|
||||
}
|
||||
|
||||
return Result.success(packages)
|
||||
|
||||
Reference in New Issue
Block a user