From c20337a4ddb50987b246c8a2ce184ef6f8af226a Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 1 Mar 2016 18:54:36 +0100 Subject: [PATCH] Pass executable path directly --- .../attach/PyLocalAttachDebuggerProvider.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/attach/PyLocalAttachDebuggerProvider.java b/python/src/com/jetbrains/python/debugger/attach/PyLocalAttachDebuggerProvider.java index 83656896afff..b6c139a8a507 100644 --- a/python/src/com/jetbrains/python/debugger/attach/PyLocalAttachDebuggerProvider.java +++ b/python/src/com/jetbrains/python/debugger/attach/PyLocalAttachDebuggerProvider.java @@ -32,7 +32,7 @@ import com.intellij.xdebugger.attach.XLocalAttachGroup; import com.jetbrains.python.sdk.PythonSdkType; import org.jetbrains.annotations.NotNull; -import java.util.Collection; +import java.io.File; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -55,12 +55,19 @@ public class PyLocalAttachDebuggerProvider implements XLocalAttachDebuggerProvid List result = contextHolder.getUserData(DEBUGGERS_KEY); if (result != null) return result; - result = ContainerUtil.map(sdksForAttachment(processInfo), new Function() { - @Override - public XLocalAttachDebugger fun(Sdk sdk) { - return new PyLocalAttachDebugger(sdk); - } - }); + if (processInfo.getExecutableCannonicalPath().isPresent() && + new File(processInfo.getExecutableCannonicalPath().get()).exists()) { + result = + Lists.newArrayList(new PyLocalAttachDebugger(processInfo.getExecutableCannonicalPath().get())); + } + else { + result = ContainerUtil.map(PythonSdkType.getAllLocalCPythons(), new Function() { + @Override + public XLocalAttachDebugger fun(Sdk sdk) { + return new PyLocalAttachDebugger(sdk); + } + }); + } // most recent python version goes first Collections.sort(result, new Comparator() { @@ -75,25 +82,19 @@ public class PyLocalAttachDebuggerProvider implements XLocalAttachDebuggerProvid } return Collections.emptyList(); } - - private static Collection sdksForAttachment(ProcessInfo info) { - if (info.getExecutableCannonicalPath().isPresent()) { - Sdk sdk = PythonSdkType.findSdkByPath(info.getExecutableCannonicalPath().get()); - if (sdk != null) { - return Lists.newArrayList(sdk); - } - } - - return PythonSdkType.getAllLocalCPythons(); - } - + private static class PyLocalAttachDebugger implements XLocalAttachDebugger { - @NotNull private final Sdk mySdk; + private final String mySdkHome; @NotNull private final String myName; public PyLocalAttachDebugger(@NotNull Sdk sdk) { - mySdk = sdk; - myName = PythonSdkType.getInstance().getVersionString(mySdk) + " Debugger"; + mySdkHome = sdk.getHomePath(); + myName = PythonSdkType.getInstance().getVersionString(sdk) + " Debugger"; + } + + public PyLocalAttachDebugger(@NotNull String sdkHome) { + mySdkHome = sdkHome; + myName = "Python Debugger"; } @NotNull @@ -105,7 +106,7 @@ public class PyLocalAttachDebuggerProvider implements XLocalAttachDebuggerProvid @NotNull @Override public XDebugSession attachDebugSession(@NotNull Project project, @NotNull ProcessInfo processInfo) throws ExecutionException { - PyAttachToProcessDebugRunner runner = new PyAttachToProcessDebugRunner(project, processInfo.getPid(), mySdk.getHomePath()); + PyAttachToProcessDebugRunner runner = new PyAttachToProcessDebugRunner(project, processInfo.getPid(), mySdkHome); return runner.launch(); } }