mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
Implement path mapping logic for target-based Python interpreters
GitOrigin-RevId: e175ccec653df17d962d745d5054b8241638df1b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b7624ee26b
commit
e582beb3dc
@@ -39,8 +39,11 @@ import com.jetbrains.python.remote.PyRemotePathMapper;
|
||||
import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase;
|
||||
import com.jetbrains.python.remote.PythonRemoteInterpreterManager;
|
||||
import com.jetbrains.python.run.PythonCommandLineState;
|
||||
import com.jetbrains.python.run.target.PySdkTargetPaths;
|
||||
import com.jetbrains.python.sdk.PySdkExtKt;
|
||||
import com.jetbrains.python.sdk.PythonEnvUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkUtil;
|
||||
import com.jetbrains.python.target.PyTargetAwareAdditionalData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -65,6 +68,10 @@ public interface PydevConsoleRunner {
|
||||
static PyRemotePathMapper getPathMapper(@NotNull Project project,
|
||||
Sdk sdk,
|
||||
PyConsoleOptions.PyConsoleSettings consoleSettings) {
|
||||
if (PySdkExtKt.isTargetBased(sdk)) {
|
||||
PyTargetAwareAdditionalData data = (PyTargetAwareAdditionalData)sdk.getSdkAdditionalData();
|
||||
return PySdkTargetPaths.getPathMapper(project, consoleSettings, data);
|
||||
}
|
||||
if (PythonSdkUtil.isRemote(sdk)) {
|
||||
PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData = (PyRemoteSdkAdditionalDataBase)sdk.getSdkAdditionalData();
|
||||
return getPathMapper(project, consoleSettings, remoteSdkAdditionalData);
|
||||
|
||||
@@ -9,11 +9,15 @@ import com.intellij.execution.target.value.constant
|
||||
import com.intellij.execution.target.value.getTargetEnvironmentValueForLocalPath
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.remote.RemoteMappingsManager
|
||||
import com.intellij.remote.RemoteSdkAdditionalData
|
||||
import com.jetbrains.python.console.PyConsoleOptions
|
||||
import com.jetbrains.python.console.PyConsoleOptions.PyConsoleSettings
|
||||
import com.jetbrains.python.console.PydevConsoleRunner
|
||||
import com.jetbrains.python.remote.PyRemotePathMapper
|
||||
import com.jetbrains.python.remote.PythonRemoteInterpreterManager
|
||||
import com.jetbrains.python.remote.PythonRemoteInterpreterManager.appendBasicMappings
|
||||
import com.jetbrains.python.target.PyTargetAwareAdditionalData
|
||||
|
||||
/**
|
||||
* @param pathMapper corresponds to the path mappings specified in the run configuration
|
||||
@@ -68,4 +72,27 @@ private fun getPythonConsolePathMapper(project: Project, sdk: Sdk?): PyRemotePat
|
||||
PydevConsoleRunner.getPathMapper(project, sdk, PyConsoleOptions.getInstance(project).pythonConsoleSettings)
|
||||
|
||||
private fun PyRemotePathMapper.convertToRemoteOrNull(localPath: String): String? =
|
||||
takeIf { it.canReplaceLocal(localPath) }?.convertToRemote(localPath)
|
||||
takeIf { it.canReplaceLocal(localPath) }?.convertToRemote(localPath)
|
||||
|
||||
fun getPathMapper(project: Project, consoleSettings: PyConsoleSettings, data: PyTargetAwareAdditionalData): PyRemotePathMapper {
|
||||
val remotePathMapper = appendBasicMappings(project, null, data)
|
||||
consoleSettings.mappingSettings?.let { mappingSettings ->
|
||||
remotePathMapper.addAll(mappingSettings.pathMappings, PyRemotePathMapper.PyPathMappingType.USER_DEFINED)
|
||||
}
|
||||
return remotePathMapper
|
||||
}
|
||||
|
||||
private fun appendBasicMappings(project: Project?,
|
||||
pathMapper: PyRemotePathMapper?,
|
||||
data: PyTargetAwareAdditionalData): PyRemotePathMapper {
|
||||
val newPathMapper = PyRemotePathMapper.cloneMapper(pathMapper)
|
||||
PythonRemoteInterpreterManager.addHelpersMapping(data, newPathMapper)
|
||||
newPathMapper.addAll(data.pathMappings.pathMappings, PyRemotePathMapper.PyPathMappingType.SYS_PATH)
|
||||
if (project != null) {
|
||||
val mappings = RemoteMappingsManager.getInstance(project).getForServer(PythonRemoteInterpreterManager.PYTHON_PREFIX, data.sdkId)
|
||||
if (mappings != null) {
|
||||
newPathMapper.addAll(mappings.settings, PyRemotePathMapper.PyPathMappingType.USER_DEFINED)
|
||||
}
|
||||
}
|
||||
return newPathMapper
|
||||
}
|
||||
Reference in New Issue
Block a user