Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2013-02-20 14:32:51 +04:00
5 changed files with 64 additions and 12 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ class PyDBFrame:
return None
if event == 'call':
sendSignatureCallTrace(mainDebugger, frame)
sendSignatureCallTrace(mainDebugger, frame, filename)
if event not in ('line', 'call', 'return'):
if event == 'exception':
+16 -2
View File
@@ -1,5 +1,7 @@
import inspect
import trace
import os
trace._warn = lambda *args: None # workaround for http://bugs.python.org/issue17143 (PY-8706)
import gc
from pydevd_comm import CMD_SIGNATURE_CALL_TRACE, NetCommand
@@ -23,6 +25,17 @@ class Signature(object):
class SignatureFactory(object):
def __init__(self):
self._caller_cache = {}
self.project_roots = os.getenv('PYCHARM_PROJECT_ROOTS', '').split(os.pathsep)
def is_in_scope(self, filename):
filename = normcase(realpath(filename))
for root in self.project_roots:
root = normcase(realpath(root))
if filename.startsWith(root):
return True
return False
def create_signature(self, frame):
try:
@@ -109,9 +122,10 @@ def create_signature_message(signature):
cmdText = ''.join(cmdTextList)
return NetCommand(CMD_SIGNATURE_CALL_TRACE, 0, cmdText)
def sendSignatureCallTrace(dbg, frame):
def sendSignatureCallTrace(dbg, frame, filename):
if dbg.signature_factory:
dbg.writer.addCommand(create_signature_message(dbg.signature_factory.create_signature(frame)))
if dbg.signature_factory.is_in_scope(filename):
dbg.writer.addCommand(create_signature_message(dbg.signature_factory.create_signature(frame)))
@@ -1,5 +1,7 @@
package com.jetbrains.python.debugger;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.Executor;
@@ -15,11 +17,16 @@ import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.xdebugger.XDebugProcess;
import com.intellij.xdebugger.XDebugProcessStarter;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XDebuggerManager;
import com.jetbrains.appengine.util.StringUtils;
import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.console.PythonConsoleView;
import com.jetbrains.python.console.PythonDebugConsoleCommunication;
@@ -32,8 +39,11 @@ import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.net.ServerSocket;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author yole
@@ -45,6 +55,7 @@ public class PyDebugRunner extends GenericProgramRunner {
public static final String CLIENT_PARAM = "--client";
public static final String PORT_PARAM = "--port";
public static final String FILE_PARAM = "--file";
public static final String PYCHARM_PROJECT_ROOTS = "PYCHARM_PROJECT_ROOTS";
@NotNull
public String getRunnerId() {
@@ -139,7 +150,9 @@ public class PyDebugRunner extends GenericProgramRunner {
return new CommandLinePatcher[]{createDebugServerPatcher(project, state, serverLocalPort), createRunConfigPatcher(state, profile)};
}
private static CommandLinePatcher createDebugServerPatcher(final Project project, final PythonCommandLineState pyState, final int serverLocalPort) {
private static CommandLinePatcher createDebugServerPatcher(final Project project,
final PythonCommandLineState pyState,
final int serverLocalPort) {
return new CommandLinePatcher() {
public void patchCommandLine(GeneralCommandLine commandLine) {
@@ -160,12 +173,16 @@ public class PyDebugRunner extends GenericProgramRunner {
}
}
fillDebugParameters(project, debugParams, serverLocalPort, pyState);
fillDebugParameters(project, debugParams, serverLocalPort, pyState, commandLine);
}
};
}
private static void fillDebugParameters(Project project, ParamsGroup debugParams, int serverLocalPort, PythonCommandLineState pyState) {
private static void fillDebugParameters(@NotNull Project project,
@NotNull ParamsGroup debugParams,
int serverLocalPort,
@NotNull PythonCommandLineState pyState,
@NotNull GeneralCommandLine generalCommandLine) {
debugParams.addParameter(PythonHelpersLocator.getHelperPath(DEBUGGER_MAIN));
if (pyState.isMultiprocessDebug()) {
debugParams.addParameter("--multiproc");
@@ -177,6 +194,7 @@ public class PyDebugRunner extends GenericProgramRunner {
if (PyDebuggerOptionsProvider.getInstance(project).isSaveCallSignatures()) {
debugParams.addParameter("--save-signatures");
addProjectRootsToEnv(project, generalCommandLine);
}
final String[] debuggerArgs = new String[]{
@@ -188,4 +206,20 @@ public class PyDebugRunner extends GenericProgramRunner {
debugParams.addParameter(s);
}
}
private static void addProjectRootsToEnv(@NotNull Project project, @NotNull GeneralCommandLine commandLine) {
Map<String, String> params = commandLine.getEnvParams();
if (params == null) {
params = Maps.newHashMap();
commandLine.setEnvParams(params);
}
List<String> roots = Lists.newArrayList();
for (VirtualFile contentRoot : ProjectRootManager.getInstance(project).getContentRoots()) {
roots.add(contentRoot.getPath());
}
params.put(PYCHARM_PROJECT_ROOTS, StringUtil.join(roots, File.pathSeparator));
}
}
@@ -62,7 +62,7 @@ public class PythonEnvUtil {
assert source != null;
Set<String> vals = Sets.newHashSet(source.split(File.pathSeparator));
if (!vals.contains(value)) {
return source + File.pathSeparatorChar + value;
return source + File.pathSeparator + value;
}
else {
return source;
@@ -73,11 +73,11 @@ public class PythonEnvUtil {
public static void addToEnv(Map<String, String> envs, String key, Collection<String> values) {
for (String val : values) {
addToEnv(envs, key, val);
addPathToEnv(envs, key, val);
}
}
public static void addToEnv(Map<String, String> envs, String key, String value) {
public static void addPathToEnv(Map<String, String> envs, String key, String value) {
if (!StringUtil.isEmpty(value)) {
if (envs.containsKey(key)) {
envs.put(key, appendToPathEnvVar(envs.get(key), value));
@@ -93,13 +93,17 @@ public class PythonEnvUtil {
}
public static void addToPythonPath(Map<String, String> envs, String value) {
addToEnv(envs, PYTHONPATH, value);
addPathToEnv(envs, PYTHONPATH, value);
}
@Nullable
public static List<String> getPythonPathList(Map<String, String> envs) {
String pythonPath = envs.get(PYTHONPATH);
return getPathListFromEnv(envs, PYTHONPATH);
}
public static List<String> getPathListFromEnv(Map<String, String> envs, String envKey) {
String pythonPath = envs.get(envKey);
if (pythonPath != null) {
String[] paths = pythonPath.split(Character.toString(File.pathSeparatorChar));
return Lists.newArrayList(paths);
@@ -194,7 +194,7 @@ public abstract class PythonSdkFlavor {
}
public static void addToEnv(final String key, String value, Map<String, String> envs) {
PythonEnvUtil.addToEnv(envs, key, value);
PythonEnvUtil.addPathToEnv(envs, key, value);
}
static Map<String, String> getEnv(GeneralCommandLine cmd) {