Merge branch 'master' into traff/zip_helpers
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 31 Aug 2015 21:10:02 +0000 (23:10 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 31 Aug 2015 21:10:02 +0000 (23:10 +0200)
# Conflicts:
# platform/util/src/com/intellij/openapi/util/BuildNumber.java
# python/ipnb/src/org/jetbrains/plugins/ipnb/configuration/IpnbConnectionManager.java

78 files changed:
platform/core-impl/src/com/intellij/execution/process/CommandLineArgumentsProvider.java
python/helpers/coverage_runner/__init__.py [new file with mode: 0644]
python/helpers/coverage_runner/run_coverage.py [moved from python/helpers/run_coverage.py with 76% similarity]
python/helpers/coveragepy/__init__.py [new file with mode: 0644]
python/helpers/coveragepy/coverage/__init__.py [moved from python/helpers/coverage/__init__.py with 100% similarity]
python/helpers/coveragepy/coverage/__main__.py [moved from python/helpers/coverage/__main__.py with 100% similarity]
python/helpers/coveragepy/coverage/annotate.py [moved from python/helpers/coverage/annotate.py with 100% similarity]
python/helpers/coveragepy/coverage/backward.py [moved from python/helpers/coverage/backward.py with 100% similarity]
python/helpers/coveragepy/coverage/bytecode.py [moved from python/helpers/coverage/bytecode.py with 100% similarity]
python/helpers/coveragepy/coverage/cmdline.py [moved from python/helpers/coverage/cmdline.py with 100% similarity]
python/helpers/coveragepy/coverage/codeunit.py [moved from python/helpers/coverage/codeunit.py with 100% similarity]
python/helpers/coveragepy/coverage/collector.py [moved from python/helpers/coverage/collector.py with 100% similarity]
python/helpers/coveragepy/coverage/config.py [moved from python/helpers/coverage/config.py with 100% similarity]
python/helpers/coveragepy/coverage/control.py [moved from python/helpers/coverage/control.py with 100% similarity]
python/helpers/coveragepy/coverage/data.py [moved from python/helpers/coverage/data.py with 100% similarity]
python/helpers/coveragepy/coverage/debug.py [moved from python/helpers/coverage/debug.py with 100% similarity]
python/helpers/coveragepy/coverage/execfile.py [moved from python/helpers/coverage/execfile.py with 100% similarity]
python/helpers/coveragepy/coverage/files.py [moved from python/helpers/coverage/files.py with 100% similarity]
python/helpers/coveragepy/coverage/fullcoverage/encodings.py [moved from python/helpers/coverage/fullcoverage/encodings.py with 100% similarity]
python/helpers/coveragepy/coverage/html.py [moved from python/helpers/coverage/html.py with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/coverage_html.js [moved from python/helpers/coverage/htmlfiles/coverage_html.js with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/index.html [moved from python/helpers/coverage/htmlfiles/index.html with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/jquery.hotkeys.js [moved from python/helpers/coverage/htmlfiles/jquery.hotkeys.js with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/jquery.isonscreen.js [moved from python/helpers/coverage/htmlfiles/jquery.isonscreen.js with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/jquery.min.js [moved from python/helpers/coverage/htmlfiles/jquery.min.js with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/jquery.tablesorter.min.js [moved from python/helpers/coverage/htmlfiles/jquery.tablesorter.min.js with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/keybd_closed.png [moved from python/helpers/coverage/htmlfiles/keybd_closed.png with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/keybd_open.png [moved from python/helpers/coverage/htmlfiles/keybd_open.png with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/pyfile.html [moved from python/helpers/coverage/htmlfiles/pyfile.html with 100% similarity]
python/helpers/coveragepy/coverage/htmlfiles/style.css [moved from python/helpers/coverage/htmlfiles/style.css with 100% similarity]
python/helpers/coveragepy/coverage/misc.py [moved from python/helpers/coverage/misc.py with 100% similarity]
python/helpers/coveragepy/coverage/parser.py [moved from python/helpers/coverage/parser.py with 100% similarity]
python/helpers/coveragepy/coverage/phystokens.py [moved from python/helpers/coverage/phystokens.py with 100% similarity]
python/helpers/coveragepy/coverage/report.py [moved from python/helpers/coverage/report.py with 100% similarity]
python/helpers/coveragepy/coverage/results.py [moved from python/helpers/coverage/results.py with 100% similarity]
python/helpers/coveragepy/coverage/summary.py [moved from python/helpers/coverage/summary.py with 100% similarity]
python/helpers/coveragepy/coverage/templite.py [moved from python/helpers/coverage/templite.py with 100% similarity]
python/helpers/coveragepy/coverage/tracer.c [moved from python/helpers/coverage/tracer.c with 100% similarity]
python/helpers/coveragepy/coverage/version.py [moved from python/helpers/coverage/version.py with 100% similarity]
python/helpers/coveragepy/coverage/xmlreport.py [moved from python/helpers/coverage/xmlreport.py with 100% similarity]
python/helpers/pydev/pydevd.py
python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.java
python/ipnb/src/org/jetbrains/plugins/ipnb/configuration/IpnbConnectionManager.java
python/openapi/src/com/jetbrains/python/run/AbstractPythonRunConfigurationParams.java
python/openapi/src/com/jetbrains/python/run/PythonRunParams.java [new file with mode: 0644]
python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.java
python/python-rest/src/com/jetbrains/rest/run/RestCommandLineState.java
python/python-rest/src/com/jetbrains/rest/run/docutils/DocutilsCommandLineState.java
python/python-rest/src/com/jetbrains/rest/run/sphinx/SphinxCommandLineState.java
python/python-rest/src/com/jetbrains/rest/sphinx/SphinxBaseCommand.java
python/src/com/jetbrains/python/HelperPackage.java [new file with mode: 0644]
python/src/com/jetbrains/python/PythonHelper.java [new file with mode: 0644]
python/src/com/jetbrains/python/PythonHelpersLocator.java
python/src/com/jetbrains/python/buildout/BuildoutFacet.java
python/src/com/jetbrains/python/console/PyConsoleOptions.java
python/src/com/jetbrains/python/console/PydevConsoleRunner.java
python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.java
python/src/com/jetbrains/python/debugger/PyDebugRunner.java
python/src/com/jetbrains/python/debugger/attach/PyAttachToProcessCommandLineState.java
python/src/com/jetbrains/python/documentation/PyStructuredDocstringFormatter.java
python/src/com/jetbrains/python/inspections/quickfix/GenerateBinaryStubsFix.java
python/src/com/jetbrains/python/run/AbstractPythonRunConfiguration.java
python/src/com/jetbrains/python/run/PythonCommandLineState.java
python/src/com/jetbrains/python/run/PythonScriptCommandLineState.java
python/src/com/jetbrains/python/run/PythonTask.java
python/src/com/jetbrains/python/sdk/PySdkUtil.java
python/src/com/jetbrains/python/sdk/PythonEnvUtil.java
python/src/com/jetbrains/python/sdk/PythonSdkType.java
python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java
python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java
python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java
python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java
python/src/com/jetbrains/python/testing/doctest/PythonDocTestCommandLineState.java
python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java
python/src/com/jetbrains/python/testing/pytest/PyTestCommandLineState.java
python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java
python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java
python/testSrc/com/jetbrains/python/fixtures/PyCommandLineTestCase.java

index 207ba23c76ae4d56c2900a9f8cf1b4c0846b64e6..c7ca1e1bcf779ec22965b1043da0c2e390669882 100644 (file)
@@ -25,7 +25,10 @@ import java.util.Map;
 
 /**
  * @author Roman.Chernyatchik, oleg
+ * @deprecated Use GeneralCommandLine instead
+ * @deprecated Usages only in Ruby. Move to Ruby module?
  */
+@Deprecated
 public class CommandLineArgumentsProvider {
     /**
    * @return Commands to execute (one command corresponds to one add argument)
diff --git a/python/helpers/coverage_runner/__init__.py b/python/helpers/coverage_runner/__init__.py
new file mode 100644 (file)
index 0000000..595e381
--- /dev/null
@@ -0,0 +1 @@
+__author__ = 'traff'
similarity index 76%
rename from python/helpers/run_coverage.py
rename to python/helpers/coverage_runner/run_coverage.py
index 57859456e99e2d3ec174fe8ee3ae73897014107d..8de5a4770a132cf2cb730720a9f89340a80320bb 100644 (file)
@@ -2,12 +2,11 @@
 
 import os
 import sys
-import imp
 
-helpers_root = os.getenv('PYCHARM_HELPERS_ROOT')
-if helpers_root:
+bundled_coverage_path = os.getenv('BUNDLED_COVERAGE_PATH')
+if bundled_coverage_path:
     sys_path_backup = sys.path
-    sys.path = [p for p in sys.path if p!=helpers_root]
+    sys.path = [p for p in sys.path if p != bundled_coverage_path]
     from coverage.cmdline import main
     sys.path = sys_path_backup
 else:
@@ -31,6 +30,16 @@ if run_cov:
     a_file.write(os.getcwd()+"\n")
     for path in sys.path: a_file.write(path + "\n")
     a_file.close()
+
+argv = []
+for arg in sys.argv:
+    if arg.startswith('-m'):
+        argv.append('-m')
+        argv.append(arg[2:])
+    else:
+        argv.append(arg)
+sys.argv = argv
+
 main()
 if run_cov:
     main(["xml", "-o", coverage_file + ".xml", "--ignore-errors"])
\ No newline at end of file
diff --git a/python/helpers/coveragepy/__init__.py b/python/helpers/coveragepy/__init__.py
new file mode 100644 (file)
index 0000000..595e381
--- /dev/null
@@ -0,0 +1 @@
+__author__ = 'traff'
index 7dbb6d8cde9fc20462aa47971e4bca1abe47dd7e..708971b844e7ae38c7e8597cee944a5c65912d84 100644 (file)
@@ -1713,19 +1713,6 @@ class PyDB:
         return None
 
     def run(self, file, globals=None, locals=None, module=False, set_trace=True):
-        if module:
-            filename = self.get_fullname(file)
-            if filename is None:
-                sys.stderr.write("No module named %s\n" % file)
-                return
-            else:
-                file = filename
-
-        if os.path.isdir(file):
-            new_target = os.path.join(file, '__main__.py')
-            if os.path.isfile(new_target):
-                file = new_target
-
         if globals is None:
             m = save_main_module(file, 'pydevd')
             globals = m.__dict__
@@ -1769,7 +1756,26 @@ class PyDB:
             sys.stderr.write("Matplotlib support in debugger failed\n")
             traceback.print_exc()
 
-        pydev_imports.execfile(file, globals, locals)  # execute the script
+        launch = pydev_imports.execfile
+
+        if module:
+            try:
+                import runpy
+                launch = lambda f, g, l: runpy.run_module(f, init_globals=g)
+            except:
+                filename = self.get_fullname(file)
+                if filename is None:
+                    sys.stderr.write("No module named %s\n" % file)
+                    return
+                else:
+                    file = filename
+
+        if os.path.isdir(file):
+            new_target = os.path.join(file, '__main__.py')
+            if os.path.isfile(new_target):
+                file = new_target
+
+        launch(file, globals, locals)  # execute the script
 
     def exiting(self):
         sys.stdout.flush()
@@ -1834,7 +1840,11 @@ def processCommandLine(argv):
             setup['server'] = True
         elif argv[i] == '--file':
             del argv[i]
-            setup['file'] = argv[i]
+            file = argv[i]
+            if file.startswith('-m'):
+                setup['module'] = True
+                file = file[2:]
+            setup['file'] = file
             i = len(argv) # pop out, file is our last argument
         elif argv[i] == '--DEBUG_RECORD_SOCKET_READS':
             del argv[i]
index e792d4a1f2da18320bf4d1bd54cfce7e70fda7d8..2d07a852be724026e5b430212cd8d3130d1cf3e3 100644 (file)
@@ -364,4 +364,10 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
     public void sdkHomeSelected(Sdk sdk, String newSdkHome) {
     }
   }
+
+  @Override
+  public String getModuleName() {
+    Module module = getModule();
+    return module != null? module.getName() : null;
+  }
 }
index aab8fc34387329c6cd9445f56a2f0cc00a02b947..04ce2139bac9fe6d4cde73686adb1cca34159d92 100644 (file)
@@ -28,7 +28,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.HyperlinkAdapter;
 import com.intellij.util.Alarm;
 import com.intellij.util.io.HttpRequests;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.packaging.PyPackage;
 import com.jetbrains.python.packaging.PyPackageManager;
 import com.jetbrains.python.sdk.PythonSdkType;
@@ -265,6 +265,7 @@ public final class IpnbConnectionManager implements ProjectComponent {
     }
     catch (ExecutionException ignored) {
     }
+    final Map<String, String> env = ImmutableMap.of("PYCHARM_EP_DIST", "ipython", "PYCHARM_EP_NAME", "ipython");
 
     final Pair<String, String> hostPort = getHostPortFromUrl(url);
     if (hostPort == null) {
index 113da30692a5c2a788fe1351c722896578cced67..812cb72ebe901e4632367024712dd8b5d874a98a 100644 (file)
 package com.jetbrains.python.run;
 
 import com.intellij.openapi.module.Module;
-import com.intellij.util.PathMappingSettings;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Map;
-
 /**
  * @author Leonid Shalupov
  */
-public interface AbstractPythonRunConfigurationParams {
-  String getInterpreterOptions();
-
-  void setInterpreterOptions(String interpreterOptions);
-
-  String getWorkingDirectory();
-
-  void setWorkingDirectory(String workingDirectory);
-
-  @Nullable
-  String getSdkHome();
-
-  void setSdkHome(String sdkHome);
-
+public interface AbstractPythonRunConfigurationParams extends PythonRunParams {
   @Nullable
   Module getModule();
-
-  void setModule(Module module);
-
-  boolean isUseModuleSdk();
-
-  void setUseModuleSdk(boolean useModuleSdk);
-
-  boolean isPassParentEnvs();
-
-  void setPassParentEnvs(boolean passParentEnvs);
-
-  Map<String, String> getEnvs();
-
-  void setEnvs(final Map<String, String> envs);
-
-  @Nullable
-  PathMappingSettings getMappingSettings();
-
-  void setMappingSettings(@Nullable PathMappingSettings mappingSettings);
-
-  boolean shouldAddContentRoots();
-  boolean shouldAddSourceRoots();
-
-  void setAddContentRoots(boolean flag);
-  void setAddSourceRoots(boolean flag);
 }
diff --git a/python/openapi/src/com/jetbrains/python/run/PythonRunParams.java b/python/openapi/src/com/jetbrains/python/run/PythonRunParams.java
new file mode 100644 (file)
index 0000000..b9b2b98
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.run;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.util.PathMappingSettings;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
+
+/**
+ * @author traff
+ */
+public interface PythonRunParams {
+  String getInterpreterOptions();
+
+  void setInterpreterOptions(String interpreterOptions);
+
+  String getWorkingDirectory();
+
+  void setWorkingDirectory(String workingDirectory);
+
+  @Nullable
+  String getSdkHome();
+
+  void setSdkHome(String sdkHome);
+
+  void setModule(Module module);
+
+  String getModuleName();
+
+  boolean isUseModuleSdk();
+
+  void setUseModuleSdk(boolean useModuleSdk);
+
+  boolean isPassParentEnvs();
+
+  void setPassParentEnvs(boolean passParentEnvs);
+
+  Map<String, String> getEnvs();
+
+  void setEnvs(Map<String, String> envs);
+
+  @Nullable
+  PathMappingSettings getMappingSettings();
+
+  void setMappingSettings(@Nullable PathMappingSettings mappingSettings);
+
+  boolean shouldAddContentRoots();
+
+  boolean shouldAddSourceRoots();
+
+  void setAddContentRoots(boolean flag);
+
+  void setAddSourceRoots(boolean flag);
+}
index ee46566b89cce1691273c85d9d24042964edd4ec..bd0fb418c5be6b00ab2fc34f9890c4a5ae142ed5 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.execution.util.PathMappingsComponent;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
 import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.projectRoots.impl.SdkListCellRenderer;
@@ -184,6 +185,12 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
     return myModuleComboBox.getSelectedModule();
   }
 
+  @Override
+  public String getModuleName() {
+    Module module = getModule();
+    return module != null? module.getName() : null;
+  }
+
   public void setModule(Module module) {
     myModuleComboBox.setSelectedModule(module);
   }
@@ -273,5 +280,4 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
   public void setAddSourceRoots(boolean flag) {
     myAddSourceRootsCheckbox.setSelected(flag);
   }
-
 }
index 0e9b16b745fc2b1bc2d7684d0ad0e8fd272c2ad6..4e89eac4799cd9525954782b5ebb554a0c3770ab 100644 (file)
@@ -26,7 +26,7 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.HelperPackage;
 import com.jetbrains.python.run.PythonCommandLineState;
 import com.jetbrains.python.run.PythonProcessRunner;
 import org.jetbrains.annotations.Nullable;
@@ -48,28 +48,26 @@ public abstract class RestCommandLineState extends PythonCommandLineState {
   @Override
   protected void buildCommandLineParameters(GeneralCommandLine commandLine) {
     ParametersList parametersList = commandLine.getParametersList();
-    ParamsGroup exe_options = parametersList.getParamsGroup(GROUP_EXE_OPTIONS);
-    assert exe_options != null;
-    exe_options.addParametersString(myConfiguration.getInterpreterOptions());
-
-    ParamsGroup script_parameters = parametersList.getParamsGroup(GROUP_SCRIPT);
-    assert script_parameters != null;
-    String runner = PythonHelpersLocator.getHelperPath(getRunnerPath());
-    if (runner != null )
-      script_parameters.addParameter(runner);
+    ParamsGroup exeOptions = parametersList.getParamsGroup(GROUP_EXE_OPTIONS);
+    assert exeOptions != null;
+    exeOptions.addParametersString(myConfiguration.getInterpreterOptions());
+
+    ParamsGroup scriptParameters = parametersList.getParamsGroup(GROUP_SCRIPT);
+    assert scriptParameters != null;
+    getRunner().addToGroup(scriptParameters, commandLine);
     final String key = getKey();
     if (key != null)
-      script_parameters.addParameter(key);
-    script_parameters.addParameter(getTask());
+      scriptParameters.addParameter(key);
+    scriptParameters.addParameter(getTask());
 
     final String params = myConfiguration.getParams();
-    if (params != null) script_parameters.addParametersString(params);
+    if (params != null) scriptParameters.addParametersString(params);
 
     if (!StringUtil.isEmptyOrSpaces(myConfiguration.getInputFile()))
-      script_parameters.addParameter(myConfiguration.getInputFile());
+      scriptParameters.addParameter(myConfiguration.getInputFile());
 
     if (!StringUtil.isEmptyOrSpaces(myConfiguration.getOutputFile()))
-      script_parameters.addParameter(myConfiguration.getOutputFile());
+      scriptParameters.addParameter(myConfiguration.getOutputFile());
 
     if (!StringUtil.isEmptyOrSpaces(myConfiguration.getWorkingDirectory()))
       commandLine.setWorkDirectory(myConfiguration.getWorkingDirectory());
@@ -106,7 +104,7 @@ public abstract class RestCommandLineState extends PythonCommandLineState {
     return null;
   }
 
-  protected abstract String getRunnerPath();
+  protected abstract HelperPackage getRunner();
 
   protected abstract String getTask();
 
index b06279e485fb4d2c276cddc32c97430abc8ffd02..e677f37b9763544066c3b7484057ef4dbd652969 100644 (file)
@@ -19,6 +19,8 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.ide.BrowserUtil;
 import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.python.HelperPackage;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.rest.run.RestCommandLineState;
 import org.jetbrains.annotations.Nullable;
 
@@ -51,8 +53,8 @@ public class DocutilsCommandLineState extends RestCommandLineState {
   }
 
   @Override
-  protected String getRunnerPath() {
-    return "rest_runners/rst2smth.py";
+  protected HelperPackage getRunner() {
+    return PythonHelper.REST_RUNNER;
   }
 
   @Override
index 9224930bd46ad1edcd2802f6ebd89f1d57e06239..8bb913f178fd8970d2a67a7cb82d2f382bf64c85 100644 (file)
@@ -18,6 +18,8 @@ package com.jetbrains.rest.run.sphinx;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.python.HelperPackage;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.rest.run.RestCommandLineState;
 
 import java.util.Collections;
@@ -45,8 +47,8 @@ public class SphinxCommandLineState extends RestCommandLineState {
   }
 
   @Override
-  protected String getRunnerPath() {
-    return "rest_runners/sphinx_runner.py";
+  protected HelperPackage getRunner() {
+    return PythonHelper.SPHINX_RUNNER;
   }
 
   @Override
index 1a9c3435a7c9ac54b570eb2cd0e0dfe542f3733b..a34986fb0735db650674e27a8b1cd11643fc2728 100644 (file)
@@ -31,7 +31,7 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.TextFieldWithBrowseButton;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.ReSTService;
 import com.jetbrains.python.buildout.BuildoutFacet;
 import com.jetbrains.python.run.PythonCommandLineState;
@@ -139,30 +139,25 @@ public class SphinxBaseCommand {
   }
 
   protected GeneralCommandLine createCommandLine(Module module, List<String> params) throws ExecutionException {
-    GeneralCommandLine cmd = new GeneralCommandLine();
-
     Sdk sdk = PythonSdkType.findPythonSdk(module);
     if (sdk == null) {
       throw new ExecutionException("No sdk specified");
     }
 
     ReSTService service = ReSTService.getInstance(module);
+
+    String sdkHomePath = sdk.getHomePath();
+
+    final GeneralCommandLine cmd = PythonHelper.LOAD_ENTRY_POINT.newCommandLine(sdkHomePath, Lists.<String>newArrayList());
+
     cmd.setWorkDirectory(service.getWorkdir().isEmpty()? module.getProject().getBaseDir().getPath(): service.getWorkdir());
-    PythonCommandLineState.createStandardGroupsIn(cmd);
-    ParamsGroup script_params = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
-    assert script_params != null;
+    PythonCommandLineState.createStandardGroups(cmd);
+    ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
+    assert scriptParams != null;
 
-    String commandPath = PythonHelpersLocator.getHelperPath("pycharm/pycharm_load_entry_point.py");
-    if (commandPath == null) {
-      throw new ExecutionException("Cannot find sphinx-quickstart.");
-    }
-    final String sdkHomePath = sdk.getHomePath();
-    if (sdkHomePath != null)
-      cmd.setExePath(sdkHomePath);
-    cmd.addParameter(commandPath);
     if (params != null) {
       for (String p : params) {
-        script_params.addParameter(p);
+        scriptParams.addParameter(p);
       }
     }
 
diff --git a/python/src/com/jetbrains/python/HelperPackage.java b/python/src/com/jetbrains/python/HelperPackage.java
new file mode 100644 (file)
index 0000000..e212d93
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python;
+
+import com.intellij.execution.configurations.GeneralCommandLine;
+import com.intellij.execution.configurations.ParamsGroup;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author traff
+ */
+public interface HelperPackage {
+  void addToPythonPath(@NotNull Map<String, String> environment);
+
+  String getPythonPath();
+
+  void addToGroup(@NotNull ParamsGroup group, @NotNull GeneralCommandLine cmd);
+
+  String asParamString();
+
+  GeneralCommandLine newCommandLine(String sdkPath, List<String> parameters);
+}
diff --git a/python/src/com/jetbrains/python/PythonHelper.java b/python/src/com/jetbrains/python/PythonHelper.java
new file mode 100644 (file)
index 0000000..12d041b
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python;
+
+import com.google.common.collect.Lists;
+import com.intellij.execution.configurations.GeneralCommandLine;
+import com.intellij.execution.configurations.ParamsGroup;
+import com.intellij.openapi.util.io.FileUtil;
+import com.jetbrains.python.sdk.PythonEnvUtil;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import static com.jetbrains.python.PythonHelpersLocator.getHelperFile;
+import static com.jetbrains.python.PythonHelpersLocator.getHelpersRoot;
+
+/**
+ * @author traff
+ */
+public enum PythonHelper implements HelperPackage {
+  COVERAGEPY("coveragepy", ""), COVERAGE("coverage_runner", "run_coverage"),
+  DEBUGGER("pydev", "pydevd"),
+  ATTACH_DEBUGGER("pydev", "pydevd_attach_to_process.attach_pydevd"),
+
+  CONSOLE("pydev", "pydevconsole"),
+  RUN_IN_CONSOLE("pydev", "pydev_run_in_console"),
+  PROFILER("profiler", "run_profiler"),
+
+  LOAD_ENTRY_POINT("pycharm", "pycharm_load_entry_point"),
+
+  // Test runners
+  UT("pycharm", "utrunner"),
+  SETUPPY("pycharm", "pycharm_setup_runner"),
+  NOSE("pycharm", "noserunner"),
+  PYTEST("pycharm", "pytestrunner"),
+  ATTEST("pycharm", "attestrunner"),
+  DOCSTRING("pycharm", "docrunner"),
+
+  BEHAVE("pycharm", "behave_runner"),
+  LETTUCE("pycharm", "lettuce_runner"),
+
+  DJANGO_TEST_MANAGE("pycharm", "django_test_manage"),
+  DJANGO_MANAGE("pycharm", "django_manage"),
+  MANAGE_TASKS_PROVIDER("pycharm", "_jb_manage_tasks_provider"),
+
+  BUILDOUT_ENGULFER("pycharm", "buildout_engulfer"),
+
+  EPYDOC_FORMATTER("epydoc_formatter.py"),
+  REST_FORMATTER("rest_formatter.py"),
+
+  EXTRA_SYSPATH("extra_syspath.py"),
+  SYSPATH("syspath.py"),
+
+  PEP8("pep8.py"),
+
+  REST_RUNNER("rest_runners/rst2smth.py"),
+
+  SPHINX_RUNNER("rest_runners/sphinx_runner.py");
+
+  @NotNull
+  private static PathHelperPackage findModule(String moduleEntryPoint, String path, boolean asModule) {
+    if (getHelperFile(path + ".zip").isFile()) {
+      return new ModuleHelperPackage(moduleEntryPoint, path + ".zip");
+    }
+
+    if (!asModule && new File(getHelperFile(path), moduleEntryPoint + ".py").isFile()) {
+      return new ScriptPythonHelper(moduleEntryPoint + ".py", getHelperFile(path));
+    }
+
+    return new ModuleHelperPackage(moduleEntryPoint, path);
+  }
+
+  private PathHelperPackage myModule;
+
+  PythonHelper(String pythonPath, String moduleName) {
+    this(pythonPath, moduleName, false);
+  }
+
+  PythonHelper(String pythonPath, String moduleName, boolean asModule) {
+    myModule = findModule(moduleName, pythonPath, asModule);
+  }
+
+  PythonHelper(String helperScript) {
+    myModule = new ScriptPythonHelper(helperScript, getHelpersRoot());
+  }
+
+
+  public String getPythonPath() {
+    return myModule.getPythonPath();
+  }
+
+  public abstract static class PathHelperPackage implements HelperPackage {
+    protected final File myPath;
+
+    PathHelperPackage(String path) {
+      myPath = new File(path);
+    }
+
+    @Override
+    public void addToPythonPath(@NotNull Map<String, String> environment) {
+      PythonEnvUtil.addToPythonPath(environment, myPath.getAbsolutePath());
+    }
+
+    @Override
+    public void addToGroup(@NotNull ParamsGroup group, @NotNull GeneralCommandLine cmd) {
+      addToPythonPath(cmd.getEnvironment());
+      group.addParameter(asParamString());
+    }
+
+    @Override
+    public String asParamString() {
+      return FileUtil.toSystemDependentName(myPath.getAbsolutePath());
+    }
+
+    @Override
+    public GeneralCommandLine newCommandLine(String sdkPath, List<String> parameters) {
+      List<String> args = Lists.newArrayList();
+      args.add(sdkPath);
+      args.add(asParamString());
+      args.addAll(parameters);
+      GeneralCommandLine cmd = new GeneralCommandLine(args);
+      addToPythonPath(cmd.getEnvironment());
+      return cmd;
+    }
+  }
+
+  /**
+   * Module Python helper can be executed from zip-archive
+   */
+  public static class ModuleHelperPackage extends PathHelperPackage {
+    private final String myModuleName;
+
+    public ModuleHelperPackage(String moduleName, String relativePath) {
+      super(getHelperFile(relativePath).getAbsolutePath());
+      this.myModuleName = moduleName;
+    }
+
+    @Override
+    public String asParamString() {
+      return "-m" + myModuleName;
+    }
+
+    @Override
+    public String getPythonPath() {
+      return FileUtil.toSystemDependentName(myPath.getAbsolutePath());
+    }
+  }
+
+  /**
+   * Script Python helper can be executed as a Python script, therefore
+   * PYTHONDONTWRITEBYTECODE option is set not to spoil installation
+   * with .pyc files
+   */
+  public static class ScriptPythonHelper extends PathHelperPackage {
+    private String myPythonPath;
+
+    public ScriptPythonHelper(String script, File pythonPath) {
+      super(new File(pythonPath, script).getAbsolutePath());
+      myPythonPath = pythonPath.getAbsolutePath();
+    }
+
+    @Override
+    public void addToPythonPath(@NotNull Map<String, String> environment) {
+      PythonEnvUtil.setPythonDontWriteBytecode(environment);
+      PythonEnvUtil.addToPythonPath(environment, myPythonPath);
+    }
+
+    @Override
+    public String getPythonPath() {
+      return myPythonPath;
+    }
+  }
+
+
+  @Override
+  public void addToPythonPath(@NotNull Map<String, String> environment) {
+    myModule.addToPythonPath(environment);
+  }
+
+  @Override
+  public void addToGroup(@NotNull ParamsGroup group, @NotNull GeneralCommandLine cmd) {
+    myModule.addToGroup(group, cmd);
+  }
+
+
+  @Override
+  public String asParamString() {
+    return myModule.asParamString();
+  }
+
+  @Override
+  public GeneralCommandLine newCommandLine(String sdkPath, List<String> parameters) {
+    return myModule.newCommandLine(sdkPath, parameters);
+  }
+
+}
index 56def0180bfa85840c9f92e8a6fbb645eb487ac4..873caa01df97cbe42d6cdfa693c3ad1e3c56c712 100644 (file)
@@ -24,11 +24,9 @@ import java.io.File;
 
 public class PythonHelpersLocator {
   private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.PythonHelpersLocator");
-
   private static final String COMMUNITY_SUFFIX = "-community";
 
-  private PythonHelpersLocator() {
-  }
+  private PythonHelpersLocator() {}
 
   /**
    * @return the base directory under which various scripts, etc are stored.
@@ -52,6 +50,7 @@ public class PythonHelpersLocator {
 
   /**
    * Find a resource by name under helper root.
+   *
    * @param resourceName a path relative to helper root
    * @return absolute path of the resource
    */
@@ -61,6 +60,7 @@ public class PythonHelpersLocator {
 
   /**
    * Finds a resource file by name under helper root.
+   *
    * @param resourceName a path relative to helper root
    * @return a file object pointing to that path; existence is not checked.
    */
@@ -68,6 +68,7 @@ public class PythonHelpersLocator {
     return new File(getHelpersRoot(), resourceName);
   }
 
+
   public static String getPythonCommunityPath() {
     File pathFromUltimate = new File(PathManager.getHomePath(), "community/python");
     if (pathFromUltimate.exists()) {
index ab5c711a48c4ac2012bd6183d29b9e7da267cdae..5be81efe54ce73ad13cd37da5c03a0ae8e5174c2 100644 (file)
@@ -36,6 +36,8 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.*;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiFileFactory;
+import com.jetbrains.python.HelperPackage;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.PythonHelpersLocator;
 import com.jetbrains.python.buildout.config.BuildoutCfgLanguage;
 import com.jetbrains.python.buildout.config.psi.impl.BuildoutCfgFile;
@@ -287,13 +289,13 @@ public class BuildoutFacet extends Facet<BuildoutFacetConfiguration> implements
     Map<String, String> env = commandLine.getEnvironment();
     ParametersList params = commandLine.getParametersList();
     // alter execution script
-    ParamsGroup script_params = params.getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
-    assert script_params != null;
-    if (script_params.getParameters().size() > 0) {
-      String normal_script = script_params.getParameters().get(0); // expect DjangoUtil.MANAGE_FILE
-      String engulfer_path = PythonHelpersLocator.getHelperPath("pycharm/buildout_engulfer.py");
+    ParamsGroup scriptParams = params.getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
+    assert scriptParams != null;
+    if (scriptParams.getParameters().size() > 0) {
+      String normalScript = scriptParams.getParameters().get(0); // expect DjangoUtil.MANAGE_FILE
+      HelperPackage engulfer = PythonHelper.BUILDOUT_ENGULFER;
       env.put("PYCHARM_ENGULF_SCRIPT", getConfiguration().getScriptName());
-      script_params.getParametersList().replaceOrPrepend(normal_script, engulfer_path);
+      scriptParams.getParametersList().replaceOrPrepend(normalScript, engulfer.asParamString());
     }
     // add pycharm helpers to pythonpath so that fixGetpass is importable
 
index 1bf857347dc07ffd03831c1cbfde65d36d7a530c..64f0dd111fe82ce6a3013d0a38e1ca9d4cf5c969 100644 (file)
@@ -17,12 +17,15 @@ package com.jetbrains.python.console;
 
 import com.google.common.collect.Maps;
 import com.intellij.openapi.components.*;
+import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.util.PathMappingSettings;
 import com.intellij.util.containers.ComparatorUtil;
 import com.intellij.util.xmlb.annotations.*;
 import com.jetbrains.python.run.AbstractPyCommonOptionsForm;
+import com.jetbrains.python.run.AbstractPythonRunConfigurationParams;
+import com.jetbrains.python.run.PythonRunParams;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -84,7 +87,7 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
   }
 
   @Tag("console-settings")
-  public static class PyConsoleSettings {
+  public static class PyConsoleSettings implements PythonRunParams {
     public String myCustomStartScript = PydevConsoleRunner.CONSOLE_START_COMMAND;
     public String mySdkHome = null;
     public String myInterpreterOptions = "";
@@ -104,7 +107,7 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
       this.myCustomStartScript = myCustomStartScript;
     }
 
-    public void apply(AbstractPyCommonOptionsForm form) {
+    public void apply(AbstractPythonRunConfigurationParams form) {
       mySdkHome = form.getSdkHome();
       myInterpreterOptions = form.getInterpreterOptions();
       myEnvs = form.getEnvs();
@@ -129,7 +132,7 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
              || !myMappings.equals(form.getMappingSettings());
     }
 
-    public void reset(Project project, AbstractPyCommonOptionsForm form) {
+    public void reset(Project project, AbstractPythonRunConfigurationParams form) {
       form.setEnvs(myEnvs);
       form.setInterpreterOptions(myInterpreterOptions);
       form.setSdkHome(mySdkHome);
@@ -190,12 +193,12 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
     }
 
     @Attribute("add-content-roots")
-    public boolean addContentRoots() {
+    public boolean shouldAddContentRoots() {
       return myAddContentRoots;
     }
 
     @Attribute("add-source-roots")
-    public boolean addSourceRoots() {
+    public boolean shouldAddSourceRoots() {
       return myAddSourceRoots;
     }
 
@@ -217,6 +220,11 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
       mySdkHome = sdkHome;
     }
 
+    @Override
+    public void setModule(Module module) {
+      setModuleName(module.getName());
+    }
+
     public void setInterpreterOptions(String interpreterOptions) {
       myInterpreterOptions = interpreterOptions;
     }
@@ -225,6 +233,16 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
       myUseModuleSdk = useModuleSdk;
     }
 
+    @Override
+    public boolean isPassParentEnvs() {
+      return true; // doesn't make sense for console
+    }
+
+    @Override
+    public void setPassParentEnvs(boolean passParentEnvs) {
+      // doesn't make sense for console
+    }
+
     public void setModuleName(String moduleName) {
       myModuleName = moduleName;
     }
@@ -233,6 +251,17 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
       myEnvs = envs;
     }
 
+    @Nullable
+    @Override
+    public PathMappingSettings getMappingSettings() {
+      return null;
+    }
+
+    @Override
+    public void setMappingSettings(@Nullable PathMappingSettings mappingSettings) {
+
+    }
+
     public void setWorkingDirectory(String workingDirectory) {
       myWorkingDirectory = workingDirectory;
     }
index cf7659fcf9755bba4b402684ca4d44f92c7f83cc..1bfade993fc8640f582c4219daa3fdc329ebfacc 100644 (file)
@@ -24,10 +24,10 @@ import com.intellij.execution.ExecutionHelper;
 import com.intellij.execution.Executor;
 import com.intellij.execution.configurations.EncodingEnvironmentUtil;
 import com.intellij.execution.configurations.GeneralCommandLine;
+import com.intellij.execution.configurations.ParamsGroup;
 import com.intellij.execution.console.ConsoleHistoryController;
 import com.intellij.execution.console.LanguageConsoleView;
 import com.intellij.execution.console.ProcessBackedConsoleExecuteActionHandler;
-import com.intellij.execution.process.CommandLineArgumentsProvider;
 import com.intellij.execution.process.ProcessAdapter;
 import com.intellij.execution.process.ProcessEvent;
 import com.intellij.execution.process.ProcessOutputTypes;
@@ -59,7 +59,6 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Couple;
 import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.io.StreamUtil;
 import com.intellij.openapi.vfs.CharsetToolkit;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -80,7 +79,7 @@ import com.intellij.xdebugger.XDebugProcess;
 import com.intellij.xdebugger.XDebugProcessStarter;
 import com.intellij.xdebugger.XDebugSession;
 import com.intellij.xdebugger.XDebuggerManager;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.console.completion.PydevConsoleElement;
 import com.jetbrains.python.console.parsing.PythonConsoleData;
 import com.jetbrains.python.console.pydev.ConsoleCommunication;
@@ -91,7 +90,6 @@ import com.jetbrains.python.remote.PyRemotePathMapper;
 import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase;
 import com.jetbrains.python.remote.PyRemoteSdkCredentials;
 import com.jetbrains.python.remote.PythonRemoteInterpreterManager;
-import com.jetbrains.python.run.ProcessRunner;
 import com.jetbrains.python.run.PythonCommandLineState;
 import com.jetbrains.python.run.PythonTracebackFilter;
 import com.jetbrains.python.sdk.PySdkUtil;
@@ -126,7 +124,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
   public static final int PORTS_WAITING_TIMEOUT = 20000;
 
   private Sdk mySdk;
-  private CommandLineArgumentsProvider myCommandLineArgumentsProvider;
+  private GeneralCommandLine myGeneralCommandLine;
   protected int[] myPorts;
   private PydevConsoleCommunication myPydevConsoleCommunication;
   private PyConsoleProcessHandler myProcessHandler;
@@ -247,7 +245,8 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
 
   /**
    * Add requered ENV var to Python task to set its stdout charset to current project charset to allow it print correctly.
-   * @param envs map of envs to add variable
+   *
+   * @param envs    map of envs to add variable
    * @param project current project
    */
   public static void setCorrectStdOutEncoding(@NotNull final Map<String, String> envs, @NotNull final Project project) {
@@ -310,7 +309,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
 
     assert myPorts != null;
 
-    myCommandLineArgumentsProvider = createCommandLineArgumentsProvider(mySdk, myEnvironmentVariables, myPorts);
+    myGeneralCommandLine = createCommandLine(mySdk, myEnvironmentVariables, myPorts);
 
     try {
       super.initAndRun();
@@ -356,7 +355,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
 
     assert myPorts != null;
 
-    myCommandLineArgumentsProvider = createCommandLineArgumentsProvider(mySdk, myEnvironmentVariables, myPorts);
+    myGeneralCommandLine = createCommandLine(mySdk, myEnvironmentVariables, myPorts);
 
     UIUtil.invokeLaterIfNeeded(new Runnable() {
       @Override
@@ -393,35 +392,27 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
     return ports;
   }
 
-  protected CommandLineArgumentsProvider createCommandLineArgumentsProvider(final Sdk sdk,
-                                                                            final Map<String, String> environmentVariables,
-                                                                            int[] ports) {
-    final ArrayList<String> args = new ArrayList<String>();
-    args.add(sdk.getHomePath());
-    final String versionString = sdk.getVersionString();
-    if (versionString == null || !versionString.toLowerCase().contains("jython")) {
-      args.add("-u");
-    }
-    args.add(FileUtil.toSystemDependentName(PythonHelpersLocator.getHelperPath(PYDEV_PYDEVCONSOLE_PY)));
+  protected GeneralCommandLine createCommandLine(@NotNull final Sdk sdk,
+                                                 @NotNull final Map<String, String> environmentVariables,
+                                                 int[] ports) {
+    return doCreateConsoleCmdLine(ports, PythonHelper.CONSOLE);
+  }
+
+  @NotNull
+  protected GeneralCommandLine doCreateConsoleCmdLine(int[] ports, PythonHelper helper) {
+    PyConsoleOptions.PyConsoleSettings settings = PyConsoleOptions.getInstance(getProject()).getPythonConsoleSettings();
+
+    GeneralCommandLine cmd = PythonCommandLineState.createPythonCommandLine(getProject(), settings);
+    cmd.withWorkDirectory(getWorkingDir());
+
+    ParamsGroup group = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
+    helper.addToGroup(group, cmd);
+
     for (int port : ports) {
-      args.add(String.valueOf(port));
+      group.addParameter(String.valueOf(port));
     }
-    return new CommandLineArgumentsProvider() {
-      @Override
-      public String[] getArguments() {
-        return ArrayUtil.toStringArray(args);
-      }
 
-      @Override
-      public boolean passParentEnvs() {
-        return false;
-      }
-
-      @Override
-      public Map<String, String> getAdditionalEnvs() {
-        return addDefaultEnvironments(sdk, environmentVariables, getProject());
-      }
-    };
+    return cmd;
   }
 
   @Override
@@ -437,19 +428,18 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
     if (PySdkUtil.isRemote(mySdk)) {
       PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
       if (manager != null) {
-        return createRemoteConsoleProcess(manager, myCommandLineArgumentsProvider.getArguments(),
-                                          myCommandLineArgumentsProvider.getAdditionalEnvs());
+        return createRemoteConsoleProcess(manager, myGeneralCommandLine.getParametersList().getArray(),
+                                          myGeneralCommandLine.getEnvironment());
       }
       throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
     }
     else {
-      myCommandLine = myCommandLineArgumentsProvider.getCommandLineString();
-      Map<String, String> envs = myCommandLineArgumentsProvider.getAdditionalEnvs();
-      if (envs != null) {
-        EncodingEnvironmentUtil.fixDefaultEncodingIfMac(envs, getProject());
-      }
-      final Process server = ProcessRunner
-        .createProcess(getWorkingDir(), envs, myCommandLineArgumentsProvider.getArguments());
+      myCommandLine = myGeneralCommandLine.getCommandLineString();
+      Map<String, String> envs = myGeneralCommandLine.getEnvironment();
+      EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(envs, myGeneralCommandLine.getCharset());
+
+      final Process server = myGeneralCommandLine.createProcess();
+
       try {
         myPydevConsoleCommunication = new PydevConsoleCommunication(getProject(), myPorts[0], server, myPorts[1]);
       }
@@ -1023,7 +1013,8 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
 
     @Override
     public void actionPerformed(AnActionEvent e) {
-      PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(e.getData(CommonDataKeys.PROJECT), e.getData(LangDataKeys.MODULE));
+      PydevConsoleRunner runner =
+        PythonConsoleRunnerFactory.getInstance().createConsoleRunner(e.getData(CommonDataKeys.PROJECT), e.getData(LangDataKeys.MODULE));
       runner.createNewConsole();
     }
   }
index 19436e4b20f8dad75b0412c2ac32b71ee77b01ae..a75e8b8070e763fcd014dac73d807d17bc8b3f4e 100644 (file)
@@ -54,8 +54,8 @@ public class PydevConsoleRunnerFactory extends PythonConsoleRunnerFactory {
     String[] setupFragment;
 
     PyConsoleOptions.PyConsoleSettings settingsProvider = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
-    Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.addContentRoots(),
-                                                                             settingsProvider.addSourceRoots());
+    Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.shouldAddContentRoots(),
+                                                                             settingsProvider.shouldAddSourceRoots());
 
     if (pathMapper != null) {
       pythonPath = pathMapper.convertToRemote(pythonPath);
index 728936052ced33e8aa088c698a9956ed15ffb130..fa80077d1395bfd5ccf0415fc31fb718c55d28b7 100644 (file)
@@ -37,7 +37,7 @@ import com.intellij.xdebugger.XDebugProcess;
 import com.intellij.xdebugger.XDebugProcessStarter;
 import com.intellij.xdebugger.XDebugSession;
 import com.intellij.xdebugger.XDebuggerManager;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.console.PythonConsoleView;
 import com.jetbrains.python.console.PythonDebugConsoleCommunication;
 import com.jetbrains.python.console.PythonDebugLanguageConsoleView;
@@ -64,6 +64,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 MODULE_PARAM = "--module";
   public static final String IDE_PROJECT_ROOTS = "IDE_PROJECT_ROOTS";
   @SuppressWarnings("SpellCheckingInspection")
   public static final String GEVENT_SUPPORT = "GEVENT_SUPPORT";
@@ -249,8 +250,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) {
+    PythonHelper.DEBUGGER.addToGroup(debugParams, cmd);
+
     if (pyState.isMultiprocessDebug()) {
       //noinspection SpellCheckingInspection
       debugParams.addParameter("--multiproc");
@@ -269,10 +271,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",
index 04083e972dd6faaf7aa3ca5eb108ff55521bb587..e2b6f4b0aaeda229092d23d0c1ef62a9637573e8 100644 (file)
@@ -11,7 +11,7 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Key;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.debugger.PyRemoteDebugProcess;
 import com.jetbrains.python.debugger.PyRemoteDebugProcessAware;
 import com.jetbrains.python.run.PythonConfigurationType;
@@ -25,7 +25,7 @@ import java.io.OutputStream;
  * @author traff
  */
 public class PyAttachToProcessCommandLineState extends PythonScriptCommandLineState {
-  private final static String ATTACH_PYDEVD = "pydev/pydevd_attach_to_process/attach_pydevd.py";
+
 
   private PyAttachToProcessCommandLineState(PythonRunConfiguration runConfiguration,
                                             ExecutionEnvironment env) {
@@ -36,7 +36,7 @@ public class PyAttachToProcessCommandLineState extends PythonScriptCommandLineSt
     throws ExecutionException {
     PythonRunConfiguration conf =
       (PythonRunConfiguration)PythonConfigurationType.getInstance().getFactory().createTemplateConfiguration(project);
-    conf.setScriptName(PythonHelpersLocator.getHelperPath(ATTACH_PYDEVD));
+    conf.setScriptName(PythonHelper.ATTACH_DEBUGGER.asParamString());
     conf.setSdkHome(sdkPath);
     conf.setScriptParameters("--port " + port + " --pid " + pid);
 
index f74be9bdaf9dd9596522b940e39f88df2fefb37e..c5c4815a1cb18de6e03905e01df9b96dbba3e92c 100644 (file)
@@ -25,7 +25,8 @@ import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
 import com.intellij.psi.PsiElement;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.HelperPackage;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.psi.StructuredDocString;
 import com.jetbrains.python.sdk.PySdkUtil;
 import com.jetbrains.python.sdk.PythonEnvUtil;
@@ -66,17 +67,17 @@ public class PyStructuredDocstringFormatter {
     final String[] lines = PyDocumentationBuilder.removeCommonIndentation(docstring);
     final String preparedDocstring = StringUtil.join(lines, "\n");
 
-    final String formatter;
+    final HelperPackage formatter;
     final StructuredDocStringBase structuredDocString;
     if (documentationSettings.isEpydocFormat(element.getContainingFile()) ||
         DocStringUtil.isEpydocDocString(preparedDocstring)) {
-      formatter = PythonHelpersLocator.getHelperPath("epydoc_formatter.py");
+      formatter = PythonHelper.EPYDOC_FORMATTER;
       structuredDocString = new EpydocString(preparedDocstring);
       result.add(formatStructuredDocString(structuredDocString));
     }
     else if (documentationSettings.isReSTFormat(element.getContainingFile()) ||
              DocStringUtil.isSphinxDocString(preparedDocstring)) {
-      formatter = PythonHelpersLocator.getHelperPath("rest_formatter.py");
+      formatter = PythonHelper.REST_FORMATTER;
       structuredDocString = new SphinxDocString(preparedDocstring);
     }
     else {
@@ -94,7 +95,7 @@ public class PyStructuredDocstringFormatter {
 
   @Nullable
   private static String runExternalTool(@NotNull final Module module,
-                                        @NotNull final String formatter,
+                                        @NotNull final HelperPackage formatter,
                                         @NotNull final String docstring) {
     final Sdk sdk = PythonSdkType.findPython2Sdk(module);
     if (sdk == null) return null;
@@ -111,7 +112,8 @@ public class PyStructuredDocstringFormatter {
     final Map<String, String> env = new HashMap<String, String>();
     PythonEnvUtil.setPythonDontWriteBytecode(env);
 
-    final ProcessOutput output = PySdkUtil.getProcessOutput(new File(sdkHome).getParent(), new String[]{sdkHome, formatter},
+    final ProcessOutput output = PySdkUtil.getProcessOutput(formatter.newCommandLine(sdkHome, Lists.<String>newArrayList()),
+                                                            new File(sdkHome).getParent(),
                                                             env, 5000, data, true);
     if (output.isTimeout()) {
       LOG.info("timeout when calculating docstring");
index 99075ba9a02333550cd6dab5a69e996c7e5d997c..e6647ee288ca46536484785c06466f7ef8d52a56 100644 (file)
@@ -18,6 +18,7 @@ package com.jetbrains.python.inspections.quickfix;
 import com.google.common.collect.Lists;
 import com.intellij.codeInspection.LocalQuickFix;
 import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.process.ProcessOutput;
 import com.intellij.openapi.application.ReadAction;
 import com.intellij.openapi.application.Result;
@@ -38,7 +39,7 @@ import com.intellij.psi.PsiFile;
 import com.intellij.psi.util.QualifiedName;
 import com.intellij.util.Consumer;
 import com.jetbrains.python.PyBundle;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.psi.*;
 import com.jetbrains.python.sdk.InvalidSdkException;
 import com.jetbrains.python.sdk.PySdkUtil;
@@ -78,8 +79,9 @@ public class GenerateBinaryStubsFix implements LocalQuickFix {
     final List<GenerateBinaryStubsFix> result = new ArrayList<GenerateBinaryStubsFix>(names.size());
     if (importStatementBase instanceof PyFromImportStatement && names.isEmpty()) {
       final QualifiedName qName = ((PyFromImportStatement)importStatementBase).getImportSourceQName();
-      if (qName != null)
+      if (qName != null) {
         result.add(new GenerateBinaryStubsFix(importStatementBase, qName.toString()));
+      }
     }
     for (final String qualifiedName : names) {
       result.add(new GenerateBinaryStubsFix(importStatementBase, qualifiedName));
@@ -118,6 +120,7 @@ public class GenerateBinaryStubsFix implements LocalQuickFix {
 
   /**
    * Returns fix task that is used to generate stubs
+   *
    * @param fileToRunTaskIn file where task should run
    * @return task itself
    */
@@ -170,12 +173,10 @@ public class GenerateBinaryStubsFix implements LocalQuickFix {
     indicator.setIndeterminate(false);
     final String homePath = mySdk.getHomePath();
     if (homePath == null) return false;
-    final ProcessOutput runResult = PySdkUtil.getProcessOutput(
-      new File(homePath).getParent(),
-      new String[]{
-        homePath,
-        PythonHelpersLocator.getHelperPath("extra_syspath.py"), myQualifiedName},
-      PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000
+    GeneralCommandLine cmd = PythonHelper.EXTRA_SYSPATH.newCommandLine(homePath, Lists.newArrayList(myQualifiedName));
+    final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd,
+                                                               new File(homePath).getParent(),
+                                                               PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000
     );
     if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
       final String extraPath = runResult.getStdout();
index 2957987d37344425ce6248bf3a82c89cc5081f54..0ed73cdb56af9fdfbfc5962153004df592af594b 100644 (file)
@@ -436,4 +436,10 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
     }
     return result;
   }
+
+  @Override
+  public String getModuleName() {
+    Module module = getModule();
+    return module != null? module.getName() : null;
+  }
 }
index b882e8084e8dd96313d9bb4f22737ab0d74ae40b..79c51cb584f275dc489dc4fed75b9ff7f394043d 100644 (file)
@@ -34,6 +34,7 @@ import com.intellij.facet.Facet;
 import com.intellij.facet.FacetManager;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.module.ModuleUtilCore;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
@@ -43,13 +44,13 @@ import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
 import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.JarFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
 import com.intellij.remote.RemoteProcessHandlerBase;
 import com.intellij.util.PlatformUtils;
 import com.intellij.util.containers.HashMap;
-import com.jetbrains.python.PythonHelpersLocator;
 import com.jetbrains.python.console.PyDebugConsoleBuilder;
 import com.jetbrains.python.debugger.PyDebugRunner;
 import com.jetbrains.python.debugger.PyDebuggerOptionsProvider;
@@ -61,13 +62,13 @@ import com.jetbrains.python.sdk.PySdkUtil;
 import com.jetbrains.python.sdk.PythonEnvUtil;
 import com.jetbrains.python.sdk.PythonSdkAdditionalData;
 import com.jetbrains.python.sdk.PythonSdkType;
-import com.jetbrains.python.sdk.flavors.JythonSdkFlavor;
 import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.IOException;
 import java.net.ServerSocket;
+import java.nio.charset.Charset;
 import java.util.*;
 
 /**
@@ -80,6 +81,7 @@ public abstract class PythonCommandLineState extends CommandLineState {
   public static final String GROUP_EXE_OPTIONS = "Exe Options";
   public static final String GROUP_DEBUGGER = "Debugger";
   public static final String GROUP_PROFILER = "Profiler";
+  public static final String GROUP_COVERAGE = "Coverage";
   public static final String GROUP_SCRIPT = "Script";
   private final AbstractPythonRunConfiguration myConfig;
 
@@ -214,7 +216,7 @@ public abstract class PythonCommandLineState extends CommandLineState {
   }
 
 
-  public GeneralCommandLine generateCommandLine(CommandLinePatcher[] patchers) throws ExecutionException {
+  public GeneralCommandLine generateCommandLine(CommandLinePatcher[] patchers) {
     GeneralCommandLine commandLine = generateCommandLine();
     if (patchers != null) {
       for (CommandLinePatcher patcher : patchers) {
@@ -228,23 +230,31 @@ public abstract class PythonCommandLineState extends CommandLineState {
     return PythonProcessRunner.createProcess(commandLine);
   }
 
-  public GeneralCommandLine generateCommandLine() throws ExecutionException {
-    GeneralCommandLine commandLine = createCommandLine();
+  public GeneralCommandLine generateCommandLine() {
+    GeneralCommandLine commandLine = createPythonCommandLine(myConfig.getProject(), myConfig);
 
-    commandLine.withCharset(EncodingProjectManager.getInstance(myConfig.getProject()).getDefaultCharset());
+    buildCommandLineParameters(commandLine);
+
+    customizeEnvironmentVars(commandLine.getEnvironment(), myConfig.isPassParentEnvs());
 
-    setRunnerPath(commandLine);
+    return commandLine;
+  }
 
-    // define groups
-    createStandardGroupsIn(commandLine);
+  @NotNull
+  public static GeneralCommandLine createPythonCommandLine(Project project, PythonRunParams config) {
+    GeneralCommandLine commandLine = generalCommandLine();
+    initEnvironment(project, commandLine, config);
 
-    buildCommandLineParameters(commandLine);
+    commandLine.withCharset(EncodingProjectManager.getInstance(project).getDefaultCharset());
+
+    setRunnerPath(project, commandLine, config);
+
+    createStandardGroups(commandLine);
 
-    initEnvironment(commandLine);
     return commandLine;
   }
 
-  private static GeneralCommandLine createCommandLine() {
+  public static GeneralCommandLine generalCommandLine() {
     return PtyCommandLine.isEnabled() ? new PtyCommandLine() : new GeneralCommandLine();
   }
 
@@ -255,15 +265,16 @@ public abstract class PythonCommandLineState extends CommandLineState {
    *
    * @param commandLine
    */
-  public static void createStandardGroupsIn(GeneralCommandLine commandLine) {
+  public static void createStandardGroups(GeneralCommandLine commandLine) {
     ParametersList params = commandLine.getParametersList();
     params.addParamsGroup(GROUP_EXE_OPTIONS);
     params.addParamsGroup(GROUP_DEBUGGER);
     params.addParamsGroup(GROUP_PROFILER);
+    params.addParamsGroup(GROUP_COVERAGE);
     params.addParamsGroup(GROUP_SCRIPT);
   }
 
-  protected void initEnvironment(GeneralCommandLine commandLine) {
+  protected static void initEnvironment(Project project, GeneralCommandLine commandLine, PythonRunParams myConfig) {
     Map<String, String> env = myConfig.getEnvs();
     if (env == null) {
       env = new HashMap<String, String>();
@@ -272,14 +283,15 @@ public abstract class PythonCommandLineState extends CommandLineState {
       env = new HashMap<String, String>(env);
     }
 
-    addPredefinedEnvironmentVariables(env, myConfig.isPassParentEnvs());
+    setupEncodingEnvs(env, commandLine.getCharset());
+
     addCommonEnvironmentVariables(env);
 
     commandLine.getEnvironment().clear();
     commandLine.getEnvironment().putAll(env);
     commandLine.setPassParentEnvironment(myConfig.isPassParentEnvs());
 
-    buildPythonPath(commandLine, myConfig.isPassParentEnvs());
+    buildPythonPath(project, commandLine, myConfig);
   }
 
   protected static void addCommonEnvironmentVariables(Map<String, String> env) {
@@ -287,19 +299,19 @@ public abstract class PythonCommandLineState extends CommandLineState {
     env.put("PYCHARM_HOSTED", "1");
   }
 
-  public void addPredefinedEnvironmentVariables(Map<String, String> envs, boolean passParentEnvs) {
-    final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(myConfig.getInterpreterPath());
-    if (flavor != null) {
-      flavor.addPredefinedEnvironmentVariables(envs, myConfig.getProject());
-    }
+  public void customizeEnvironmentVars(Map<String, String> envs, boolean passParentEnvs) {
   }
 
-  private void buildPythonPath(GeneralCommandLine commandLine, boolean passParentEnvs) {
-    Sdk pythonSdk = PythonSdkType.findSdkByPath(myConfig.getInterpreterPath());
+  private static void setupEncodingEnvs(Map<String, String> envs, Charset charset) {
+    PythonSdkFlavor.setupEncodingEnvs(envs, charset);
+  }
+
+  private static void buildPythonPath(Project project, GeneralCommandLine commandLine, PythonRunParams config) {
+    Sdk pythonSdk = PythonSdkType.findSdkByPath(config.getSdkHome());
     if (pythonSdk != null) {
       List<String> pathList = Lists.newArrayList(getAddedPaths(pythonSdk));
-      pathList.addAll(collectPythonPath());
-      initPythonPath(commandLine, passParentEnvs, pathList, myConfig.getInterpreterPath());
+      pathList.addAll(collectPythonPath(project, config));
+      initPythonPath(commandLine, config.isPassParentEnvs(), pathList, config.getSdkHome());
     }
   }
 
@@ -352,16 +364,14 @@ public abstract class PythonCommandLineState extends CommandLineState {
     }
   }
 
-  protected Collection<String> collectPythonPath() {
-    final Module module = myConfig.getModule();
-    Set<String> pythonPath = Sets.newHashSet(collectPythonPath(module, myConfig.shouldAddContentRoots(), myConfig.shouldAddSourceRoots()));
+  protected static Collection<String> collectPythonPath(Project project, PythonRunParams config) {
+    final Module module = getModule(project, config);
 
-    if (isDebug() && getSdkFlavor() instanceof JythonSdkFlavor) { //that fixes Jython problem changing sys.argv on execfile, see PY-8164
-      pythonPath.add(PythonHelpersLocator.getHelperPath("pycharm"));
-      pythonPath.add(PythonHelpersLocator.getHelperPath("pydev"));
-    }
+    return Sets.newHashSet(collectPythonPath(module, config.shouldAddContentRoots(), config.shouldAddSourceRoots()));
+  }
 
-    return pythonPath;
+  private static Module getModule(Project project, PythonRunParams config) {
+    return ModuleManager.getInstance(project).findModuleByName(config.getModuleName());
   }
 
   @NotNull
@@ -456,9 +466,23 @@ public abstract class PythonCommandLineState extends CommandLineState {
     }
   }
 
-  protected void setRunnerPath(GeneralCommandLine commandLine) throws ExecutionException {
-    String interpreterPath = getInterpreterPath();
-    commandLine.setExePath(FileUtil.toSystemDependentName(interpreterPath));
+  protected static void setRunnerPath(Project project, GeneralCommandLine commandLine, PythonRunParams config) {
+    String interpreterPath = getInterpreterPath(project, config);
+    if (StringUtil.isNotEmpty(interpreterPath)) {
+      commandLine.setExePath(FileUtil.toSystemDependentName(interpreterPath));
+    }
+  }
+
+  @Nullable
+  public static String getInterpreterPath(Project project, PythonRunParams config) {
+    String sdkHome = config.getSdkHome();
+    if (config.isUseModuleSdk() || StringUtil.isEmpty(sdkHome)) {
+      Sdk sdk = PythonSdkType.findPythonSdk(getModule(project, config));
+      if (sdk == null) return null;
+      sdkHome = sdk.getHomePath();
+    }
+
+    return sdkHome;
   }
 
   protected String getInterpreterPath() throws ExecutionException {
index ecc47133732f7c52e9d2797840a3e45bc4435bda..2227cf34ec71974de82121a0498ddff7bba35171 100644 (file)
@@ -24,21 +24,19 @@ import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.configurations.ParametersList;
 import com.intellij.execution.configurations.ParamsGroup;
 import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.process.CommandLineArgumentsProvider;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.ArrayUtil;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.console.PyConsoleType;
 import com.jetbrains.python.console.PydevConsoleRunner;
+import com.jetbrains.python.sdk.PythonEnvUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -127,46 +125,22 @@ public class PythonScriptCommandLineState extends PythonCommandLineState {
     }
 
     @Override
-    protected CommandLineArgumentsProvider createCommandLineArgumentsProvider(final Sdk sdk,
-                                                                              final Map<String, String> environmentVariables,
-                                                                              int[] ports) {
-      final ArrayList<String> args = new ArrayList<String>();
-      args.add(sdk.getHomePath());
-      final String versionString = sdk.getVersionString();
-      if (versionString == null || !versionString.toLowerCase().contains("jython")) {
-        args.add("-u");
-      }
-      args.add(FileUtil.toSystemDependentName(PythonHelpersLocator.getHelperPath("pydev/pydev_run_in_console.py")));
-      for (int port : ports) {
-        args.add(String.valueOf(port));
-      }
+    protected GeneralCommandLine createCommandLine(@NotNull Sdk sdk,
+                                                   @NotNull Map<String, String> environmentVariables,
+                                                   int[] ports) {
+      GeneralCommandLine consoleCmdLine = doCreateConsoleCmdLine(ports, PythonHelper.RUN_IN_CONSOLE);
 
-      try {
-        final GeneralCommandLine cmd = generateCommandLine(myPatchers);
-        args.addAll(cmd.getParametersList().getList());
+      final GeneralCommandLine cmd = generateCommandLine(myPatchers);
 
-        return new CommandLineArgumentsProvider() {
-          @Override
-          public String[] getArguments() {
-            return ArrayUtil.toStringArray(args);
-          }
+      ParamsGroup group = consoleCmdLine.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
+      assert group != null;
+      group.addParameters(cmd.getParametersList().getList());
 
-          @Override
-          public boolean passParentEnvs() {
-            return false;
-          }
+      PythonEnvUtil.mergePythonPath(consoleCmdLine.getEnvironment(), cmd.getEnvironment());
 
-          @Override
-          public Map<String, String> getAdditionalEnvs() {
-            Map<String, String> map = addDefaultEnvironments(sdk, environmentVariables,getProject());
-            map.putAll(cmd.getEnvironment());
-            return map;
-          }
-        };
-      }
-      catch (Exception e) {
-        throw new IllegalStateException(e);
-      }
+      consoleCmdLine.getEnvironment().putAll(cmd.getEnvironment());
+
+      return consoleCmdLine;
     }
   }
 }
index 5b1d91963375e77e4ae4246a9a82b04dabd4917b..1d9ac37412343038b288a699f8f129a8f9e5fabf 100644 (file)
@@ -33,6 +33,7 @@ import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.NotNullFunction;
+import com.jetbrains.python.HelperPackage;
 import com.jetbrains.python.PyBundle;
 import com.jetbrains.python.buildout.BuildoutFacet;
 import com.jetbrains.python.console.PydevConsoleRunner;
@@ -60,6 +61,8 @@ public class PythonTask {
   private final Sdk mySdk;
   private String myWorkingDirectory;
   private String myRunnerScript;
+  private HelperPackage myHelper = null;
+
   private List<String> myParameters = new ArrayList<String>();
   private final String myRunTabTitle;
   private String myHelpId;
@@ -90,6 +93,10 @@ public class PythonTask {
     myRunnerScript = script;
   }
 
+  public void setHelper(HelperPackage helper) {
+    myHelper = helper;
+  }
+
   public void setParameters(List<String> parameters) {
     myParameters = parameters;
   }
@@ -148,7 +155,7 @@ public class PythonTask {
       homePath = FileUtil.toSystemDependentName(homePath);
     }
 
-    PythonCommandLineState.createStandardGroupsIn(cmd);
+    PythonCommandLineState.createStandardGroups(cmd);
     ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
     assert scriptParams != null;
 
@@ -160,8 +167,14 @@ public class PythonTask {
       bashParams.addParameter("-cl");
 
       NotNullFunction<String, String> escaperFunction = StringUtil.escaper(false, "|>$\"'& ");
-      StringBuilder paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript));
-
+      StringBuilder paramString;
+      if (myHelper != null) {
+        paramString= new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myHelper.asParamString()));
+        myHelper.addToPythonPath(cmd.getEnvironment());
+      }
+      else {
+        paramString= new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript));
+      }
       for (String p : myParameters) {
         paramString.append(" ").append(p);
       }
@@ -169,7 +182,12 @@ public class PythonTask {
     }
     else {
       cmd.setExePath(homePath);
-      scriptParams.addParameter(myRunnerScript);
+      if (myHelper != null) {
+        myHelper.addToGroup(scriptParams, cmd);
+      }
+      else {
+        scriptParams.addParameter(myRunnerScript);
+      }
       scriptParams.addParameters(myParameters);
     }
 
index 24c2409c60a6f8917b5d4a961a4518cd04ec7840..386966488643601eaeb6e4a935a38a7cd3e849ec 100644 (file)
@@ -106,13 +106,27 @@ public class PySdkUtil {
                                                final int timeout,
                                                @Nullable byte[] stdin,
                                                boolean needEOFMarker) {
+    return getProcessOutput(new GeneralCommandLine(command), homePath, extraEnv, timeout, stdin, needEOFMarker);
+  }
+
+  public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath,
+                                               @Nullable @NonNls Map<String, String> extraEnv,
+                                               int timeout) {
+    return getProcessOutput(cmd, homePath, extraEnv, timeout, null, true);
+  }
+
+  public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath,
+                                               @Nullable @NonNls Map<String, String> extraEnv,
+                                               int timeout,
+                                               @Nullable byte[] stdin, boolean needEOFMarker) {
     if (homePath == null || !new File(homePath).exists()) {
       return new ProcessOutput();
     }
     final Map<String, String> systemEnv = System.getenv();
     final Map<String, String> env = extraEnv != null ? mergeEnvVariables(systemEnv, extraEnv) : systemEnv;
     try {
-      final Process process = new GeneralCommandLine(command).withWorkDirectory(homePath).withEnvironment(env).createProcess();
+
+      final Process process = cmd.withWorkDirectory(homePath).withEnvironment(env).createProcess();
       final CapturingProcessHandler processHandler = new CapturingProcessHandler(process);
       if (stdin != null) {
         final OutputStream processInput = processHandler.getProcessInput();
@@ -159,6 +173,7 @@ public class PySdkUtil {
                                                        @NotNull Map<String, String> extraEnvironment) {
     final Map<String, String> result = new HashMap<String, String>(environment);
     for (Map.Entry<String, String> entry : extraEnvironment.entrySet()) {
+      //TODO: merge python path also?
       if (PATH_ENV_VARIABLE.equals(entry.getKey()) && result.containsKey(PATH_ENV_VARIABLE)) {
         result.put(PATH_ENV_VARIABLE, result.get(PATH_ENV_VARIABLE) + File.pathSeparator + entry.getValue());
       }
index 7b4184fd00a0e26ed5e7ea522c4f39b89dab227a..75319d7acc971c1f4fcd97df1b22bb4d18661b44 100644 (file)
@@ -86,6 +86,14 @@ public class PythonEnvUtil {
     addPathToEnv(env, PYTHONPATH, value);
   }
 
+  public static void mergePythonPath(@NotNull Map<String, String> from, @NotNull Map<String, String> to) {
+    String value = from.get(PYTHONPATH);
+    if (value != null) {
+      Set<String> paths = Sets.newHashSet(value.split(File.pathSeparator));
+      addToPythonPath(to, paths);
+    }
+  }
+
   @NotNull
   public static Map<String, String> setPythonDontWriteBytecode(@NotNull Map<String, String> env) {
     env.put(PYTHONDONTWRITEBYTECODE, "1");
index 77a9f0e2ae25c40579b9a6837b35e22b69159284..364050a8b3665ffbb40a4107925bcdcb83d08589 100644 (file)
@@ -16,6 +16,7 @@
 package com.jetbrains.python.sdk;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import com.intellij.execution.ExecutionException;
 import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.process.ProcessOutput;
@@ -65,7 +66,7 @@ import com.intellij.util.ui.UIUtil;
 import com.jetbrains.python.PyBundle;
 import com.jetbrains.python.PyNames;
 import com.jetbrains.python.PythonFileType;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil;
 import com.jetbrains.python.facet.PythonFacetSettings;
 import com.jetbrains.python.psi.LanguageLevel;
@@ -782,17 +783,17 @@ public class PythonSdkType extends SdkType {
 
   @NotNull
   public static List<String> getSysPathsFromScript(@NotNull String binaryPath) throws InvalidSdkException {
-    String scriptFile = PythonHelpersLocator.getHelperPath("syspath.py");
     // to handle the situation when PYTHONPATH contains ., we need to run the syspath script in the
     // directory of the script itself - otherwise the dir in which we run the script (e.g. /usr/bin) will be added to SDK path
-    final ProcessOutput run_result = PySdkUtil.getProcessOutput(new File(scriptFile).getParent(), new String[]{binaryPath, scriptFile},
+    GeneralCommandLine cmd = PythonHelper.SYSPATH.newCommandLine(binaryPath, Lists.<String>newArrayList());
+    final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(binaryPath).getParent(),
                                                                 getVirtualEnvExtraEnv(binaryPath), MINUTE);
-    if (!run_result.checkSuccess(LOG)) {
+    if (!runResult.checkSuccess(LOG)) {
       throw new InvalidSdkException(String.format("Failed to determine Python's sys.path value:\nSTDOUT: %s\nSTDERR: %s",
-                                                  run_result.getStdout(),
-                                                  run_result.getStderr()));
+                                                  runResult.getStdout(),
+                                                  runResult.getStderr()));
     }
-    return run_result.getStdoutLines();
+    return runResult.getStdoutLines();
   }
 
   /**
index 3ecaf40ad0f6d78e96c03050830b87d85e77b9e2..c68e6bdff8b4caae9fe054795800c61d29ae07f1 100644 (file)
@@ -208,10 +208,8 @@ public abstract class PythonSdkFlavor {
     PythonEnvUtil.addPathToEnv(envs, key, value);
   }
 
-  @SuppressWarnings({"MethodMayBeStatic"})
-  public void addPredefinedEnvironmentVariables(Map<String, String> envs, @NotNull Project project) {
-    Charset defaultCharset = EncodingProjectManager.getInstance(project).getDefaultCharset();
-    final String encoding = defaultCharset.name();
+  public static void setupEncodingEnvs(Map<String, String> envs, @NotNull Charset charset) {
+    final String encoding = charset.name();
     PythonEnvUtil.setPythonIOEncoding(envs, encoding);
   }
 
index 0a178153821b69f9bbf8920239ad1bb495bdab2f..766f50f1d6517d856cac6e46b88bda132caa313f 100644 (file)
@@ -30,6 +30,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.ComponentContainer;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.search.GlobalSearchScope;
+import com.jetbrains.python.HelperPackage;
 import com.jetbrains.python.run.AbstractPythonRunConfiguration;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -99,7 +100,7 @@ public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction {
     }
 
     @Override
-    protected String getRunner() {
+    protected HelperPackage getRunner() {
       return myState.getRunner();
     }
 
@@ -122,19 +123,19 @@ public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction {
     }
 
     @Override
-    protected void addAfterParameters(GeneralCommandLine cmd) throws ExecutionException {
+    protected void addAfterParameters(GeneralCommandLine cmd) {
       myState.addAfterParameters(cmd);
     }
 
     @Override
-    protected void addBeforeParameters(GeneralCommandLine cmd) throws ExecutionException {
+    protected void addBeforeParameters(GeneralCommandLine cmd) {
       myState.addBeforeParameters(cmd);
     }
 
     @Override
-    public void addPredefinedEnvironmentVariables(Map<String, String> envs, boolean passParentEnvs) {
-      myState.addPredefinedEnvironmentVariables(envs,
-                                                passParentEnvs);
+    public void customizeEnvironmentVars(Map<String, String> envs, boolean passParentEnvs) {
+      myState.customizeEnvironmentVars(envs,
+                                       passParentEnvs);
     }
   }
 }
index efd51aaf130bb4da7def729982268c24eb7d4a64..0661d1be819cb26681230fdd1b16d66b62e4d0c6 100644 (file)
@@ -36,6 +36,7 @@ import com.intellij.openapi.util.Getter;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.python.HelperPackage;
 import com.jetbrains.python.PythonHelpersLocator;
 import com.jetbrains.python.console.PythonDebugLanguageConsoleView;
 import com.jetbrains.python.run.AbstractPythonRunConfiguration;
@@ -44,7 +45,6 @@ import com.jetbrains.python.run.PythonCommandLineState;
 import com.jetbrains.python.sdk.PythonSdkType;
 import org.jetbrains.annotations.NotNull;
 
-import java.io.File;
 import java.util.List;
 import java.util.Map;
 
@@ -92,7 +92,7 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt
   }
 
   @Override
-  public GeneralCommandLine generateCommandLine() throws ExecutionException {
+  public GeneralCommandLine generateCommandLine()  {
     GeneralCommandLine cmd = super.generateCommandLine();
 
     setWorkingDirectory(cmd);
@@ -154,24 +154,24 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt
     return executionResult;
   }
 
-  protected void addBeforeParameters(GeneralCommandLine cmd) throws ExecutionException {}
-  protected void addAfterParameters(GeneralCommandLine cmd) throws ExecutionException {}
+  protected void addBeforeParameters(GeneralCommandLine cmd)  {}
+  protected void addAfterParameters(GeneralCommandLine cmd) {}
 
-  protected void addTestRunnerParameters(GeneralCommandLine cmd) throws ExecutionException {
-    ParamsGroup script_params = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT);
-    assert script_params != null;
-    script_params.addParameter(new File(PythonHelpersLocator.getHelpersRoot(), getRunner()).getAbsolutePath());
+  protected void addTestRunnerParameters(GeneralCommandLine cmd)  {
+    ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT);
+    assert scriptParams != null;
+    getRunner().addToGroup(scriptParams, cmd);
     addBeforeParameters(cmd);
-    script_params.addParameters(getTestSpecs());
+    scriptParams.addParameters(getTestSpecs());
     addAfterParameters(cmd);
   }
 
   @Override
-  public void addPredefinedEnvironmentVariables(Map<String, String> envs, boolean passParentEnvs) {
-    super.addPredefinedEnvironmentVariables(envs, passParentEnvs);
+  public void customizeEnvironmentVars(Map<String, String> envs, boolean passParentEnvs) {
+    super.customizeEnvironmentVars(envs, passParentEnvs);
     envs.put("PYCHARM_HELPERS_DIR", PythonHelpersLocator.getHelperPath("pycharm"));
   }
 
-  protected abstract String getRunner();
+  protected abstract HelperPackage getRunner();
   protected abstract List<String> getTestSpecs();
 }
index a6def647ab233e4f5418c14139260046cc486433..cfe65d3067a19881beb5b28fcca050b1a0a8f78f 100644 (file)
@@ -17,6 +17,7 @@ package com.jetbrains.python.testing.attest;
 
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.util.io.FileUtil;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
 
 import java.util.ArrayList;
@@ -27,7 +28,7 @@ import java.util.List;
  */
 public class PythonAtTestCommandLineState extends PythonTestCommandLineStateBase {
   private final PythonAtTestRunConfiguration myConfig;
-  private static final String UTRUNNER_PY = "pycharm/attestrunner.py";
+
 
   public PythonAtTestCommandLineState(PythonAtTestRunConfiguration runConfiguration, ExecutionEnvironment env) {
     super(runConfiguration, env);
@@ -35,8 +36,8 @@ public class PythonAtTestCommandLineState extends PythonTestCommandLineStateBase
   }
 
   @Override
-  protected String getRunner() {
-    return UTRUNNER_PY;
+  protected PythonHelper getRunner() {
+    return PythonHelper.ATTEST;
   }
 
   protected List<String> getTestSpecs() {
index cfd1ea4b358c9da7fe57fe01fd3a322a48de63bc..a47242aad107f7f955a09b39583f1ad99da65860 100644 (file)
@@ -16,6 +16,7 @@
 package com.jetbrains.python.testing.doctest;
 
 import com.intellij.execution.runners.ExecutionEnvironment;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
 
 import java.util.ArrayList;
@@ -26,7 +27,7 @@ import java.util.List;
  */
 public class PythonDocTestCommandLineState extends PythonTestCommandLineStateBase {
   private final PythonDocTestRunConfiguration myConfig;
-  private static final String UTRUNNER_PY = "pycharm/docrunner.py";
+
 
   public PythonDocTestCommandLineState(PythonDocTestRunConfiguration runConfiguration, ExecutionEnvironment env) {
     super(runConfiguration, env);
@@ -34,8 +35,8 @@ public class PythonDocTestCommandLineState extends PythonTestCommandLineStateBas
   }
 
   @Override
-  protected String getRunner() {
-    return UTRUNNER_PY;
+  protected PythonHelper getRunner() {
+    return PythonHelper.DOCSTRING;
   }
 
   protected List<String> getTestSpecs() {
index cd00594f1b9bf89b9a1ea12ab5b8b5b3077b13c8..4d9393b8cedd7d94370d8b6868e7226d0b2d3a74 100644 (file)
  */
 package com.jetbrains.python.testing.nosetest;
 
-import com.intellij.execution.ExecutionException;
 import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.configurations.ParamsGroup;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
 
 import java.util.ArrayList;
@@ -31,7 +31,6 @@ import java.util.List;
  */
 public class PythonNoseTestCommandLineState extends PythonTestCommandLineStateBase {
   private final PythonNoseTestRunConfiguration myConfig;
-  private static final String NOSERUNNER_PY = "pycharm/noserunner.py";
 
   public PythonNoseTestCommandLineState(PythonNoseTestRunConfiguration runConfiguration, ExecutionEnvironment env) {
     super(runConfiguration, env);
@@ -39,8 +38,8 @@ public class PythonNoseTestCommandLineState extends PythonTestCommandLineStateBa
   }
 
   @Override
-  protected String getRunner() {
-    return NOSERUNNER_PY;
+  protected PythonHelper getRunner() {
+    return PythonHelper.NOSE;
   }
 
   protected List<String> getTestSpecs() {
@@ -70,7 +69,7 @@ public class PythonNoseTestCommandLineState extends PythonTestCommandLineStateBa
   }
 
   @Override
-  protected void addAfterParameters(GeneralCommandLine cmd) throws ExecutionException {
+  protected void addAfterParameters(GeneralCommandLine cmd)  {
     ParamsGroup script_params = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT);
     assert script_params != null;
     if (myConfig.useParam() && !StringUtil.isEmptyOrSpaces(myConfig.getParams()))
index 7e3c4d51f270c879500138a72d8b312124b3cf92..dd202187e83c52aeefa2d01bb2489b183af7daa7 100644 (file)
@@ -24,6 +24,8 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.ui.ConsoleView;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.text.StringUtil;
+import com.jetbrains.python.HelperPackage;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
 import org.jetbrains.annotations.NotNull;
 
@@ -35,7 +37,6 @@ import java.util.List;
  */
 public class PyTestCommandLineState extends PythonTestCommandLineStateBase {
   private final PyTestRunConfiguration myConfiguration;
-  private static final String PYTESTRUNNER_PY = "pycharm/pytestrunner.py";
 
   public PyTestCommandLineState(PyTestRunConfiguration configuration, ExecutionEnvironment env) {
     super(configuration, env);
@@ -43,15 +44,15 @@ public class PyTestCommandLineState extends PythonTestCommandLineStateBase {
   }
 
   @Override
-  protected void addBeforeParameters(GeneralCommandLine cmd) throws ExecutionException {
+  protected void addBeforeParameters(GeneralCommandLine cmd) {
     ParamsGroup script_params = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT);
     assert script_params != null;
     script_params.addParameters("-p", "pytest_teamcity");
   }
 
   @Override
-  protected String getRunner() {
-    return PYTESTRUNNER_PY;
+  protected HelperPackage getRunner() {
+    return PythonHelper.PYTEST;
   }
 
   @Override
@@ -62,7 +63,7 @@ public class PyTestCommandLineState extends PythonTestCommandLineStateBase {
   }
 
   @Override
-  protected void addAfterParameters(GeneralCommandLine cmd) throws ExecutionException {
+  protected void addAfterParameters(GeneralCommandLine cmd)  {
     ParamsGroup script_params = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT);
     assert script_params != null;
     String params = myConfiguration.getParams();
index 90b0f5b4cdbe1fdc6a95bed492ff3885dd018207..8ecc4d60a7d029189ef3d9e693ca516a4fcf53e3 100644 (file)
  */
 package com.jetbrains.python.testing.unittest;
 
-import com.intellij.execution.ExecutionException;
 import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.configurations.ParamsGroup;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.jetbrains.python.PyNames;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.testing.AbstractPythonTestRunConfiguration;
 import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
 
@@ -34,8 +34,7 @@ import java.util.List;
 public class PythonUnitTestCommandLineState extends
                                             PythonTestCommandLineStateBase {
   private final PythonUnitTestRunConfiguration myConfig;
-  private static final String UTRUNNER_PY = "pycharm/utrunner.py";
-  private static final String SETUP_PY_TESTRUNNER = "pycharm/pycharm_setup_runner.py";
+
 
   public PythonUnitTestCommandLineState(PythonUnitTestRunConfiguration runConfiguration, ExecutionEnvironment env) {
     super(runConfiguration, env);
@@ -43,11 +42,11 @@ public class PythonUnitTestCommandLineState extends
   }
 
   @Override
-  protected String getRunner() {
+  protected PythonHelper getRunner() {
     if (myConfig.getTestType() == AbstractPythonTestRunConfiguration.TestType.TEST_SCRIPT &&
       myConfig.getScriptName().endsWith(PyNames.SETUP_DOT_PY))
-      return SETUP_PY_TESTRUNNER;
-    return UTRUNNER_PY;
+      return PythonHelper.SETUPPY;
+    return PythonHelper.UT;
   }
 
   protected List<String> getTestSpecs() {
@@ -84,7 +83,7 @@ public class PythonUnitTestCommandLineState extends
   }
 
   @Override
-  protected void addAfterParameters(GeneralCommandLine cmd) throws ExecutionException {
+  protected void addAfterParameters(GeneralCommandLine cmd) {
     ParamsGroup script_params = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT);
     assert script_params != null;
     if (myConfig.useParam() && !StringUtil.isEmptyOrSpaces(myConfig.getParams()))
index 38c8e5d2ff966008f9b0bd7114c4996bc62a00e7..646b7b8fab3e54c558f06171ac319eee9922be41 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.intention.IntentionAction;
 import com.intellij.codeInspection.InspectionProfile;
 import com.intellij.codeInspection.ModifiableModel;
 import com.intellij.codeInspection.ex.CustomEditInspectionToolsSettingsAction;
+import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.process.ProcessOutput;
 import com.intellij.lang.annotation.Annotation;
 import com.intellij.lang.annotation.AnnotationHolder;
@@ -49,11 +50,10 @@ import com.intellij.psi.PsiWhiteSpace;
 import com.intellij.psi.codeStyle.CodeStyleSettings;
 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
 import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
-import com.intellij.util.ArrayUtil;
 import com.intellij.util.Consumer;
 import com.intellij.util.IncorrectOperationException;
 import com.jetbrains.python.PythonFileType;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.PythonLanguage;
 import com.jetbrains.python.codeInsight.imports.OptimizeImportsQuickFix;
 import com.jetbrains.python.formatter.PyCodeStyleSettings;
@@ -184,16 +184,17 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
   @Override
   public Results doAnnotate(State collectedInfo) {
     if (collectedInfo == null) return null;
-    final String pep8Path = PythonHelpersLocator.getHelperPath("pep8.py");
-    ArrayList<String> options = new ArrayList<String>();
-    Collections.addAll(options, collectedInfo.interpreterPath, pep8Path);
+    ArrayList<String> options = Lists.newArrayList();
+
     if (collectedInfo.ignoredErrors.size() > 0) {
       options.add("--ignore=" + StringUtil.join(collectedInfo.ignoredErrors, ","));
     }
     options.add("--max-line-length=" + collectedInfo.margin);
     options.add("-");
-    ProcessOutput output = PySdkUtil.getProcessOutput(new File(collectedInfo.interpreterPath).getParent(),
-                                                      ArrayUtil.toStringArray(options),
+
+    GeneralCommandLine cmd = PythonHelper.PEP8.newCommandLine(collectedInfo.interpreterPath, options);
+
+    ProcessOutput output = PySdkUtil.getProcessOutput(cmd, new File(collectedInfo.interpreterPath).getParent(),
                                                       ImmutableMap.of("PYTHONBUFFERED", "1"),
                                                       10000,
                                                       collectedInfo.fileText.getBytes(), false);
index 65815c112b2ecdfbf45b3ddcfdf106b25e23a798..463c5c2c43d11fe1f10d74b5eeff73e34eef3de5 100644 (file)
@@ -24,7 +24,7 @@ import com.intellij.execution.executors.DefaultDebugExecutor;
 import com.intellij.execution.executors.DefaultRunExecutor;
 import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.openapi.project.Project;
-import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.PythonHelper;
 import com.jetbrains.python.debugger.PyDebugRunner;
 import com.jetbrains.python.run.AbstractPythonRunConfiguration;
 import com.jetbrains.python.run.PythonCommandLineState;
@@ -41,7 +41,7 @@ public abstract class PyCommandLineTestCase extends PyTestCase {
   protected static int verifyPyDevDParameters(List<String> params) {
     params = Lists.newArrayList(params);
     int debugParam = params.remove("--DEBUG") ? 1 : 0;
-    assertEquals(PythonHelpersLocator.getHelperPath("pydev/pydevd.py"), params.get(0));
+    assertEquals(PythonHelper.DEBUGGER.asParamString(), params.get(0));
     assertEquals("--multiproc", params.get(1));
     assertEquals("--client", params.get(2));
     assertEquals("--port", params.get(4));