diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkConfigurationCollector.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkConfigurationCollector.kt index 1e226c784abe..632d70a11835 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkConfigurationCollector.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkConfigurationCollector.kt @@ -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) diff --git a/python/src/com/jetbrains/python/extensions/PythonProjectExt.kt b/python/src/com/jetbrains/python/extensions/PythonProjectExt.kt deleted file mode 100644 index b10d274037a1..000000000000 --- a/python/src/com/jetbrains/python/extensions/PythonProjectExt.kt +++ /dev/null @@ -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 } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/packaging/pipenv/PyPipEnvPackageManagementService.kt b/python/src/com/jetbrains/python/packaging/pipenv/PyPipEnvPackageManagementService.kt deleted file mode 100644 index 2df73cc3f4c3..000000000000 --- a/python/src/com/jetbrains/python/packaging/pipenv/PyPipEnvPackageManagementService.kt +++ /dev/null @@ -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? = null - - override fun canInstallToUser() = false - - @RequiresBackgroundThread - override fun getAllPackages(): List { - PyPIPackageUtil.INSTANCE.loadAdditionalPackages(runBlockingCancellable { pipFileLockSources(sdk) }, false) - return allPackagesCached - } - - @RequiresBackgroundThread - override fun reloadAllPackages(): List { - PyPIPackageUtil.INSTANCE.loadAdditionalPackages(runBlockingCancellable { pipFileLockSources(sdk) }, true) - return allPackagesCached - } - - @RequiresBackgroundThread - override fun getAllPackagesCached(): List = - 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?) { - 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) - } - -} \ No newline at end of file diff --git a/python/src/com/jetbrains/python/sdk/add/v2/EnvironmentCreatorUv.kt b/python/src/com/jetbrains/python/sdk/add/v2/EnvironmentCreatorUv.kt index 16fc8bd64631..f475fd72b17d 100644 --- a/python/src/com/jetbrains/python/sdk/add/v2/EnvironmentCreatorUv.kt +++ b/python/src/com/jetbrains/python/sdk/add/v2/EnvironmentCreatorUv.kt @@ -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 = model.state.uvExecutable diff --git a/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt b/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt index b7b0136597dc..ae8822328559 100644 --- a/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt +++ b/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt @@ -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 { diff --git a/python/src/com/jetbrains/python/sdk/pipenv/PipenvFilesUtils.kt b/python/src/com/jetbrains/python/sdk/pipenv/PipenvFilesUtils.kt index 0d48991d2c79..9185b451f898 100644 --- a/python/src/com/jetbrains/python/sdk/pipenv/PipenvFilesUtils.kt +++ b/python/src/com/jetbrains/python/sdk/pipenv/PipenvFilesUtils.kt @@ -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 = - 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 { - // 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 = diff --git a/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt b/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt index f672357ff545..b0441132e717 100644 --- a/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt +++ b/python/src/com/jetbrains/python/sdk/poetry/PoetryCommandExecutor.kt @@ -186,15 +186,6 @@ suspend fun poetryInstallPackage(sdk: Sdk, pkg: String, extraArgs: List) @Internal suspend fun poetryUninstallPackage(sdk: Sdk, pkg: String): Result = runPoetryWithSdk(sdk, "remove", pkg) -@Internal -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() diff --git a/python/src/com/jetbrains/python/sdk/poetry/PoetryFilesUtils.kt b/python/src/com/jetbrains/python/sdk/poetry/PoetryFilesUtils.kt index cdfaa1f870b1..686bbe1e12cd 100644 --- a/python/src/com/jetbrains/python/sdk/poetry/PoetryFilesUtils.kt +++ b/python/src/com/jetbrains/python/sdk/poetry/PoetryFilesUtils.kt @@ -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") diff --git a/python/src/com/jetbrains/python/sdk/poetry/PyPoetryPackageManagementService.kt b/python/src/com/jetbrains/python/sdk/poetry/PyPoetryPackageManagementService.kt deleted file mode 100644 index f5d4a8e2e42e..000000000000 --- a/python/src/com/jetbrains/python/sdk/poetry/PyPoetryPackageManagementService.kt +++ /dev/null @@ -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 - */ - -class PyPoetryPackageManagementService(project: Project, sdk: Sdk) : PyPackageManagementService(project, sdk) { - override fun getAllRepositories(): List? = null - - override fun canInstallToUser() = false - - override fun getAllPackages(): List { - PyPIPackageUtil.INSTANCE.loadAdditionalPackages(poetrySources, false) - return allPackagesCached - } - - override fun reloadAllPackages(): List { - PyPIPackageUtil.INSTANCE.loadAdditionalPackages(poetrySources, true) - return allPackagesCached - } - - override fun getAllPackagesCached(): List = - 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?) { - 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 - // TODO parse pyproject.toml for tool.poetry.source.url - get() = listOf(POETRY_DEFAULT_SOURCE_URL) -} \ No newline at end of file diff --git a/python/src/com/jetbrains/python/sdk/uv/UvExt.kt b/python/src/com/jetbrains/python/sdk/uv/UvExt.kt index f5a5cd93e9a4..9c55ff8c4531 100644 --- a/python/src/com/jetbrains/python/sdk/uv/UvExt.kt +++ b/python/src/com/jetbrains/python/sdk/uv/UvExt.kt @@ -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"