diff --git a/python/src/com/jetbrains/python/console/RunPythonConsoleAction.java b/python/src/com/jetbrains/python/console/RunPythonConsoleAction.java index e1aecc2ed98e..51f740048ec1 100644 --- a/python/src/com/jetbrains/python/console/RunPythonConsoleAction.java +++ b/python/src/com/jetbrains/python/console/RunPythonConsoleAction.java @@ -1,5 +1,8 @@ package com.jetbrains.python.console; +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.Collections2; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.LangDataKeys; @@ -12,9 +15,12 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.IconLoader; import com.jetbrains.python.PyBundle; import com.jetbrains.python.buildout.BuildoutFacet; +import com.jetbrains.python.run.PythonCommandLineState; import com.jetbrains.python.sdk.PythonSdkType; import org.jetbrains.annotations.Nullable; +import java.util.Collection; + /** * @author oleg */ @@ -25,26 +31,26 @@ public class RunPythonConsoleAction extends AnAction implements DumbAware { getTemplatePresentation().setIcon(IconLoader.getIcon("/com/jetbrains/python/icons/python.png")); } - @Override - public void update(final AnActionEvent e) { - e.getPresentation().setVisible(false); - e.getPresentation().setEnabled(false); - final Project project = e.getData(LangDataKeys.PROJECT); - if (project != null){ - for (Module module : ModuleManager.getInstance(project).getModules()) { - e.getPresentation().setVisible(true); - if (PythonSdkType.findPythonSdk(module) != null){ - e.getPresentation().setEnabled(true); - break; - } + @Override + public void update(final AnActionEvent e) { + e.getPresentation().setVisible(false); + e.getPresentation().setEnabled(false); + final Project project = e.getData(LangDataKeys.PROJECT); + if (project != null) { + for (Module module : ModuleManager.getInstance(project).getModules()) { + e.getPresentation().setVisible(true); + if (PythonSdkType.findPythonSdk(module) != null) { + e.getPresentation().setEnabled(true); + break; } } } + } - public void actionPerformed(final AnActionEvent e) { - final Project project = e.getData(LangDataKeys.PROJECT); - runPythonConsole(project); - } + public void actionPerformed(final AnActionEvent e) { + final Project project = e.getData(LangDataKeys.PROJECT); + runPythonConsole(project); + } @Nullable public static PydevConsoleRunner runPythonConsole(Project project) { @@ -54,7 +60,7 @@ public class RunPythonConsoleAction extends AnAction implements DumbAware { for (Module m : ModuleManager.getInstance(project).getModules()) { module = m; sdk = PythonSdkType.findPythonSdk(module); - if (sdk != null){ + if (sdk != null) { break; } } @@ -63,14 +69,24 @@ public class RunPythonConsoleAction extends AnAction implements DumbAware { String[] setup_fragment; - final String path = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath(); - final String self_path_append = "sys.path.append('" + path + "')"; + Collection pythonPath = PythonCommandLineState.collectPythonPath(module); + + final String path = Joiner.on(", ").join(Collections2.transform(pythonPath, new Function() { + @Override + public String apply(String input) { + return "'" + input + "'"; + } + })); + String workingDir = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath(); + final String self_path_append = "sys.path.extend([" + path + "])"; BuildoutFacet facet = BuildoutFacet.getInstance(module); if (facet != null) { setup_fragment = new String[]{facet.getPathPrependStatement(), self_path_append}; } - else setup_fragment = new String[]{self_path_append}; + else { + setup_fragment = new String[]{self_path_append}; + } - return PydevConsoleRunner.run(project, sdk, PyBundle.message("python.console"), path, setup_fragment); + return PydevConsoleRunner.run(project, sdk, PyBundle.message("python.console"), workingDir, setup_fragment); } } diff --git a/python/src/com/jetbrains/python/run/PythonCommandLineState.java b/python/src/com/jetbrains/python/run/PythonCommandLineState.java index e9882887f9c6..61880c8afc71 100644 --- a/python/src/com/jetbrains/python/run/PythonCommandLineState.java +++ b/python/src/com/jetbrains/python/run/PythonCommandLineState.java @@ -39,6 +39,7 @@ import com.jetbrains.python.sdk.PythonSdkAdditionalData; import com.jetbrains.python.sdk.PythonSdkFlavor; import com.jetbrains.python.sdk.PythonSdkType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; @@ -234,9 +235,14 @@ public abstract class PythonCommandLineState extends CommandLineState { } protected Collection collectPythonPath() { + final Module module = myConfig.getModule(); + return collectPythonPath(module); + } + + @NotNull + public static Collection collectPythonPath(@Nullable Module module) { Collection pythonPathList = Sets.newLinkedHashSet(); pythonPathList.add(PythonHelpersLocator.getHelpersRoot().getPath()); - final Module module = myConfig.getModule(); if (module != null) { final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); addRoots(pythonPathList, moduleRootManager.getContentRoots()); @@ -275,6 +281,4 @@ public abstract class PythonCommandLineState extends CommandLineState { protected void buildCommandLineParameters(GeneralCommandLine commandLine) { } - - }