diff --git a/python/src/com/jetbrains/python/PythonHelper.java b/python/src/com/jetbrains/python/PythonHelper.java index 9416156e25c5..9f27590b3675 100644 --- a/python/src/com/jetbrains/python/PythonHelper.java +++ b/python/src/com/jetbrains/python/PythonHelper.java @@ -27,6 +27,8 @@ import java.util.Map; public interface PythonHelper { void addToPythonPath(@NotNull Map environment); + String getPythonPath(); + void addToGroup(@NotNull ParamsGroup group, @NotNull GeneralCommandLine cmd); String asParamString(); diff --git a/python/src/com/jetbrains/python/PythonHelpersLocator.java b/python/src/com/jetbrains/python/PythonHelpersLocator.java index a8b5021f110b..402f4d2ac503 100644 --- a/python/src/com/jetbrains/python/PythonHelpersLocator.java +++ b/python/src/com/jetbrains/python/PythonHelpersLocator.java @@ -29,10 +29,25 @@ import java.io.File; import java.util.Map; public enum PythonHelpersLocator implements PythonHelper { - COVERAGEPY("", "coveragepy"), COVERAGE("run_coverage", "coverage"), - DEBUGGER("pydevd", "pydev"), - CONSOLE("pydevconsole", "pydev"), - RUN_IN_CONSOLE("pydev_run_in_console", "pydev"); + COVERAGEPY("coveragepy", ""), COVERAGE("coverage", "run_coverage"), + DEBUGGER("pydev", "pydevd"), + CONSOLE("pydev", "pydevconsole"), + RUN_IN_CONSOLE("pydev", "pydev_run_in_console"), + + 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"), + + + ; @NotNull private PathPythonHelper findModule(String moduleEntryPoint, String path) { @@ -44,7 +59,7 @@ public enum PythonHelpersLocator implements PythonHelper { return new ModulePythonHelper(moduleEntryPoint, path); } - return new ScriptPythonHelper(path + ".py"); + return new ScriptPythonHelper(moduleEntryPoint, path); } private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.PythonHelpersLocator"); @@ -52,10 +67,14 @@ public enum PythonHelpersLocator implements PythonHelper { private PathPythonHelper myModule; - PythonHelpersLocator(String moduleName, String pythonPath) { + PythonHelpersLocator(String pythonPath, String moduleName) { myModule = findModule(moduleName, pythonPath); } + public String getPythonPath() { + return myModule.getPythonPath(); + } + /** * @return the base directory under which various scripts, etc are stored. @@ -145,6 +164,11 @@ public enum PythonHelpersLocator implements PythonHelper { public String asParamString() { return "-m" + myModuleName; } + + @Override + public String getPythonPath() { + return FileUtil.toSystemDependentName(myPath.getAbsolutePath()); + } } /** @@ -153,15 +177,25 @@ public enum PythonHelpersLocator implements PythonHelper { * with .pyc files */ public static class ScriptPythonHelper extends PathPythonHelper { - public ScriptPythonHelper(String relativePath) { - super(relativePath); + private String myPythonPath; + + public ScriptPythonHelper(String module, String pythonPath) { + super(new File(pythonPath, module.replace(".", File.separator)).getPath()); + myPythonPath = pythonPath; } @Override public void addToPythonPath(@NotNull Map environment) { PythonEnvUtil.setPythonDontWriteBytecode(environment); - PythonEnvUtil.addToPythonPath(environment, myPath.getParent()); + PythonEnvUtil.addToPythonPath(environment, myPythonPath); } + + @Override + public String getPythonPath() { + return myPythonPath; + } + + } diff --git a/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java b/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java index 1ee7b479b32a..711995013f95 100644 --- a/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java +++ b/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java @@ -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.PythonHelpersLocator; 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 PythonHelpersLocator getRunner() { return myState.getRunner(); } diff --git a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java index d4ccd790f7c0..f9806b4123d0 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java +++ b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java @@ -158,11 +158,11 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt protected void addAfterParameters(GeneralCommandLine cmd) {} protected void addTestRunnerParameters(GeneralCommandLine cmd) { - ParamsGroup script_params = cmd.getParametersList().getParamsGroup(GROUP_SCRIPT); - assert script_params != null; - script_params.addParameter(new File(PythonHelpersLocator.getHelpersRoot(), getRunner()).getAbsolutePath()); + 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); } @@ -172,6 +172,6 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt envs.put("PYCHARM_HELPERS_DIR", PythonHelpersLocator.getHelperPath("pycharm")); } - protected abstract String getRunner(); + protected abstract PythonHelpersLocator getRunner(); protected abstract List getTestSpecs(); } diff --git a/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java b/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java index a6def647ab23..4ee2cc22a2b7 100644 --- a/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java @@ -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.PythonHelpersLocator; 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 PythonHelpersLocator getRunner() { + return PythonHelpersLocator.ATTEST; } protected List getTestSpecs() { diff --git a/python/src/com/jetbrains/python/testing/doctest/PythonDocTestCommandLineState.java b/python/src/com/jetbrains/python/testing/doctest/PythonDocTestCommandLineState.java index cfd1ea4b358c..bfe5658a5f95 100644 --- a/python/src/com/jetbrains/python/testing/doctest/PythonDocTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/doctest/PythonDocTestCommandLineState.java @@ -16,6 +16,7 @@ package com.jetbrains.python.testing.doctest; import com.intellij.execution.runners.ExecutionEnvironment; +import com.jetbrains.python.PythonHelpersLocator; 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 PythonHelpersLocator getRunner() { + return PythonHelpersLocator.DOCSTRING; } protected List getTestSpecs() { diff --git a/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java b/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java index dfdd8c4d9285..337291d88ff1 100644 --- a/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java @@ -15,12 +15,12 @@ */ 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.PythonHelpersLocator; 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 PythonHelpersLocator getRunner() { + return PythonHelpersLocator.NOSE; } protected List getTestSpecs() { diff --git a/python/src/com/jetbrains/python/testing/pytest/PyTestCommandLineState.java b/python/src/com/jetbrains/python/testing/pytest/PyTestCommandLineState.java index 8995b07029fb..b22e607ba900 100644 --- a/python/src/com/jetbrains/python/testing/pytest/PyTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/pytest/PyTestCommandLineState.java @@ -24,6 +24,7 @@ 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.PythonHelpersLocator; import com.jetbrains.python.testing.PythonTestCommandLineStateBase; import org.jetbrains.annotations.NotNull; @@ -35,7 +36,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); @@ -50,8 +50,8 @@ public class PyTestCommandLineState extends PythonTestCommandLineStateBase { } @Override - protected String getRunner() { - return PYTESTRUNNER_PY; + protected PythonHelpersLocator getRunner() { + return PythonHelpersLocator.PYTEST; } @Override diff --git a/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java b/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java index 761a48686df0..899eea28c997 100644 --- a/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java @@ -22,6 +22,7 @@ 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.PythonHelpersLocator; import com.jetbrains.python.testing.AbstractPythonTestRunConfiguration; import com.jetbrains.python.testing.PythonTestCommandLineStateBase; @@ -34,8 +35,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 +43,11 @@ public class PythonUnitTestCommandLineState extends } @Override - protected String getRunner() { + protected PythonHelpersLocator getRunner() { if (myConfig.getTestType() == AbstractPythonTestRunConfiguration.TestType.TEST_SCRIPT && myConfig.getScriptName().endsWith(PyNames.SETUP_DOT_PY)) - return SETUP_PY_TESTRUNNER; - return UTRUNNER_PY; + return PythonHelpersLocator.SETUPPY; + return PythonHelpersLocator.UT; } protected List getTestSpecs() {