From 89df7c174cad855e2bb342e7832e9624ff8ca279 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Thu, 22 Jan 2026 05:08:49 +0100 Subject: [PATCH] cleanup [eel] [python]: Add extension `Path.osFamily`. Calling `getEelDescriptor()` is too much ceremony. Space-RevId: cc7d4b851dd8dbf484fe7f67e44625cdd1dd7772 GitOrigin-RevId: 2aaa72756a77a0cba7ee865eb9afc4ade39b6a27 --- .../openapi/projectRoots/impl/jdkPathUtil.kt | 3 ++- .../eel-provider/api-dump-experimental.txt | 1 + .../platform/eel/provider/EelProvider.kt | 6 ++++- .../intellij/platform/eel/provider/impl.kt | 2 +- .../eel/provider/utils/eelPathUtils.kt | 2 +- .../intellij/openapi/projectRoots/javaName.kt | 3 ++- .../execution/target/GradleServerRunner.kt | 3 ++- .../idea/maven/server/MavenWrapperSupport.kt | 3 ++- .../python/venvReader/VirtualEnvReader.kt | 22 ++++++++++--------- .../python/sdk/impl/PythonBinaryExt.kt | 3 ++- .../sdk/conda/execution/CondaExecutor.kt | 3 ++- 11 files changed, 32 insertions(+), 19 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/jdkPathUtil.kt b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/jdkPathUtil.kt index 906413e2c9c9..74cb91edf2d2 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/jdkPathUtil.kt +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/jdkPathUtil.kt @@ -3,9 +3,10 @@ package com.intellij.openapi.projectRoots.impl import com.intellij.platform.eel.isPosix import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.osFamily import java.nio.file.Path internal fun getJavaPath(binPath: Path): Path { - val os = binPath.getEelDescriptor().osFamily + val os = binPath.osFamily return binPath.resolve(if (os.isPosix) "java" else "java.exe") } diff --git a/platform/eel-provider/api-dump-experimental.txt b/platform/eel-provider/api-dump-experimental.txt index aced9a24fa87..966121602258 100644 --- a/platform/eel-provider/api-dump-experimental.txt +++ b/platform/eel-provider/api-dump-experimental.txt @@ -15,6 +15,7 @@ f:com.intellij.platform.eel.provider.EelProviderUtil - *sf:getEelDescriptor(com.intellij.openapi.project.Project):com.intellij.platform.eel.EelDescriptor - *sf:getEelDescriptor(java.nio.file.Path):com.intellij.platform.eel.EelDescriptor - *sf:getLocalEel():com.intellij.platform.eel.LocalEelApi +- *sf:getOsFamily(java.nio.file.Path):com.intellij.platform.eel.EelOsFamily - *sf:toEelApiBlocking(com.intellij.platform.eel.EelDescriptor):com.intellij.platform.eel.EelApi - *sf:toEelApiBlocking(com.intellij.platform.eel.EelMachine,com.intellij.platform.eel.EelDescriptor):com.intellij.platform.eel.EelApi *f:com.intellij.platform.eel.provider.LocalEelDescriptor diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/EelProvider.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/EelProvider.kt index dfe626fd8a30..84d49e50a5e8 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/EelProvider.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/EelProvider.kt @@ -147,6 +147,9 @@ fun Path.getEelDescriptor(): EelDescriptor { return LocalEelDescriptor } +@get:ApiStatus.Experimental +val Path.osFamily: EelOsFamily get() = getEelDescriptor().osFamily + /** * Retrieves [EelDescriptor] for the environment where [this] is located. * If the project is not the real one (i.e., it is default or not backed by a real file), then [LocalEelDescriptor] will be returned. @@ -169,7 +172,8 @@ fun Project.getEelDescriptor(): EelDescriptor { @get:ApiStatus.Experimental val localEel: LocalEelApi by lazy { - if (SystemInfo.isWindows) ApplicationManager.getApplication().service() else ApplicationManager.getApplication().service() + if (SystemInfo.isWindows) ApplicationManager.getApplication().service() + else ApplicationManager.getApplication().service() } @Deprecated("Use toEelApiBlocking() instead", ReplaceWith("toEelApiBlocking()")) diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/impl.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/impl.kt index fecd5b499b13..478cf06ac23b 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/impl.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/impl.kt @@ -10,5 +10,5 @@ internal class ArchiveBackendImpl : ArchiveBackend { @OptIn(EelDelicateApi::class) override fun isWindows(path: Path): Boolean = // If app isn't loaded we are called from some low-level thing and can't access eel without app anyway - path.getEelDescriptor().osFamily.isWindows + path.osFamily.isWindows } \ No newline at end of file diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt index d8c51ba44a5d..4342f1143327 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt @@ -1087,7 +1087,7 @@ object EelPathUtils { val localPathEel = sourceRoot.asEelPath() val sourceDescriptor = localPathEel.descriptor val localOsFamily = localPathEel.descriptor.osFamily - val remoteOsFamily = targetRoot.getEelDescriptor().osFamily + val remoteOsFamily = targetRoot.osFamily val sourceRoot = localPathEel.asNioPath() val targetRoot = targetRootEel.asNioPath() diff --git a/platform/lang-core/src/com/intellij/openapi/projectRoots/javaName.kt b/platform/lang-core/src/com/intellij/openapi/projectRoots/javaName.kt index 0bee066d44ec..456414ea7d41 100644 --- a/platform/lang-core/src/com/intellij/openapi/projectRoots/javaName.kt +++ b/platform/lang-core/src/com/intellij/openapi/projectRoots/javaName.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.util.NlsSafe import com.intellij.platform.eel.EelOsFamily import com.intellij.platform.eel.channels.EelDelicateApi import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.osFamily import java.nio.file.Path @@ -16,7 +17,7 @@ internal enum class CheckFor(val file: String) { * Which file name is used for java binary for an OS this [path] resides on */ @OptIn(EelDelicateApi::class) -internal fun getJavaFileName(path: Path, checkFor: CheckFor): @NlsSafe String = when (path.getEelDescriptor().osFamily) { +internal fun getJavaFileName(path: Path, checkFor: CheckFor): @NlsSafe String = when (path.osFamily) { // It is important to use the right file name because of IJPL-217480 EelOsFamily.Posix -> checkFor.file EelOsFamily.Windows -> checkFor.file + ".exe" diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerRunner.kt b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerRunner.kt index 889186fa2121..5822e487a25b 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerRunner.kt +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/target/GradleServerRunner.kt @@ -13,6 +13,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.NlsSafe import com.intellij.platform.eel.EelOsFamily import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.osFamily import com.intellij.util.io.BaseOutputReader import org.gradle.tooling.ResultHandler import org.gradle.tooling.internal.consumer.parameters.ConsumerOperationParameters @@ -182,6 +183,6 @@ internal class GradleServerRunner(private val connection: TargetProjectConnectio return text } - private fun String.getPathPlatform(): EelOsFamily = Path.of(this).getEelDescriptor().osFamily + private fun String.getPathPlatform(): EelOsFamily = Path.of(this).osFamily } \ No newline at end of file diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt index 5ee476ba8ccc..00f8ec0bfc0a 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.platform.eel.isPosix import com.intellij.platform.eel.provider.LocalEelDescriptor import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.osFamily import com.intellij.util.io.HttpRequests import com.intellij.util.io.zip.JBZipFile import org.jetbrains.idea.maven.buildtool.MavenSyncConsole @@ -117,7 +118,7 @@ internal class MavenWrapperSupport { throw IllegalStateException(SyncBundle.message("zip.is.not.correct", zipFile.toAbsolutePath())) } val mavenHome = dirs[0] - if (mavenHome.getEelDescriptor().osFamily.isPosix) { + if (mavenHome.osFamily.isPosix) { makeMavenBinRunnable(mavenHome) } return mavenHome.toRealPath() diff --git a/python/openapi/src/com/jetbrains/python/venvReader/VirtualEnvReader.kt b/python/openapi/src/com/jetbrains/python/venvReader/VirtualEnvReader.kt index 49af4fe2da2e..da51561652bb 100644 --- a/python/openapi/src/com/jetbrains/python/venvReader/VirtualEnvReader.kt +++ b/python/openapi/src/com/jetbrains/python/venvReader/VirtualEnvReader.kt @@ -8,8 +8,8 @@ import com.intellij.platform.eel.EelApi import com.intellij.platform.eel.EelOsFamily import com.intellij.platform.eel.environmentVariables import com.intellij.platform.eel.provider.asNioPath -import com.intellij.platform.eel.provider.getEelDescriptor import com.intellij.platform.eel.provider.localEel +import com.intellij.platform.eel.provider.osFamily import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.jetbrains.python.PythonBinary import com.jetbrains.python.PythonHomePath @@ -132,10 +132,7 @@ class VirtualEnvReader private constructor( */ @RequiresBackgroundThread fun findPythonInPythonRoot(pathOrDir: PythonHomePath): PythonBinary? { - val pythonNames = when (forcedOs ?: pathOrDir.getEelDescriptor().osFamily) { - EelOsFamily.Posix -> POSIX_BINS - EelOsFamily.Windows -> WIN_BINS - } + val pythonNames = getPythonBinaryNames(pathOrDir.osFamily) if (pathOrDir.isRegularFile() && pathOrDir.name.lowercase() in pythonNames) { return pathOrDir } @@ -160,7 +157,7 @@ class VirtualEnvReader private constructor( fun getVenvRootPath(path: Path): Path? { val bin = path.parent - val binFolderName = when (forcedOs ?: path.getEelDescriptor().osFamily) { + val binFolderName = when (forcedOs ?: path.osFamily) { EelOsFamily.Posix -> "bin" EelOsFamily.Windows -> "Scripts" } @@ -191,10 +188,7 @@ class VirtualEnvReader private constructor( private fun findInterpreter(dir: Path): PythonBinary? = try { Files.newDirectoryStream(dir).use { stream -> - val pythonNames = when (forcedOs ?: dir.getEelDescriptor().osFamily) { - EelOsFamily.Posix -> POSIX_BINS - EelOsFamily.Windows -> WIN_BINS - } + val pythonNames = getPythonBinaryNames(forcedOs ?: dir.osFamily) stream.firstOrNull { it.name.lowercase() in pythonNames && it.isRegularFile() @@ -238,6 +232,14 @@ class VirtualEnvReader private constructor( private val POSIX_BINS = setOf("pypy", "python") private val WIN_BINS = setOf("pypy.exe", "python.exe") private fun getLocalEelIfApp(): EelApi? = if (ApplicationManager.getApplication() != null) localEel else null + + private fun getPythonBinaryNames(osFamily: EelOsFamily): Set { + val pythonNames = when (osFamily) { + EelOsFamily.Posix -> POSIX_BINS + EelOsFamily.Windows -> WIN_BINS + } + return pythonNames + } } } diff --git a/python/python-sdk/src/com/jetbrains/python/sdk/impl/PythonBinaryExt.kt b/python/python-sdk/src/com/jetbrains/python/sdk/impl/PythonBinaryExt.kt index af1739326f35..999057d79bbb 100644 --- a/python/python-sdk/src/com/jetbrains/python/sdk/impl/PythonBinaryExt.kt +++ b/python/python-sdk/src/com/jetbrains/python/sdk/impl/PythonBinaryExt.kt @@ -3,6 +3,7 @@ package com.jetbrains.python.sdk.impl import com.intellij.platform.eel.EelOsFamily import com.intellij.platform.eel.isWindows import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.osFamily import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.jetbrains.python.PythonBinary import com.jetbrains.python.PythonHomePath @@ -13,7 +14,7 @@ import kotlin.io.path.name @RequiresBackgroundThread @ApiStatus.Internal -fun PythonBinary.resolvePythonHome(): PythonHomePath = when (getEelDescriptor().osFamily) { +fun PythonBinary.resolvePythonHome(): PythonHomePath = when (osFamily) { EelOsFamily.Windows -> parent.takeIf { it.name.lowercase() != "scripts" } ?: parent.parent EelOsFamily.Posix -> parent.takeIf { it.name != "bin" } ?: parent.parent } diff --git a/python/src/com/jetbrains/python/sdk/conda/execution/CondaExecutor.kt b/python/src/com/jetbrains/python/sdk/conda/execution/CondaExecutor.kt index 90edcdb08ef3..0b46471bd125 100644 --- a/python/src/com/jetbrains/python/sdk/conda/execution/CondaExecutor.kt +++ b/python/src/com/jetbrains/python/sdk/conda/execution/CondaExecutor.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.projectRoots.Sdk import com.intellij.platform.eel.isWindows import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.osFamily import com.intellij.python.community.execService.* import com.intellij.python.community.execService.python.advancedApi.ExecutablePython import com.intellij.python.community.execService.python.advancedApi.validatePythonAndGetInfo @@ -150,7 +151,7 @@ object CondaExecutor { val pathOnEel = (binaryToExec as? BinOnEel)?.path ?: return PyResult.success(emptyMap()) - val osFamily = pathOnEel.getEelDescriptor().osFamily + val osFamily = pathOnEel.osFamily if (!osFamily.isWindows) return PyResult.success(emptyMap()) if (!pathOnEel.exists()) { return PyResult.localizedError(PyBundle.message("python.add.sdk.conda.executable.path.is.not.found"))