mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Python: remove unused symbols
GitOrigin-RevId: 7de5aee028900d0e764f682721603141fe063dc6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f70146c36
commit
037bf38733
+1
-1
@@ -21,7 +21,7 @@ object PySdkConfigurationCollector : CounterUsagesCollector() {
|
||||
CREATED
|
||||
}
|
||||
|
||||
internal enum class PipEnvResult { CREATION_FAILURE, NO_EXECUTABLE, NO_EXECUTABLE_FILE, CREATED }
|
||||
internal enum class PipEnvResult { CREATION_FAILURE, CREATED }
|
||||
|
||||
internal fun logVirtualEnvDialog(project: Project, permitted: Boolean, source: Source, baseSdk: InputData) {
|
||||
venvDialogEvent.log(project, permitted.asDialogResult, source, baseSdk)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:JvmName("PythonProjectExt")
|
||||
|
||||
package com.jetbrains.python.extensions
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.modules
|
||||
import com.jetbrains.python.sdk.PythonSdkType
|
||||
import com.jetbrains.python.sdk.PythonSdkUtil
|
||||
|
||||
val Project.hasPython: Boolean
|
||||
get() = modules.asSequence()
|
||||
.map { PythonSdkUtil.findPythonSdk(it) }
|
||||
.any { it != null && it.sdkType is PythonSdkType }
|
||||
@@ -1,62 +0,0 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.packaging.pipenv
|
||||
|
||||
import com.intellij.execution.ExecutionException
|
||||
import com.intellij.openapi.progress.runBlockingCancellable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
|
||||
import com.intellij.webcore.packaging.RepoPackage
|
||||
import com.jetbrains.python.packaging.PyPIPackageUtil
|
||||
import com.jetbrains.python.packaging.PyPackageManagerUI
|
||||
import com.jetbrains.python.packaging.PyRequirementParser
|
||||
import com.jetbrains.python.packaging.ui.PyPackageManagementService
|
||||
import com.jetbrains.python.sdk.pipenv.pipFileLockSources
|
||||
|
||||
class PyPipEnvPackageManagementService(project: Project, sdk: Sdk) : PyPackageManagementService(project, sdk) {
|
||||
override fun getAllRepositories(): List<String>? = null
|
||||
|
||||
override fun canInstallToUser() = false
|
||||
|
||||
@RequiresBackgroundThread
|
||||
override fun getAllPackages(): List<RepoPackage> {
|
||||
PyPIPackageUtil.INSTANCE.loadAdditionalPackages(runBlockingCancellable { pipFileLockSources(sdk) }, false)
|
||||
return allPackagesCached
|
||||
}
|
||||
|
||||
@RequiresBackgroundThread
|
||||
override fun reloadAllPackages(): List<RepoPackage> {
|
||||
PyPIPackageUtil.INSTANCE.loadAdditionalPackages(runBlockingCancellable { pipFileLockSources(sdk) }, true)
|
||||
return allPackagesCached
|
||||
}
|
||||
|
||||
@RequiresBackgroundThread
|
||||
override fun getAllPackagesCached(): List<RepoPackage> =
|
||||
PyPIPackageUtil.INSTANCE.getAdditionalPackages(runBlockingCancellable { pipFileLockSources(sdk) })
|
||||
|
||||
override fun installPackage(
|
||||
repoPackage: RepoPackage,
|
||||
version: String?,
|
||||
forceUpgrade: Boolean,
|
||||
extraOptions: String?,
|
||||
listener: Listener,
|
||||
installToUser: Boolean,
|
||||
) {
|
||||
val ui = PyPackageManagerUI(project, sdk, object : PyPackageManagerUI.Listener {
|
||||
override fun started() {
|
||||
listener.operationStarted(repoPackage.name)
|
||||
}
|
||||
|
||||
override fun finished(exceptions: List<ExecutionException>?) {
|
||||
listener.operationFinished(repoPackage.name, toErrorDescription(exceptions, sdk))
|
||||
}
|
||||
})
|
||||
val requirement = when {
|
||||
version != null -> PyRequirementParser.fromLine("${repoPackage.name}==$version")
|
||||
else -> PyRequirementParser.fromLine(repoPackage.name)
|
||||
} ?: return
|
||||
val extraArgs = extraOptions?.split(" +".toRegex()) ?: emptyList()
|
||||
ui.install(listOf(requirement), extraArgs)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import com.jetbrains.python.sdk.uv.setupUvSdkUnderProgress
|
||||
import com.jetbrains.python.statistics.InterpreterType
|
||||
import java.nio.file.Path
|
||||
|
||||
class EnvironmentCreatorUv(model: PythonMutableTargetAddInterpreterModel, private val moduleOrProject: ModuleOrProject?) : CustomNewEnvironmentCreator("uv", model) {
|
||||
class EnvironmentCreatorUv(model: PythonMutableTargetAddInterpreterModel) : CustomNewEnvironmentCreator("uv", model) {
|
||||
override val interpreterType: InterpreterType = InterpreterType.UV
|
||||
override val executable: ObservableMutableProperty<String> = model.state.uvExecutable
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class PythonAddCustomInterpreter(val model: PythonMutableTargetAddInterpreterMod
|
||||
CONDA to CondaNewEnvironmentCreator(model, errorSink),
|
||||
PIPENV to EnvironmentCreatorPip(model),
|
||||
POETRY to EnvironmentCreatorPoetry(model, moduleOrProject),
|
||||
UV to EnvironmentCreatorUv(model, moduleOrProject),
|
||||
UV to EnvironmentCreatorUv(model),
|
||||
)
|
||||
|
||||
private val existingInterpreterSelectors = buildMap {
|
||||
|
||||
@@ -42,12 +42,10 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.io.FileNotFoundException
|
||||
import java.nio.file.Path
|
||||
|
||||
const val PIP_FILE: String = "Pipfile"
|
||||
const val PIP_FILE_LOCK: String = "Pipfile.lock"
|
||||
const val PIPENV_DEFAULT_SOURCE_URL: String = "https://pypi.org/simple"
|
||||
const val PIPENV_PATH_SETTING: String = "PyCharm.Pipenv.Path"
|
||||
|
||||
/**
|
||||
@@ -56,13 +54,6 @@ const val PIPENV_PATH_SETTING: String = "PyCharm.Pipenv.Path"
|
||||
@Internal
|
||||
suspend fun pipFile(module: Module) = withContext(Dispatchers.IO) { findAmongRoots(module, PIP_FILE) }
|
||||
|
||||
/**
|
||||
* The URLs of package sources configured in the Pipfile.lock of the module associated with this SDK.
|
||||
*/
|
||||
@Internal
|
||||
suspend fun pipFileLockSources(sdk: Sdk): List<String> =
|
||||
sdk.parsePipFileLock().getOrNull()?.meta?.sources?.mapNotNull { it.url } ?: listOf(PIPENV_DEFAULT_SOURCE_URL)
|
||||
|
||||
/**
|
||||
* Resolves and returns the list of Python requirements from the Pipfile.lock of the SDK's associated module.
|
||||
*
|
||||
@@ -199,12 +190,6 @@ private suspend fun getPipFileLockRequirements(virtualFile: VirtualFile, package
|
||||
return packages + devPackages
|
||||
}
|
||||
|
||||
private suspend fun Sdk.parsePipFileLock(): Result<PipFileLock> {
|
||||
// TODO: Log errors if Pipfile.lock is not found
|
||||
val file = pipFileLock() ?: return Result.failure(FileNotFoundException("Pipfile.lock not found"))
|
||||
return parsePipFileLock(file)
|
||||
}
|
||||
|
||||
private val gson = Gson()
|
||||
|
||||
private suspend fun parsePipFileLock(virtualFile: VirtualFile): Result<PipFileLock> =
|
||||
|
||||
@@ -186,15 +186,6 @@ suspend fun poetryInstallPackage(sdk: Sdk, pkg: String, extraArgs: List<String>)
|
||||
@Internal
|
||||
suspend fun poetryUninstallPackage(sdk: Sdk, pkg: String): Result<String> = runPoetryWithSdk(sdk, "remove", pkg)
|
||||
|
||||
@Internal
|
||||
suspend fun poetryShowPackages(sdk: Sdk): Result<List<PythonPackage>> {
|
||||
val output = runPoetryWithSdk(sdk, "show").getOrElse {
|
||||
return Result.failure(it)
|
||||
}
|
||||
|
||||
return parsePoetryShow(output).let { Result.success(it) }
|
||||
}
|
||||
|
||||
@Internal
|
||||
fun parsePoetryShow(input: String): List<PythonPackage> {
|
||||
val result = mutableListOf<PythonPackage>()
|
||||
|
||||
@@ -57,7 +57,6 @@ import java.util.concurrent.ConcurrentMap
|
||||
const val PY_PROJECT_TOML: String = "pyproject.toml"
|
||||
const val POETRY_LOCK: String = "poetry.lock"
|
||||
const val POETRY_TOML: String = "poetry.toml"
|
||||
const val POETRY_DEFAULT_SOURCE_URL: String = "https://pypi.org/simple"
|
||||
|
||||
val LOGGER = Logger.getInstance("#com.jetbrains.python.sdk.poetry")
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.sdk.poetry
|
||||
|
||||
import com.intellij.execution.ExecutionException
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.webcore.packaging.RepoPackage
|
||||
import com.jetbrains.python.packaging.PyPIPackageUtil
|
||||
import com.jetbrains.python.packaging.PyPackageManagerUI
|
||||
import com.jetbrains.python.packaging.PyRequirementParser
|
||||
import com.jetbrains.python.packaging.ui.PyPackageManagementService
|
||||
|
||||
|
||||
/**
|
||||
* This source code is edited by @koxudaxi Koudai Aono <koxudaxi@gmail.com>
|
||||
*/
|
||||
|
||||
class PyPoetryPackageManagementService(project: Project, sdk: Sdk) : PyPackageManagementService(project, sdk) {
|
||||
override fun getAllRepositories(): List<String>? = null
|
||||
|
||||
override fun canInstallToUser() = false
|
||||
|
||||
override fun getAllPackages(): List<RepoPackage> {
|
||||
PyPIPackageUtil.INSTANCE.loadAdditionalPackages(poetrySources, false)
|
||||
return allPackagesCached
|
||||
}
|
||||
|
||||
override fun reloadAllPackages(): List<RepoPackage> {
|
||||
PyPIPackageUtil.INSTANCE.loadAdditionalPackages(poetrySources, true)
|
||||
return allPackagesCached
|
||||
}
|
||||
|
||||
override fun getAllPackagesCached(): List<RepoPackage> =
|
||||
PyPIPackageUtil.INSTANCE.getAdditionalPackages(poetrySources)
|
||||
|
||||
override fun installPackage(repoPackage: RepoPackage,
|
||||
version: String?,
|
||||
forceUpgrade: Boolean,
|
||||
extraOptions: String?,
|
||||
listener: Listener,
|
||||
installToUser: Boolean) {
|
||||
val ui = PyPackageManagerUI(project, sdk, object : PyPackageManagerUI.Listener {
|
||||
override fun started() {
|
||||
listener.operationStarted(repoPackage.name)
|
||||
}
|
||||
|
||||
override fun finished(exceptions: List<ExecutionException?>?) {
|
||||
listener.operationFinished(repoPackage.name, toErrorDescription(exceptions, sdk))
|
||||
}
|
||||
})
|
||||
val requirement = when {
|
||||
version != null -> PyRequirementParser.fromLine("${repoPackage.name}==$version")
|
||||
else -> PyRequirementParser.fromLine(repoPackage.name)
|
||||
} ?: return
|
||||
val extraArgs = extraOptions?.split(" +".toRegex()) ?: emptyList()
|
||||
ui.install(listOf(requirement), extraArgs)
|
||||
}
|
||||
|
||||
/**
|
||||
* The URLs of package sources configured in the Pipfile.lock of the module associated with this SDK.
|
||||
*/
|
||||
private val poetrySources: List<String>
|
||||
// TODO parse pyproject.toml for tool.poetry.source.url
|
||||
get() = listOf(POETRY_DEFAULT_SOURCE_URL)
|
||||
}
|
||||
@@ -22,12 +22,6 @@ import kotlin.io.path.pathString
|
||||
internal val Sdk.isUv: Boolean
|
||||
get() = sdkAdditionalData is UvSdkAdditionalData
|
||||
|
||||
internal suspend fun uvLock(module: Module): VirtualFile? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
findAmongRoots(module, UV_LOCK)
|
||||
}
|
||||
}
|
||||
|
||||
internal suspend fun pyProjectToml(module: Module): VirtualFile? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
findAmongRoots(module, PY_PROJECT_TOML)
|
||||
@@ -39,7 +33,6 @@ internal fun suggestedSdkName(basePath: Path): @NlsSafe String {
|
||||
}
|
||||
|
||||
val UV_ICON: Icon = PythonIcons.UV
|
||||
const val UV_LOCK: String = "uv.lock"
|
||||
|
||||
// FIXME: move pyprojecttoml code out to common package
|
||||
const val PY_PROJECT_TOML: String = "pyproject.toml"
|
||||
|
||||
Reference in New Issue
Block a user