Skip to content

Commit

Permalink
[fix] Fix python debugging (bazelbuild#6847)
Browse files Browse the repository at this point in the history
* [fix] Fix python debugging

* Format

* Logging

* Annotation
  • Loading branch information
agluszak authored Oct 10, 2024
1 parent 21343f0 commit 41e93fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
31 changes: 15 additions & 16 deletions python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import com.jetbrains.python.debugger.PyDebugProcess;
import com.jetbrains.python.debugger.PyDebugRunner;
import com.jetbrains.python.run.PythonCommandLineState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.concurrency.Promise;
import org.jetbrains.concurrency.Promises;

import java.net.ServerSocket;

/** Blaze plugin specific {@link PyDebugRunner}. */
Expand All @@ -57,11 +61,11 @@ public boolean canRun(String executorId, RunProfile profile) {
}

@Override
protected PyDebugProcess createDebugProcess(
XDebugSession xDebugSession,
ServerSocket serverSocket,
ExecutionResult executionResult,
PythonCommandLineState pythonCommandLineState) {
protected @NotNull PyDebugProcess createDebugProcess(
@NotNull XDebugSession xDebugSession,
ServerSocket serverSocket,
ExecutionResult executionResult,
PythonCommandLineState pythonCommandLineState) {
PyDebugProcess process =
super.createDebugProcess(
xDebugSession, serverSocket, executionResult, pythonCommandLineState);
Expand All @@ -70,19 +74,14 @@ protected PyDebugProcess createDebugProcess(
}

@Override
protected RunContentDescriptor doExecute(RunProfileState state, ExecutionEnvironment environment)
throws ExecutionException {
protected @NotNull Promise<RunContentDescriptor> execute(
@NotNull ExecutionEnvironment environment,
@NotNull RunProfileState state) throws ExecutionException {
if (!(state instanceof BlazePyDummyRunProfileState)) {
return null;
return Promises.resolvedPromise();
}
EventLoggingService.getInstance().logEvent(getClass(), "debugging-python");
try {
state = ((BlazePyDummyRunProfileState) state).toNativeState(environment);
return super.doExecute(state, environment);
} catch (ExecutionException e) {
throw e;
} catch (Exception e) {
throw new ExecutionException(e);
}

return super.execute(environment, ((BlazePyDummyRunProfileState) state).toNativeState(environment));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.intellij.util.execution.ParametersListUtil;
import com.jetbrains.python.console.PyDebugConsoleBuilder;
import com.jetbrains.python.console.PythonDebugLanguageConsoleView;
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
import com.jetbrains.python.run.CommandLinePatcher;
import com.jetbrains.python.run.PythonConfigurationType;
import com.jetbrains.python.run.PythonRunConfiguration;
Expand Down Expand Up @@ -125,7 +126,9 @@ PythonScriptCommandLineState toNativeState(ExecutionEnvironment env) throws Exec
if (sdk == null) {
throw new ExecutionException("Can't find a Python SDK when debugging a python target.");
}
nativeConfig.setModule(null);

var modules = AbstractPythonRunConfiguration.getValidModules(env.getProject());
nativeConfig.setModule(modules.get(0));
nativeConfig.setSdkHome(sdk.getHomePath());

BlazePyRunConfigState handlerState =
Expand Down

0 comments on commit 41e93fc

Please sign in to comment.