diff --git a/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/pythons.kt b/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/pythons.kt index d28143d7187e..093ad68fe6c4 100644 --- a/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/pythons.kt +++ b/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/pythons.kt @@ -9,24 +9,9 @@ class Python internal constructor(val pyenvDefinition: String, object Pythons { private val allPythons: ArrayList = ArrayList() - @Synchronized - internal fun createPython(pyenvDefinition: String, name: String, revision: String, packages: List): Python { - return Python(pyenvDefinition, name, revision, packages).also { - allPythons.add(it) - } - } - @Synchronized fun getPythons(): List { return allPythons.toList() } - val BlackJobLibTenserFlowPython311 = createPython("3.11.7", - "black-joblib-tenserflow", - "1", - listOf("black == 23.1.0", "joblib", "tensorflow")) - val CondaWithPyTorch = createPython("Miniconda3-latest", - "conda-pytorch", - "1", - listOf("pytorch")) } \ No newline at end of file diff --git a/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/setup.kt b/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/setup.kt index 4f8f910276c3..4d2e6f259003 100644 --- a/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/setup.kt +++ b/python/build/src/org/jetbrains/intellij/build/pycharm/pythons/setup.kt @@ -30,7 +30,6 @@ private val arch: String = System.getProperty("os.arch").lowercase().let { arch private const val pyEnvUrl = "https://github.com/pyenv/pyenv/archive/master.zip" private const val pyEnvWinUrl = "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -private val spaceUrl = "https://jetbrains.team/p/pyqa/packages/files/pythons" private val pipOptions = arrayOf("--trusted-host", "pypi.python.org", "--trusted-host", "pypi.org", "--trusted-host", "files.pythonhosted.org") val Python.directoryName: String get() = "$pyenvDefinition-$name-$revision-$os-$arch" diff --git a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/annotation/HuggingFaceEntityIdentitiers.kt b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/annotation/HuggingFaceEntityIdentitiers.kt deleted file mode 100644 index 0c30036a43ea..000000000000 --- a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/annotation/HuggingFaceEntityIdentitiers.kt +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.python.community.impl.huggingFace.annotation - -import org.jetbrains.annotations.ApiStatus - -@ApiStatus.Internal @JvmInline value class HuggingFaceModelIdentifier(val value: String) -@ApiStatus.Internal @JvmInline value class HuggingFaceDatasetIdentifier(val value: String) -@ApiStatus.Internal @JvmInline value class HuggingFaceEntityIdentifier(val value: String) diff --git a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCardsUsageCollector.kt b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCardsUsageCollector.kt index 8e436f995184..a3b5cc66902c 100644 --- a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCardsUsageCollector.kt +++ b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCardsUsageCollector.kt @@ -30,7 +30,7 @@ object HuggingFaceCardsUsageCollector: CounterUsagesCollector() { // PY-70535 P enum class ActiveFileType { PY, IPYNB } enum class ModelChoiceEntryPointType { CONTEXT_MENU } // will be extended later - enum class ModelChoiceDialogClosedResultType { USE_MODEL, CANCEL, CLOSE } + enum class ModelChoiceDialogClosedResultType { USE_MODEL, CLOSE } enum class CacheManagementActionSource { CONTEXT_MENU, TOOLBAR } enum class DialogWindowResult { OK, CANCEL } diff --git a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCoroutine.kt b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCoroutine.kt index 8dccd91ddf8b..e93ab56a78f3 100644 --- a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCoroutine.kt +++ b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceCoroutine.kt @@ -2,7 +2,6 @@ package com.intellij.python.community.impl.huggingFace.service import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.application.EDT import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import com.intellij.platform.util.coroutines.childScope @@ -14,13 +13,10 @@ import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal class HuggingFaceCoroutine(coroutineScope: CoroutineScope) { val ioScope = coroutineScope.childScope(context = Dispatchers.IO) - val edtScope = coroutineScope.childScope(context = Dispatchers.EDT) object Utils { val ioScope: CoroutineScope get() = ApplicationManager.getApplication().service().ioScope - val edtScope: CoroutineScope - get() = ApplicationManager.getApplication().service().edtScope } } diff --git a/python/pydevSrc/src/com/jetbrains/python/console/pydev/PydevXmlRpcClient.kt b/python/pydevSrc/src/com/jetbrains/python/console/pydev/PydevXmlRpcClient.kt deleted file mode 100644 index e92f2f062337..000000000000 --- a/python/pydevSrc/src/com/jetbrains/python/console/pydev/PydevXmlRpcClient.kt +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -// Licensed under the terms of the Eclipse Public License (EPL). -package com.jetbrains.python.console.pydev - -import com.intellij.openapi.diagnostic.Logger -import com.intellij.openapi.progress.EmptyProgressIndicator -import com.intellij.openapi.progress.ProcessCanceledException -import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.openapi.progress.ProgressManager -import com.intellij.util.net.NetUtils -import org.apache.xmlrpc.* -import java.net.MalformedURLException -import java.net.URL -import java.util.* -import java.util.concurrent.Semaphore -import java.util.concurrent.TimeUnit - -/** - * Subclass of XmlRpcClient that will monitor the process so that if the process is destroyed, we stop waiting - * for messages from it. - - * @author Fabio - */ -class PydevXmlRpcClient -/** - * Constructor (see fields description) - */ -@Throws(MalformedURLException::class) -constructor(private val process: Process, hostname: String?, port: Int) : IPydevXmlRpcClient { - - - /** - * Internal xml-rpc client (responsible for the actual communication with the server) - */ - private val impl: XmlRpcClient - private val requestSynchronizer = Semaphore(1, true) - - - init { - XmlRpc.setDefaultInputEncoding("UTF8") //even though it uses UTF anyway - impl = XmlRpcClientLite(hostname ?: NetUtils.getLocalHostString(), port) - impl.maxThreads = 1 - } - - constructor(process: Process, port: Int) : this(process = process, hostname = null, port = port) - - - override fun execute(command: String, args: Array): Any { - return execute(command, args, TIME_LIMIT) - } - - /** - * Executes a command in the server. - * - * - * Within this method, we should be careful about being able to return if the server dies. - * If we wanted to have a timeout, this would be the place to add it. - - * @return the result from executing the given command in the server. - */ - @Throws(XmlRpcException::class) - override fun execute(command: String, args: Array, timeoutMillis: Long): Any { - - val result = arrayOf(null) - val started = System.currentTimeMillis() - /* Try to leave at least 'MIN_TIME_SLICE' time for actual execution - if not possible then divide the wait times evenly - */ - val semTimeout = maxOf(timeoutMillis - MIN_TIME_SLICE, MIN_TIME_SLICE / 2) - val progress = ProgressManager.getInstance().progressIndicator ?: EmptyProgressIndicator() - try { - if (!requestSynchronizer.tryAcquireWithIndicator(progress, timeoutMillis = semTimeout)) { - throw XmlRpcException(-1, "Timeout while connecting to server") - } - } - catch (e: ProcessCanceledException) { - throw e - } - //make an async call so that we can keep track of not actually having an answer. - try { - impl.executeAsync(command, Vector(listOf(*args)), object : AsyncCallback { - - override fun handleError(error: Exception, url: URL, method: String) { - requestSynchronizer.release() - result[0] = makeError(error.message ?: "Unknown Error") - } - - override fun handleResult(recievedResult: Any, url: URL, method: String) { - requestSynchronizer.release() - result[0] = recievedResult - } - }) - } - catch (t: Throwable) { // Should not show but just in case! - requestSynchronizer.release() - throw t - } - - //busy loop waiting for the answer (or having the console die). - while (result[0] == null && System.currentTimeMillis() - started < timeoutMillis) { - progress.checkCanceled() - val exitValue = process.waitFor(10, TimeUnit.MILLISECONDS) - if (exitValue) { - result[0] = makeError(String.format("Console already exited with value: %s while waiting for an answer.\n", true)) - break - } - } - return result[0] ?: throw XmlRpcException(-1, "Timeout while connecting to server") - } - - fun makeError(error: String): Array { - return arrayOf(error) - } - - private fun Semaphore.tryAcquireWithIndicator(indicator: ProgressIndicator, - timeoutMillis: Long = TIME_LIMIT, - pollIntervalMillis: Long = 50): Boolean { - indicator.checkCanceled() - val started = System.currentTimeMillis() - while (!this.tryAcquire(1, pollIntervalMillis, java.util.concurrent.TimeUnit.MILLISECONDS)) { - indicator.checkCanceled() - if (System.currentTimeMillis() - started >= timeoutMillis) { - return false - } - } - return true - } - - companion object { - - /** - * ItelliJ Logging - */ - private val LOG = Logger.getInstance(PydevXmlRpcClient::class.java.name) - private const val MIN_TIME_SLICE: Long = 1000 - private const val TIME_LIMIT: Long = 40000 - } -} diff --git a/python/python-psi-impl/src/com/jetbrains/python/documentation/PyDocumentationLink.kt b/python/python-psi-impl/src/com/jetbrains/python/documentation/PyDocumentationLink.kt index b3fc10bf1cd6..45c6d3ef6ba1 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/documentation/PyDocumentationLink.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/documentation/PyDocumentationLink.kt @@ -43,14 +43,6 @@ object PyDocumentationLink { return HtmlChunk.link("${DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL}$LINK_TYPE_CLASS", content) } - @JvmStatic - fun toParameterPossibleClass(@NlsSafe type: String, anchor: PsiElement, context: TypeEvalContext): HtmlChunk { - return when (PyTypeParser.getTypeByName(anchor, type, context)) { - is PyClassType -> HtmlChunk.link("${DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL}$LINK_TYPE_PARAM", type) - else -> HtmlChunk.text(type) - } - } - @JvmStatic fun toPossibleClass(typeName: @Nls String, anchor: PsiElement, context: TypeEvalContext): HtmlChunk = when (val type = PyTypeParser.getTypeByName(anchor, typeName, context)) { diff --git a/python/python-restructuredtext/src/com/intellij/restructuredtext/python/PythonRestBundle.kt b/python/python-restructuredtext/src/com/intellij/restructuredtext/python/PythonRestBundle.kt index 3ebe78d5835e..7fc328a5ac6d 100644 --- a/python/python-restructuredtext/src/com/intellij/restructuredtext/python/PythonRestBundle.kt +++ b/python/python-restructuredtext/src/com/intellij/restructuredtext/python/PythonRestBundle.kt @@ -14,7 +14,4 @@ object PythonRestBundle : DynamicBundle(BUNDLE) { @Nls fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getMessage(key, *params) - @JvmStatic - fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) - = getLazyMessage(key, *params) } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCli.kt b/python/src/com/jetbrains/python/console/PydevConsoleCli.kt index 4a2b509df755..b26dc6f88e45 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCli.kt +++ b/python/src/com/jetbrains/python/console/PydevConsoleCli.kt @@ -118,14 +118,6 @@ fun waitForPythonConsoleServerToBeStarted(process: Process) { PydevConsoleRunnerImpl.getRemotePortFromProcess(process) } -fun createPythonConsoleScriptInServerMode(serverPort: Int, - helpersAwareTargetRequest: HelpersAwareTargetEnvironmentRequest): PythonExecution { - val pythonScriptExecution = prepareHelperScriptExecution(PythonHelper.CONSOLE, helpersAwareTargetRequest) - pythonScriptExecution.addParameter(getOptionString(MODE_OPTION, MODE_OPTION_SERVER_VALUE)) - pythonScriptExecution.addParameter(getOptionString(PORT_OPTION, serverPort)) - return pythonScriptExecution -} - /** * @param ideServerPort the host and port where the IDE being Python * Console frontend listens for the connection diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.kt b/python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.kt index 203e2f472b3d..db1152829d10 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.kt +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.kt @@ -167,23 +167,6 @@ open class PydevConsoleRunnerFactory : PythonConsoleRunnerFactory() { return SystemProperties.getUserHome() } - fun createSetupFragment(module: Module?, - workingDir: String?, - pathMapper: PathMapper?, - settingsProvider: PyConsoleSettings): Array { - var customStartScript = settingsProvider.customStartScript - if (customStartScript.isNotBlank()) { - customStartScript = "\n" + customStartScript - } - var pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.shouldAddContentRoots(), - settingsProvider.shouldAddSourceRoots()) - if (pathMapper != null) { - pythonPath = pathMapper.convertToRemote(pythonPath) - } - val selfPathAppend = constructPyPathAndWorkingDirCommand(pythonPath, workingDir, customStartScript) - return arrayOf(selfPathAppend) - } - private fun makeStartWithEmptyLine(line: String): String { if (line.startsWith("\n") || line.isBlank()) return line return "\n" + line diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunnerUtil.kt b/python/src/com/jetbrains/python/console/PydevConsoleRunnerUtil.kt index 7812a5a2a8b4..ec015404a0c2 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunnerUtil.kt +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunnerUtil.kt @@ -148,16 +148,6 @@ fun findPythonSdkAndModule(project: Project, contextModule: Module?): Pair, - workingDir: String?, - command: String): String { - if (workingDir != null) { - pythonPath.add(workingDir) - } - val path = pythonPath.joinToString(separator = ", ", transform = String::toStringLiteral) - return command.replace(PydevConsoleRunnerImpl.WORKING_DIR_AND_PYTHON_PATHS, path) -} - fun constructPyPathAndWorkingDirCommand(pythonPath: MutableCollection>, workingDirFunction: TargetEnvironmentFunction?, command: String): TargetEnvironmentFunction { diff --git a/python/src/com/jetbrains/python/debugger/containerview/PyDataView.kt b/python/src/com/jetbrains/python/debugger/containerview/PyDataView.kt index d6ee10297047..5d49c8141d2c 100644 --- a/python/src/com/jetbrains/python/debugger/containerview/PyDataView.kt +++ b/python/src/com/jetbrains/python/debugger/containerview/PyDataView.kt @@ -23,7 +23,6 @@ import com.intellij.ui.content.Content import com.intellij.ui.content.ContentFactory import com.intellij.ui.content.ContentManager import com.intellij.ui.dsl.builder.panel -import com.intellij.xdebugger.XDebuggerManager import com.jetbrains.python.PyBundle import com.jetbrains.python.console.PydevConsoleCommunication import com.jetbrains.python.debugger.PyDebugProcess @@ -153,15 +152,6 @@ class PyDataView(private val project: Project) : DumbAware { } } - private fun getFrameAccessor(handler: ProcessHandler): PyFrameAccessor? { - for (process in XDebuggerManager.getInstance(project).getDebugProcesses(PyDebugProcess::class.java)) { - if (Comparing.equal(handler, process.processHandler)) { - return process - } - } - return null - } - fun closeDisconnectedFromConsoleTabs() { closeTabs { frameAccessor: PyFrameAccessor? -> frameAccessor is PydevConsoleCommunication && !isConnected(frameAccessor) diff --git a/python/src/com/jetbrains/python/newProject/steps/PythonProjectSpecificSettingsStep.kt b/python/src/com/jetbrains/python/newProject/steps/PythonProjectSpecificSettingsStep.kt index 95c449129b0d..7991047ee69d 100644 --- a/python/src/com/jetbrains/python/newProject/steps/PythonProjectSpecificSettingsStep.kt +++ b/python/src/com/jetbrains/python/newProject/steps/PythonProjectSpecificSettingsStep.kt @@ -2,13 +2,10 @@ package com.jetbrains.python.newProject.steps import com.intellij.ide.IdeBundle -import com.intellij.ide.impl.ProjectUtil -import com.intellij.ide.impl.ProjectUtil.getUserHomeProjectDir import com.intellij.ide.util.projectWizard.AbstractNewProjectStep import com.intellij.ide.util.projectWizard.WebProjectSettingsStepWrapper import com.intellij.ide.util.projectWizard.WebProjectTemplate import com.intellij.openapi.GitRepositoryInitializer -import com.intellij.openapi.application.PathManager import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory import com.intellij.openapi.observable.properties.PropertyGraph import com.intellij.openapi.observable.util.bindBooleanStorage @@ -27,7 +24,6 @@ import com.intellij.ui.dsl.builder.Align import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.bindText import com.intellij.ui.dsl.builder.panel -import com.intellij.util.PlatformUtils import com.intellij.util.SystemProperties import com.intellij.util.concurrency.annotations.RequiresEdt import com.jetbrains.python.PyBundle.message @@ -39,7 +35,6 @@ import com.jetbrains.python.sdk.PyLazySdk import com.jetbrains.python.sdk.add.v2.PythonAddNewEnvironmentPanel import com.jetbrains.python.util.ShowingMessageErrorSync import kotlinx.coroutines.flow.MutableStateFlow -import java.io.File import java.nio.file.InvalidPathException import java.nio.file.Path import javax.swing.JPanel @@ -169,14 +164,6 @@ class PythonProjectSpecificSettingsStep( } - - private fun getBaseDir(): File { - if (PlatformUtils.isDataSpell() && Path.of(ProjectUtil.getBaseDir()).startsWith(PathManager.getConfigDir())) { - return File(getUserHomeProjectDir()) - } - return File(ProjectUtil.getBaseDir()) - } - private fun updateHint(): String = try { val projectPath = Path.of(projectLocation.get(), projectName.get()) diff --git a/python/src/com/jetbrains/python/packaging/management/PythonRepositoryManager.kt b/python/src/com/jetbrains/python/packaging/management/PythonRepositoryManager.kt index 04c5ca90e742..c4635f1a7cc4 100644 --- a/python/src/com/jetbrains/python/packaging/management/PythonRepositoryManager.kt +++ b/python/src/com/jetbrains/python/packaging/management/PythonRepositoryManager.kt @@ -17,8 +17,6 @@ abstract class PythonRepositoryManager(val project: Project, val sdk: Sdk) { abstract fun allPackages(): List abstract fun packagesFromRepository(repository: PyPackageRepository): List - suspend fun addRepository(repository: PyPackageRepository) { TODO() } - suspend fun removeRepository(repository: PyPackageRepository) { TODO() } abstract suspend fun getPackageDetails(pkg: PythonPackageSpecification): PythonPackageDetails abstract suspend fun getLatestVersion(spec: PythonPackageSpecification): PyPackageVersion? diff --git a/python/src/com/jetbrains/python/packaging/toolwindow/PyPackagingToolWindowPanel.kt b/python/src/com/jetbrains/python/packaging/toolwindow/PyPackagingToolWindowPanel.kt index 8e94e25c332b..f35b0e917bc5 100644 --- a/python/src/com/jetbrains/python/packaging/toolwindow/PyPackagingToolWindowPanel.kt +++ b/python/src/com/jetbrains/python/packaging/toolwindow/PyPackagingToolWindowPanel.kt @@ -33,9 +33,7 @@ import com.jetbrains.python.packaging.toolwindow.packages.PyPackageSearchTextFie import com.jetbrains.python.packaging.toolwindow.packages.PyPackagesListController import com.jetbrains.python.packaging.toolwindow.ui.PyPackagesUiComponents import com.jetbrains.python.packaging.utils.PyPackageCoroutine -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.cancel -import kotlinx.coroutines.withContext import java.awt.BorderLayout import java.awt.Dimension import java.awt.event.ActionEvent @@ -204,15 +202,6 @@ class PyPackagingToolWindowPanel(private val project: Project) : SimpleToolWindo packagingScope.cancel() } - internal suspend fun recreateModulePanel() { - val newPanel = createLeftPanel() - withContext(Dispatchers.Main) { - leftPanel = newPanel - splitter?.firstComponent = leftPanel - splitter?.repaint() - } - } - fun selectPackageName(name: String) { this.packageListController.selectPackage(name) } diff --git a/python/src/com/jetbrains/python/refactoring/surround/surrounders/expressions/PyForExpressionSurrounder.kt b/python/src/com/jetbrains/python/refactoring/surround/surrounders/expressions/PyForExpressionSurrounder.kt deleted file mode 100644 index 244b126d78ef..000000000000 --- a/python/src/com/jetbrains/python/refactoring/surround/surrounders/expressions/PyForExpressionSurrounder.kt +++ /dev/null @@ -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.refactoring.surround.surrounders.expressions - -import com.intellij.openapi.util.NlsSafe -import com.jetbrains.python.psi.PyExpression -import com.jetbrains.python.psi.PyForStatement -import com.jetbrains.python.psi.PyStatement -import com.jetbrains.python.psi.PyStatementListContainer - -class PyForExpressionSurrounder : PyExpressionAsConditionSurrounder() { - @NlsSafe - override fun getTemplateDescription(): String = "for e in expr" - - override fun getTextToGenerate(): String = "for i in expr:\n pass" - - override fun getCondition(statement: PyStatement?): PyExpression? { - return (statement as? PyForStatement)?.forPart?.source - } - - override fun getStatementListContainer(statement: PyStatement?): PyStatementListContainer? { - return (statement as? PyForStatement)?.forPart - } -} diff --git a/python/src/com/jetbrains/python/requirements/EnvironmentMarkers.kt b/python/src/com/jetbrains/python/requirements/EnvironmentMarkers.kt index 9130ac5fdaf8..ed391beab3bb 100644 --- a/python/src/com/jetbrains/python/requirements/EnvironmentMarkers.kt +++ b/python/src/com/jetbrains/python/requirements/EnvironmentMarkers.kt @@ -1,16 +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.requirements -import com.intellij.execution.process.ProcessOutput -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.projectRoots.Sdk -import com.jetbrains.python.sdk.PySdkUtil -import com.jetbrains.python.sdk.PythonSdkType -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.Json -import java.io.File -import java.time.LocalDateTime - const val PLATFORM_RELEASE = "platform_release" const val PYTHON_VERSION = "python_version" const val PYTHON_FULL_VERSION = "python_full_version" @@ -19,76 +9,3 @@ const val PACKAGE_VERSION = "package_version" val VERSION_VARIABLES = listOf(IMPLEMENTATION_VERSION, PLATFORM_RELEASE, PYTHON_FULL_VERSION, PYTHON_VERSION, PACKAGE_VERSION) -@Serializable -data class PythonInfo( - var osName: String? = null, - var sysPlatform: String? = null, - var platformMachine: String? = null, - var platformPythonImplementation: String? = null, - var platformRelease: String? = null, - var platformSystem: String? = null, - var platformVersion: String? = null, - var pythonVersion: String? = null, - var pythonFullVersion: String? = null, - var implementationName: String? = null, - var implementationVersion: String? = null, - var extra: String? = null -) { - val map: Map - get() { - return mapOf( - "os_name" to osName, - "sys_platform" to sysPlatform, - "platform_machine" to platformMachine, - "platform_python_implementation" to platformPythonImplementation, - "platform_release" to platformRelease, - "platform_system" to platformSystem, - "platform_version" to platformVersion, - "python_version" to pythonVersion, - "python_full_version" to pythonFullVersion, - "implementation_name" to implementationName, - "implementation_version" to implementationVersion, - "extra" to extra - ) - } -} - -val markersCache = mutableMapOf>() - -fun getPythonInfo(sdk: Sdk): PythonInfo { - val cached = markersCache[sdk.name] - if (cached != null) { - val actual = cached.second.plusDays(1).isAfter(LocalDateTime.now()) - if (actual) { - return cached.first - } - } - val scriptResource = object {}.javaClass.getResource("/python_info.py") - val code = scriptResource?.readText() - val result = code?.let { execPythonCode(sdk, it) } ?: return PythonInfo() - val pythonInfo = Json.decodeFromString(result) - markersCache[sdk.name] = pythonInfo to LocalDateTime.now() - - return pythonInfo -} - -fun execPythonCode(sdk: Sdk, code: String): String? { - if (sdk.sdkType !is PythonSdkType) { - return null - } - - val pythonPath = sdk.homePath ?: return null - - val output = ApplicationManager.getApplication() - .executeOnPooledThread { - return@executeOnPooledThread PySdkUtil.getProcessOutput( - File(pythonPath).parent, - listOf(sdk.homePath, "-c", code).toTypedArray(), - 5000 - ) - }.get() ?: return null - if (output.exitCode != 0 || output.isTimeout || output.isCancelled) { - return null - } - return output.stdout -} diff --git a/python/src/com/jetbrains/python/requirements/RequirementsFile.kt b/python/src/com/jetbrains/python/requirements/RequirementsFile.kt index 3f34c098899b..6a0560af16dd 100644 --- a/python/src/com/jetbrains/python/requirements/RequirementsFile.kt +++ b/python/src/com/jetbrains/python/requirements/RequirementsFile.kt @@ -40,18 +40,6 @@ class RequirementsFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvide return getPythonSdk(this) } - fun enabledRequirements(): List { - val sdk = sdk ?: return emptyList() - return requirements().filter { - it.enabled(getPythonInfo(sdk).map) - } - } - - fun disabledRequirements(): List { - val sdk = sdk ?: return requirements() - return requirements().filter { !it.enabled(getPythonInfo(sdk).map) } - } - override fun toString(): String { return "Requirements File" } diff --git a/python/src/com/jetbrains/python/requirements/RequirementsInspectionVisitor.kt b/python/src/com/jetbrains/python/requirements/RequirementsInspectionVisitor.kt index d24ed64e82a8..e9e72d75d38d 100644 --- a/python/src/com/jetbrains/python/requirements/RequirementsInspectionVisitor.kt +++ b/python/src/com/jetbrains/python/requirements/RequirementsInspectionVisitor.kt @@ -9,7 +9,6 @@ import com.jetbrains.python.requirements.psi.NameReq import com.jetbrains.python.requirements.psi.UriReference open class RequirementsInspectionVisitor(val holder: ProblemsHolder, - val onTheFly: Boolean, val session: LocalInspectionToolSession) : PsiElementVisitor() { override fun visitElement(element: PsiElement) { diff --git a/python/src/com/jetbrains/python/requirements/UnsatisfiedRequirementInspection.kt b/python/src/com/jetbrains/python/requirements/UnsatisfiedRequirementInspection.kt index 8e4eabae7f30..9a6520e77723 100644 --- a/python/src/com/jetbrains/python/requirements/UnsatisfiedRequirementInspection.kt +++ b/python/src/com/jetbrains/python/requirements/UnsatisfiedRequirementInspection.kt @@ -51,7 +51,7 @@ class UnsatisfiedRequirementInspection : LocalInspectionTool() { private class UnsatisfiedRequirementInspectionVisitor(holder: ProblemsHolder, onTheFly: Boolean, session: LocalInspectionToolSession) : RequirementsInspectionVisitor( - holder, onTheFly, session) { + holder, session) { override fun visitRequirementsFile(element: RequirementsFile) { val module = ModuleUtilCore.findModuleForPsiElement(element) val requirementsPath = PyPackageRequirementsSettings.getInstance(module).requirementsPath diff --git a/python/src/com/jetbrains/python/run/ExceptionsWithHyperlink.kt b/python/src/com/jetbrains/python/run/ExceptionsWithHyperlink.kt deleted file mode 100644 index 5cc3d138f25a..000000000000 --- a/python/src/com/jetbrains/python/run/ExceptionsWithHyperlink.kt +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.run - -import com.intellij.execution.ExecutionException -import com.intellij.openapi.diagnostic.ControlFlowException -import com.intellij.openapi.util.NlsContexts -import org.jetbrains.annotations.ApiStatus -import javax.swing.event.HyperlinkEvent -import javax.swing.event.HyperlinkListener - -/** - * The exception implements [ControlFlowException] to skip the logging (see `org.jetbrains.concurrency.Promises.errorIfNotMessage`). - */ -@ApiStatus.Internal -internal class ExecutionExceptionWithHyperlink(s: @NlsContexts.DialogMessage String, private val hyperlinkActivatedCallback: Runnable) - : ExecutionException(s), HyperlinkListener, ControlFlowException { - override fun hyperlinkUpdate(e: HyperlinkEvent) { - if (e.eventType == HyperlinkEvent.EventType.ACTIVATED) { - hyperlinkActivatedCallback.run() - } - } -} - -/** - * The exception implements [ControlFlowException] to skip the logging (see `org.jetbrains.concurrency.Promises.errorIfNotMessage`). - */ -@ApiStatus.Internal -internal class RuntimeExceptionWithHyperlink(s: @NlsContexts.DialogMessage String, private val hyperlinkActivatedCallback: Runnable) - : RuntimeException(s), HyperlinkListener, ControlFlowException { - override fun hyperlinkUpdate(e: HyperlinkEvent) { - if (e.eventType == HyperlinkEvent.EventType.ACTIVATED) { - hyperlinkActivatedCallback.run() - } - } -} \ No newline at end of file diff --git a/python/src/com/jetbrains/python/run/PyRunConfigurationTargetOptions.kt b/python/src/com/jetbrains/python/run/PyRunConfigurationTargetOptions.kt index 362bb1907195..313993d3b193 100644 --- a/python/src/com/jetbrains/python/run/PyRunConfigurationTargetOptions.kt +++ b/python/src/com/jetbrains/python/run/PyRunConfigurationTargetOptions.kt @@ -1,36 +1,10 @@ // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.jetbrains.python.run -import com.intellij.execution.target.RunConfigurationTargetEnvironmentAdjuster -import com.intellij.openapi.options.SettingsEditor -import com.intellij.openapi.util.registry.Registry -import java.util.* - class PyRunConfigurationTargetOptions : PyRunConfigurationEditorExtension { - private val factoriesCache = WeakHashMap() override fun accepts(configuration: AbstractPythonRunConfiguration>): PyRunConfigurationEditorFactory? { return null } - private class RunConfigurationsTargetOptionsFactory(private val adjuster: RunConfigurationTargetEnvironmentAdjuster) : PyRunConfigurationEditorFactory { - override fun createEditor(configuration: AbstractPythonRunConfiguration<*>): SettingsEditor> { - val adjuster = RunConfigurationTargetEnvironmentAdjuster.Factory.findTargetEnvironmentRequestAdjuster(configuration.sdk!!)!! - val runConfigurationEditor = adjuster.createAdditionalRunConfigurationUI(configuration) { configuration.sdk } - return runConfigurationEditor as SettingsEditor> - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as RunConfigurationsTargetOptionsFactory - - return adjuster == other.adjuster - } - - override fun hashCode(): Int { - return adjuster.hashCode() - } - } } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt b/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt index d59ed479cbf4..cf7f1297c7ec 100644 --- a/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt +++ b/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt @@ -12,7 +12,6 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.module.Module import com.intellij.openapi.project.DumbAware -import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.Project import com.intellij.openapi.projectRoots.Sdk import com.jetbrains.python.PyBundle @@ -21,7 +20,6 @@ import com.jetbrains.python.run.PythonInterpreterTargetEnvironmentFactory import com.jetbrains.python.run.allowCreationTargetOfThisType import com.jetbrains.python.sdk.ModuleOrProject.ModuleAndProject import com.jetbrains.python.sdk.ModuleOrProject.ProjectOnly -import com.jetbrains.python.sdk.add.PyAddSdkDialog import com.jetbrains.python.sdk.add.collector.PythonNewInterpreterAddedCollector import com.jetbrains.python.sdk.add.v2.PythonAddLocalInterpreterDialog import com.jetbrains.python.sdk.add.v2.PythonAddLocalInterpreterPresenter @@ -93,27 +91,6 @@ private class AddInterpreterOnTargetAction( } } -class AddInterpreterAction(val project: Project, val module: Module, private val currentSdk: Sdk?) - : DumbAwareAction(PyBundle.messagePointer("python.sdk.popup.add.interpreter")) { - - override fun actionPerformed(e: AnActionEvent) { - val model = PyConfigurableInterpreterList.getInstance(project).model - - PyAddSdkDialog.show( - project, - module, - model.sdks.asList(), - Consumer { - if (it != null && model.findSdk(it.name) == null) { - model.addSdk(it) - model.apply() - switchToSdk(module, it, currentSdk) - } - } - ) - } -} - fun switchToSdk(module: Module, sdk: Sdk, currentSdk: Sdk?) { val project = module.project (sdk.sdkType as PythonSdkType).setupSdkPaths(sdk) diff --git a/python/src/com/jetbrains/python/ui/flow/FlowBinder.kt b/python/src/com/jetbrains/python/ui/flow/FlowBinder.kt index 1b4997d9e02e..578d0f42ee83 100644 --- a/python/src/com/jetbrains/python/ui/flow/FlowBinder.kt +++ b/python/src/com/jetbrains/python/ui/flow/FlowBinder.kt @@ -8,9 +8,7 @@ import com.intellij.util.ui.showingScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import org.jetbrains.annotations.ApiStatus -import org.jetbrains.annotations.Nls import javax.swing.JComponent -import javax.swing.JLabel import javax.swing.JToggleButton import javax.swing.text.JTextComponent @@ -38,18 +36,6 @@ fun Cell.bindText(flow: MutableStateFlow) = apply { bindImpl(flow, { text(it) }, Pair({ component.text }, flow)) } -/** - * Same as [bindText] but for r/o labels: - * ```kotlin - * val f:Flow - * label("..").bindLabelText(f) - * ``` - */ -@ApiStatus.Experimental -fun Cell.bindLabelText(flow: Flow<@Nls String>) = apply { - bindImpl(flow, { component.text = it }) -} - /** * Binds checkbox to a [Flow] making changing its `selected` state on each event * ```kotlin