mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 14:01:44 +07:00
Python: make system python service available from community.
We make it a part of PythonCore module to use it from community GitOrigin-RevId: ea6b00b6ac1a24478f9ff74cb34beffab0942089
This commit is contained in:
committed by
intellij-monorepo-bot
parent
91cfd7fca0
commit
6b6658fbc9
@@ -19,6 +19,9 @@ object PythonCommunityPluginModules {
|
||||
"intellij.python.community.impl.installer",
|
||||
"intellij.python.community.impl.huggingFace",
|
||||
"intellij.python.community.impl.venv",
|
||||
"intellij.python.community.services.systemPython",
|
||||
"intellij.python.community.services.shared",
|
||||
"intellij.python.community.services.internal.impl",
|
||||
"intellij.python.community.execService",
|
||||
"intellij.python.community.plugin.impl",
|
||||
"intellij.python.community.plugin.java",
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
<dependencies>
|
||||
<plugin id="PythonCore"/>
|
||||
<module name="intellij.platform.whatsNew"/>
|
||||
<module name="intellij.python.community.services.systemPython"/>
|
||||
<module name="intellij.python.community.services.shared"/>
|
||||
</dependencies>
|
||||
|
||||
<projectListeners>
|
||||
|
||||
@@ -170,5 +170,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.eel.provider" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.impl.venv" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.execService" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.services.systemPython" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,9 +0,0 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
/**
|
||||
* This package is for JetBrains only
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
package com.jetbrains.python.systemPythonSpi;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -1,9 +1,3 @@
|
||||
- name: lib/modules/intellij.python.community.services.internal.impl.jar
|
||||
contentModules:
|
||||
- name: intellij.python.community.services.internal.impl
|
||||
- name: lib/modules/intellij.python.community.services.shared.jar
|
||||
contentModules:
|
||||
- name: intellij.python.community.services.shared
|
||||
- name: lib/python-ce.jar
|
||||
projectLibraries:
|
||||
- name: XmlRPC
|
||||
@@ -37,6 +31,9 @@
|
||||
- name: intellij.python.community.impl.poetry
|
||||
- name: intellij.python.community.impl.installer
|
||||
- name: intellij.python.community.impl.venv
|
||||
- name: intellij.python.community.services.systemPython
|
||||
- name: intellij.python.community.services.shared
|
||||
- name: intellij.python.community.services.internal.impl
|
||||
- name: intellij.python.community.execService
|
||||
- name: intellij.python.psi
|
||||
- name: intellij.python.psi.impl
|
||||
@@ -58,7 +55,6 @@
|
||||
- name: intellij.python.markdown
|
||||
- name: intellij.python.ml.features
|
||||
- name: intellij.python.terminal
|
||||
- name: intellij.python.community.services.systemPython
|
||||
- name: lib/python-common.jar
|
||||
modules:
|
||||
- name: intellij.python.parser
|
||||
|
||||
@@ -53,9 +53,7 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
|
||||
<module name="intellij.python.markdown"/>
|
||||
<module name="intellij.python.ml.features"/>
|
||||
<module name="intellij.python.terminal"/>
|
||||
<module name="intellij.python.community.services.systemPython"/>
|
||||
<module name="intellij.python.community.services.shared"/>
|
||||
<module name="intellij.python.community.services.internal.impl"/>
|
||||
|
||||
</content>
|
||||
|
||||
<resource-bundle>messages.PyBundle</resource-bundle>
|
||||
@@ -1042,7 +1040,7 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
|
||||
<extensionPoints>
|
||||
<extensionPoint qualifiedName="Pythonid.systemPythonProvider"
|
||||
dynamic="true"
|
||||
interface="com.jetbrains.python.systemPythonSpi.SystemPythonProvider"/>
|
||||
interface="com.intellij.python.community.services.systemPython.SystemPythonProvider"/>
|
||||
</extensionPoints>
|
||||
|
||||
</idea-plugin>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
</content>
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<idea-plugin package="com.intellij.python.community.services.internal.impl">
|
||||
<dependencies>
|
||||
<module name="intellij.python.community.services.shared"/>
|
||||
</dependencies>
|
||||
|
||||
</idea-plugin>
|
||||
@@ -3,7 +3,6 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<idea-plugin package="com.intellij.python.community.services.shared"/>
|
||||
@@ -3,7 +3,6 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||
@@ -23,7 +22,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.testFramework" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="hamcrest" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.impl" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.services.shared" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.services.internal.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<idea-plugin package="com.intellij.python.community.services.systemPython">
|
||||
<dependencies>
|
||||
<module name="intellij.python.community.services.shared"/>
|
||||
<module name="intellij.python.community.services.internal.impl"/>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</idea-plugin>
|
||||
@@ -1,19 +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.services.systemPython
|
||||
|
||||
import com.jetbrains.python.Result
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
/**
|
||||
* Tool to install python on OS.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
sealed interface PythonInstallerService {
|
||||
|
||||
/**
|
||||
* Installs latest stable python on OS.
|
||||
* Returns Unit for now (so you should call [SystemPythonService.findSystemPythons]), but this is a subject to change.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
suspend fun installLatestPython(): Result<Unit, String>
|
||||
}
|
||||
@@ -1,14 +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.services.systemPython
|
||||
|
||||
import com.intellij.python.community.services.internal.impl.PythonWithLanguageLevelImpl
|
||||
import com.intellij.python.community.services.shared.PythonWithLanguageLevel
|
||||
|
||||
/**
|
||||
* Python installed on OS.
|
||||
* [pythonBinary] is guaranteed to be usable and have [languageLevel] at the moment of instance creation.
|
||||
*
|
||||
* Instances could be obtained with [SystemPythonService]
|
||||
*/
|
||||
@JvmInline
|
||||
value class SystemPython internal constructor(private val impl: PythonWithLanguageLevelImpl) : PythonWithLanguageLevel by impl
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.python.community.services.systemPython
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.platform.eel.EelApi
|
||||
import com.intellij.platform.eel.provider.localEel
|
||||
import com.intellij.python.community.services.internal.impl.PythonWithLanguageLevelImpl
|
||||
import com.intellij.python.community.services.shared.PythonWithLanguageLevel
|
||||
import com.jetbrains.python.PythonBinary
|
||||
import com.jetbrains.python.Result
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.Nls
|
||||
|
||||
/**
|
||||
* Service to register and obtain [SystemPython]s
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
sealed interface SystemPythonService {
|
||||
/**
|
||||
* System pythons installed on OS.
|
||||
* Sort pythons by [SystemPython.languageLevel] to find the highest one
|
||||
*/
|
||||
suspend fun findSystemPythons(eelApi: EelApi = localEel): Set<SystemPython>
|
||||
|
||||
/**
|
||||
* When user provides a path to the python binary, use this method to the [SystemPython].
|
||||
* @return either [SystemPython] or an error if python is broken.
|
||||
*/
|
||||
suspend fun registerSystemPython(pythonPath: PythonBinary): Result<SystemPython, @Nls String>
|
||||
|
||||
/**
|
||||
* @return tool to install python on OS If [eelApi] supports python installation
|
||||
*/
|
||||
fun getInstaller(eelApi: EelApi = localEel): PythonInstallerService?
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of this service
|
||||
*/
|
||||
fun SystemPythonService(): SystemPythonService = ApplicationManager.getApplication().service<SystemPythonServiceImpl>()
|
||||
|
||||
/**
|
||||
* Python installed on OS.
|
||||
* [pythonBinary] is guaranteed to be usable and have [languageLevel] at the moment of instance creation.
|
||||
*
|
||||
* Instances could be obtained with [SystemPythonService]
|
||||
*/
|
||||
@JvmInline
|
||||
value class SystemPython internal constructor(private val impl: PythonWithLanguageLevelImpl) : PythonWithLanguageLevel by impl
|
||||
|
||||
/**
|
||||
* Tool to install python on OS.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
sealed interface PythonInstallerService {
|
||||
|
||||
/**
|
||||
* Installs latest stable python on OS.
|
||||
* Returns Unit for now (so you should call [SystemPythonService.findSystemPythons]), but this is a subject to change.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
suspend fun installLatestPython(): Result<Unit, String>
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.python.community.services.systemPython
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.EDT
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.components.Service.Level.APP
|
||||
@@ -16,45 +15,19 @@ import com.jetbrains.python.PythonBinary
|
||||
import com.jetbrains.python.Result
|
||||
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor
|
||||
import com.jetbrains.python.sdk.installer.installBinary
|
||||
import com.jetbrains.python.systemPythonSpi.SystemPythonProvider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import org.jetbrains.annotations.Nls
|
||||
|
||||
/**
|
||||
* Service to register and obtain [SystemPython]s
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
sealed interface SystemPythonService {
|
||||
/**
|
||||
* System pythons installed on OS.
|
||||
* Sort pythons by [SystemPython.languageLevel] to find the highest one
|
||||
*/
|
||||
suspend fun findSystemPythons(eelApi: EelApi = localEel): Set<SystemPython>
|
||||
|
||||
/**
|
||||
* When user provides a path to the python binary, use this method to the [SystemPython].
|
||||
* @return either [SystemPython] or an error if python is broken.
|
||||
*/
|
||||
suspend fun registerSystemPython(pythonPath: PythonBinary): Result<SystemPython, @Nls String>
|
||||
|
||||
/**
|
||||
* @return tool to install python on OS If [eelApi] supports python installation
|
||||
*/
|
||||
fun getInstaller(eelApi: EelApi = localEel): PythonInstallerService?
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of this service
|
||||
*/
|
||||
fun SystemPythonService(): SystemPythonService = ApplicationManager.getApplication().service<SystemPythonServiceImpl>()
|
||||
|
||||
// Implementation
|
||||
|
||||
@Service(APP)
|
||||
@State(name = "SystemPythonService", storages = [Storage("systemPythonService.xml", roamingType = RoamingType.LOCAL)], allowLoadInTests = true)
|
||||
private class SystemPythonServiceImpl : SystemPythonService, SimplePersistentStateComponent<MyServiceState>(MyServiceState()) {
|
||||
@State(name = "SystemPythonService", storages = [Storage("systemPythonService.xml", roamingType = RoamingType.LOCAL)],
|
||||
allowLoadInTests = true)
|
||||
@Internal
|
||||
internal class SystemPythonServiceImpl : SystemPythonService, SimplePersistentStateComponent<MyServiceState>(MyServiceState()) {
|
||||
|
||||
override suspend fun registerSystemPython(pythonPath: PythonBinary): Result<SystemPython, @Nls String> {
|
||||
val impl = PythonWithLanguageLevelImpl.createByPythonBinary(pythonPath).getOr { return it }
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
/**
|
||||
* Entry point is {@link com.intellij.python.community.services.systemPython.SystemPythonService}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python.systemPythonSpi
|
||||
package com.intellij.python.community.services.systemPython
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.platform.eel.EelApi
|
||||
import com.intellij.python.community.services.systemPython.SystemPythonProvider.Companion.EP
|
||||
import com.jetbrains.python.PythonBinary
|
||||
import com.jetbrains.python.systemPythonSpi.SystemPythonProvider.Companion.EP
|
||||
|
||||
/**
|
||||
* Register [EP] to [findSystemPythons]
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
<id>pycharm.systemPython.tests</id>
|
||||
<dependencies>
|
||||
<module name="intellij.python.community.services.systemPython"/>
|
||||
<plugin id="PythonCore"/>
|
||||
</dependencies>
|
||||
<extensions defaultExtensionNs="Pythonid">
|
||||
|
||||
@@ -5,9 +5,9 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.platform.eel.EelApi
|
||||
import com.intellij.platform.eel.provider.localEel
|
||||
import com.intellij.python.community.services.systemPython.SystemPythonProvider
|
||||
import com.intellij.python.community.testFramework.testEnv.TypeVanillaPython3
|
||||
import com.jetbrains.python.PythonBinary
|
||||
import com.jetbrains.python.systemPythonSpi.SystemPythonProvider
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.toSet
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 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.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python.sdk.configuration
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
|
||||
|
||||
@@ -3,13 +3,13 @@ package com.jetbrains.python.sdk.uv
|
||||
|
||||
import com.intellij.platform.eel.EelApi
|
||||
import com.intellij.platform.eel.provider.localEel
|
||||
import com.intellij.python.community.services.systemPython.SystemPythonProvider
|
||||
import com.jetbrains.python.PythonBinary
|
||||
import com.jetbrains.python.sdk.uv.impl.createUvLowLevel
|
||||
import com.jetbrains.python.sdk.uv.impl.hasUvExecutable
|
||||
import com.jetbrains.python.systemPythonSpi.SystemPythonProvider
|
||||
import java.nio.file.Path
|
||||
|
||||
class UvSystemPythonProvider : SystemPythonProvider {
|
||||
internal class UvSystemPythonProvider : SystemPythonProvider {
|
||||
override suspend fun findSystemPythons(eelApi: EelApi): Result<Set<PythonBinary>> {
|
||||
if (eelApi != localEel || !hasUvExecutable()) {
|
||||
// TODO: support for remote execution
|
||||
|
||||
Reference in New Issue
Block a user