diff --git a/python/helpers/pydev/pydevd_frame.py b/python/helpers/pydev/pydevd_frame.py index 0d270276bbe9..85c566346eab 100644 --- a/python/helpers/pydev/pydevd_frame.py +++ b/python/helpers/pydev/pydevd_frame.py @@ -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': diff --git a/python/helpers/pydev/pydevd_signature.py b/python/helpers/pydev/pydevd_signature.py index 77559b35ae88..6ec3dc8bcbe5 100644 --- a/python/helpers/pydev/pydevd_signature.py +++ b/python/helpers/pydev/pydevd_signature.py @@ -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))) diff --git a/python/src/com/jetbrains/python/debugger/PyDebugRunner.java b/python/src/com/jetbrains/python/debugger/PyDebugRunner.java index 70ca7dd2f2ec..62dce9f8018d 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugRunner.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugRunner.java @@ -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 params = commandLine.getEnvParams(); + + if (params == null) { + params = Maps.newHashMap(); + commandLine.setEnvParams(params); + } + + List roots = Lists.newArrayList(); + for (VirtualFile contentRoot : ProjectRootManager.getInstance(project).getContentRoots()) { + roots.add(contentRoot.getPath()); + } + + params.put(PYCHARM_PROJECT_ROOTS, StringUtil.join(roots, File.pathSeparator)); + } } diff --git a/python/src/com/jetbrains/python/sdk/PythonEnvUtil.java b/python/src/com/jetbrains/python/sdk/PythonEnvUtil.java index 015c04759b02..4b5df7b1e20c 100644 --- a/python/src/com/jetbrains/python/sdk/PythonEnvUtil.java +++ b/python/src/com/jetbrains/python/sdk/PythonEnvUtil.java @@ -62,7 +62,7 @@ public class PythonEnvUtil { assert source != null; Set 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 envs, String key, Collection values) { for (String val : values) { - addToEnv(envs, key, val); + addPathToEnv(envs, key, val); } } - public static void addToEnv(Map envs, String key, String value) { + public static void addPathToEnv(Map 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 envs, String value) { - addToEnv(envs, PYTHONPATH, value); + addPathToEnv(envs, PYTHONPATH, value); } @Nullable public static List getPythonPathList(Map envs) { - String pythonPath = envs.get(PYTHONPATH); + return getPathListFromEnv(envs, PYTHONPATH); + } + + public static List getPathListFromEnv(Map envs, String envKey) { + String pythonPath = envs.get(envKey); if (pythonPath != null) { String[] paths = pythonPath.split(Character.toString(File.pathSeparatorChar)); return Lists.newArrayList(paths); diff --git a/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java index cf77e38d3f33..e0d408761949 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java @@ -194,7 +194,7 @@ public abstract class PythonSdkFlavor { } public static void addToEnv(final String key, String value, Map envs) { - PythonEnvUtil.addToEnv(envs, key, value); + PythonEnvUtil.addPathToEnv(envs, key, value); } static Map getEnv(GeneralCommandLine cmd) {