mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Run debugger as a module.
This commit is contained in:
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public interface HelperModule {
|
||||
public interface PythonHelper {
|
||||
void addToPythonPath(@NotNull Map<String, String> environment);
|
||||
|
||||
void addToGroup(@NotNull ParamsGroup group, @NotNull GeneralCommandLine cmd);
|
||||
@@ -28,31 +28,35 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public enum PythonHelpersLocator implements HelperModule {
|
||||
COVERAGEPY("", "coveragepy.zip"), COVERAGE("run_coverage", "coverage.zip", "run_coverage.py"),
|
||||
DEBUGGER("pydevd", "debugger.zip", "pydev/pydevd.py"),
|
||||
CONSOLE("pydevconsole", "debugger.zip", "pydev/pydevconsole.py");
|
||||
public enum PythonHelpersLocator implements PythonHelper {
|
||||
COVERAGEPY("", "coveragepy"), COVERAGE("run_coverage", "coverage"),
|
||||
DEBUGGER("pydevd", "pydev"),
|
||||
CONSOLE("pydevconsole", "pydev");
|
||||
|
||||
@NotNull
|
||||
private PathModule findModule(String moduleName, String zipPath, String ... fallbackPaths) {
|
||||
if (getHelperFile(zipPath).isFile()) {
|
||||
return new ZipModule(moduleName, zipPath);
|
||||
private PathPythonHelper findModule(String moduleName, String path) {
|
||||
if (getHelperFile(path + ".zip").isFile()) {
|
||||
return new ModulePythonHelper(moduleName, path + ".zip");
|
||||
}
|
||||
for (String p: fallbackPaths) {
|
||||
if (getHelperFile(p).exists()) {
|
||||
return new PathModule(p);
|
||||
}
|
||||
|
||||
if (getHelperFile(path).isDirectory()) {
|
||||
return new ModulePythonHelper(moduleName, path);
|
||||
}
|
||||
throw new IllegalStateException("Corrupted installation. Helper module not found: " + name());
|
||||
|
||||
if (getHelperFile(path).isFile()) {
|
||||
return new ScriptPythonHelper(path);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Corrupted installation. Helper not found: " + name());
|
||||
}
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.PythonHelpersLocator");
|
||||
private static final String COMMUNITY_SUFFIX = "-community";
|
||||
|
||||
private PathModule myModule;
|
||||
private PathPythonHelper myModule;
|
||||
|
||||
PythonHelpersLocator(String moduleName, String path, String ... fallbackPaths) {
|
||||
myModule = findModule(moduleName, path, fallbackPaths);
|
||||
PythonHelpersLocator(String moduleName, String pythonPath) {
|
||||
myModule = findModule(moduleName, pythonPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,10 +109,10 @@ public enum PythonHelpersLocator implements HelperModule {
|
||||
return new File(PathManager.getHomePath(), "python").getPath();
|
||||
}
|
||||
|
||||
public static class PathModule implements HelperModule {
|
||||
private final File myPath;
|
||||
public static class PathPythonHelper implements PythonHelper {
|
||||
protected final File myPath;
|
||||
|
||||
public PathModule(String relativePath) {
|
||||
public PathPythonHelper(String relativePath) {
|
||||
myPath = getHelperFile(relativePath);
|
||||
}
|
||||
|
||||
@@ -129,10 +133,10 @@ public enum PythonHelpersLocator implements HelperModule {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ZipModule extends PathModule {
|
||||
public static class ModulePythonHelper extends PathPythonHelper {
|
||||
private final String myModuleName;
|
||||
|
||||
public ZipModule(String moduleName, String relativePath) {
|
||||
public ModulePythonHelper(String moduleName, String relativePath) {
|
||||
super(relativePath);
|
||||
this.myModuleName = moduleName;
|
||||
}
|
||||
@@ -143,6 +147,18 @@ public enum PythonHelpersLocator implements HelperModule {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScriptPythonHelper extends PathPythonHelper {
|
||||
public ScriptPythonHelper(String relativePath) {
|
||||
super(relativePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToPythonPath(@NotNull Map<String, String> environment) {
|
||||
PythonEnvUtil.setPythonDontWriteBytecode(environment);
|
||||
PythonEnvUtil.addToPythonPath(environment, myPath.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addToPythonPath(@NotNull Map<String, String> environment) {
|
||||
|
||||
@@ -233,8 +233,9 @@ public class PyDebugRunner extends GenericProgramRunner {
|
||||
@NotNull ParamsGroup debugParams,
|
||||
int serverLocalPort,
|
||||
@NotNull PythonCommandLineState pyState,
|
||||
@NotNull GeneralCommandLine generalCommandLine) {
|
||||
debugParams.addParameter(PythonHelpersLocator.getHelperPath(DEBUGGER_MAIN));
|
||||
@NotNull GeneralCommandLine cmd) {
|
||||
PythonHelpersLocator.DEBUGGER.addToGroup(debugParams, cmd);
|
||||
|
||||
if (pyState.isMultiprocessDebug()) {
|
||||
//noinspection SpellCheckingInspection
|
||||
debugParams.addParameter("--multiproc");
|
||||
@@ -253,10 +254,10 @@ public class PyDebugRunner extends GenericProgramRunner {
|
||||
}
|
||||
|
||||
if (PyDebuggerOptionsProvider.getInstance(project).isSupportGeventDebugging()) {
|
||||
generalCommandLine.getEnvironment().put(GEVENT_SUPPORT, "True");
|
||||
cmd.getEnvironment().put(GEVENT_SUPPORT, "True");
|
||||
}
|
||||
|
||||
addProjectRootsToEnv(project, generalCommandLine);
|
||||
addProjectRootsToEnv(project, cmd);
|
||||
|
||||
final String[] debuggerArgs = new String[]{
|
||||
CLIENT_PARAM, "127.0.0.1",
|
||||
|
||||
Reference in New Issue
Block a user