Skip to content

Commit

Permalink
Pass executable path directly
Browse files Browse the repository at this point in the history
  • Loading branch information
trofimander committed Mar 1, 2016
1 parent 805e818 commit c20337a
Showing 1 changed file with 24 additions and 23 deletions.
Expand Up @@ -32,7 +32,7 @@
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;
Expand All @@ -55,12 +55,19 @@ public List<XLocalAttachDebugger> getAvailableDebuggers(@NotNull Project project
List<XLocalAttachDebugger> result = contextHolder.getUserData(DEBUGGERS_KEY);
if (result != null) return result;

result = ContainerUtil.map(sdksForAttachment(processInfo), new Function<Sdk, XLocalAttachDebugger>() {
@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<Sdk, XLocalAttachDebugger>() {
@Override
public XLocalAttachDebugger fun(Sdk sdk) {
return new PyLocalAttachDebugger(sdk);
}
});
}

// most recent python version goes first
Collections.sort(result, new Comparator<XLocalAttachDebugger>() {
Expand All @@ -75,25 +82,19 @@ public int compare(XLocalAttachDebugger a, XLocalAttachDebugger b) {
}
return Collections.emptyList();
}

private static Collection<Sdk> 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
Expand All @@ -105,7 +106,7 @@ public String getDebuggerDisplayName() {
@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();
}
}
Expand Down

0 comments on commit c20337a

Please sign in to comment.