mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup [eel] [python]: Add extension Path.osFamily.
Calling `getEelDescriptor()` is too much ceremony. Space-RevId: cc7d4b851dd8dbf484fe7f67e44625cdd1dd7772 GitOrigin-RevId: 2aaa72756a77a0cba7ee865eb9afc4ade39b6a27
This commit is contained in:
committed by
intellij-monorepo-bot
parent
af74b3c7a6
commit
89df7c174c
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<LocalWindowsEelApi>() else ApplicationManager.getApplication().service<LocalPosixEelApi>()
|
||||
if (SystemInfo.isWindows) ApplicationManager.getApplication().service<LocalWindowsEelApi>()
|
||||
else ApplicationManager.getApplication().service<LocalPosixEelApi>()
|
||||
}
|
||||
|
||||
@Deprecated("Use toEelApiBlocking() instead", ReplaceWith("toEelApiBlocking()"))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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<String> {
|
||||
val pythonNames = when (osFamily) {
|
||||
EelOsFamily.Posix -> POSIX_BINS
|
||||
EelOsFamily.Windows -> WIN_BINS
|
||||
}
|
||||
return pythonNames
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user