diff --git a/python/helpers/pycharm/_jb_find_best_place.py b/python/helpers/pycharm/_jb_find_best_place.py new file mode 100644 index 000000000000..1d1e04ce66d0 --- /dev/null +++ b/python/helpers/pycharm/_jb_find_best_place.py @@ -0,0 +1,14 @@ +# First arg is project name. It searches for best place for project + +import os, sys + +project_name = sys.argv[1] +current_folder = os.getcwd() + +while True: + project_folder = os.path.join(current_folder, project_name) + if not os.path.exists(project_name): + print project_folder + break + else: + project_name += "_" diff --git a/python/src/com/jetbrains/python/newProject/PythonProjectGenerator.java b/python/src/com/jetbrains/python/newProject/PythonProjectGenerator.java index fcc791673e7e..6b514a450eed 100644 --- a/python/src/com/jetbrains/python/newProject/PythonProjectGenerator.java +++ b/python/src/com/jetbrains/python/newProject/PythonProjectGenerator.java @@ -67,7 +67,7 @@ public abstract class PythonProjectGenerator imp final PythonRemoteInterpreterManager remoteManager = PythonRemoteInterpreterManager.getInstance(); final Sdk sdk = (settings != null ? settings.getSdk() : null); if (remoteManager != null && PythonSdkType.isRemote(sdk)) { - remoteManager.prepareRemoteSettingsIfNeeded(project, sdk, configureProject); + remoteManager.prepareRemoteSettingsIfNeeded(module, sdk, configureProject); } else { configureProject.run(); diff --git a/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java b/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java index 5040c9c88783..5954116ab85a 100644 --- a/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java +++ b/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java @@ -22,6 +22,7 @@ import com.intellij.execution.configurations.ParamsGroup; import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.process.ProcessOutput; import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkAdditionalData; @@ -140,7 +141,7 @@ public abstract class PythonRemoteInterpreterManager { * * @param callAfterCheck what to call after configuration completes (runs on AWT) */ - public abstract void prepareRemoteSettingsIfNeeded(@NotNull final Project project, + public abstract void prepareRemoteSettingsIfNeeded(@NotNull final Module module, @NotNull final Sdk sdk, @NotNull final Runnable callAfterCheck); diff --git a/python/src/com/jetbrains/python/run/PythonTask.java b/python/src/com/jetbrains/python/run/PythonTask.java index 2a64a0b56bfc..ea850eb913eb 100644 --- a/python/src/com/jetbrains/python/run/PythonTask.java +++ b/python/src/com/jetbrains/python/run/PythonTask.java @@ -17,6 +17,8 @@ package com.jetbrains.python.run; import com.google.common.collect.Lists; import com.intellij.execution.ExecutionException; +import com.intellij.execution.Output; +import com.intellij.execution.OutputListener; import com.intellij.execution.RunContentExecutor; import com.intellij.execution.configurations.EncodingEnvironmentUtil; import com.intellij.execution.configurations.GeneralCommandLine; @@ -39,9 +41,11 @@ import com.jetbrains.python.console.PydevConsoleRunner; import com.jetbrains.python.sdk.PySdkUtil; import com.jetbrains.python.sdk.PythonEnvUtil; import com.jetbrains.python.sdk.PythonSdkType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -71,11 +75,24 @@ public class PythonTask { this(module, runTabTitle, PythonSdkType.findPythonSdk(module)); } + @NotNull + public static PythonTask create(@NotNull final Module module, + @NotNull final String runTabTitle, + @NotNull final Sdk sdk) { + // Ctor throws checked exception which is not good, so this wrapper saves user from dumb code + try { + return new PythonTask(module, runTabTitle, sdk); + } + catch (final ExecutionException ignored) { + throw new AssertionError("Exception thrown file should not be"); + } + } + public PythonTask(final Module module, final String runTabTitle, @Nullable final Sdk sdk) throws ExecutionException { myModule = module; myRunTabTitle = runTabTitle; mySdk = sdk; - if (mySdk == null) { + if (mySdk == null) { // TODO: Get rid of such a weird contract throw new ExecutionException("Cannot find Python interpreter for selected module"); } } @@ -167,11 +184,11 @@ public class PythonTask { NotNullFunction escaperFunction = StringUtil.escaper(false, "|>$\"'& "); StringBuilder paramString; if (myHelper != null) { - paramString= new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myHelper.asParamString())); + paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myHelper.asParamString())); myHelper.addToPythonPath(cmd.getEnvironment()); } else { - paramString= new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript)); + paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript)); } for (String p : myParameters) { paramString.append(" ").append(p); @@ -246,4 +263,27 @@ public class PythonTask { .withHelpId(myHelpId) .run(); } + + + /** + * Runs task with out console + * @return stdout + * @throws ExecutionException in case of error. Consider using {@link com.intellij.execution.util.ExecutionErrorDialog} + */ + @NotNull //TODO: DOC, ExecutionErrorDialog + public final String runNoConsole() throws ExecutionException { + + final ProcessHandler process = createProcess(new HashMap<>()); + final OutputListener listener = new OutputListener(); + process.addProcessListener(listener); + process.startNotify(); + process.waitFor(); + final Output output = listener.getOutput(); + final int exitCode = output.getExitCode(); + if (exitCode == 0) { + return output.getStdout(); + } + throw new ExecutionException(String.format("Error on python side. " + + "Exit code: %s, err: %s out: %s", exitCode, output.getStderr(), output.getStdout())); + } }