diff --git a/python/src/com/jetbrains/python/run/PythonCommandLineState.java b/python/src/com/jetbrains/python/run/PythonCommandLineState.java index 73d60fefdd2e..05379621d8e4 100644 --- a/python/src/com/jetbrains/python/run/PythonCommandLineState.java +++ b/python/src/com/jetbrains/python/run/PythonCommandLineState.java @@ -102,6 +102,7 @@ public abstract class PythonCommandLineState extends CommandLineState { */ public static final String GROUP_MODULE = "Module"; public static final String GROUP_SCRIPT = "Script"; + public static final String MODULE_PARAMETER = "-m"; private final AbstractPythonRunConfiguration myConfig; private Boolean myMultiprocessDebug = null; @@ -269,9 +270,26 @@ public abstract class PythonCommandLineState extends CommandLineState { return new PyRemoteProcessStarter(); } + /** + * Generate command line and apply patchers + * + * @param patchers array of patchers + * @return generated command line changed by patchers + */ + @NotNull + public final GeneralCommandLine generateCommandLine(@Nullable CommandLinePatcher[] patchers) { + return applyPatchers(generateCommandLine(), patchers); + } - public GeneralCommandLine generateCommandLine(CommandLinePatcher[] patchers) { - GeneralCommandLine commandLine = generateCommandLine(); + /** + * Apply patchers to the given command line + * + * @param commandLine command line to change + * @param patchers array of patchers + * @return command line changed by patchers + */ + @NotNull + private static GeneralCommandLine applyPatchers(@NotNull GeneralCommandLine commandLine, @Nullable CommandLinePatcher[] patchers) { if (patchers != null) { for (CommandLinePatcher patcher : patchers) { if (patcher != null) patcher.patchCommandLine(commandLine); @@ -284,6 +302,14 @@ public abstract class PythonCommandLineState extends CommandLineState { return PythonProcessRunner.createProcess(commandLine); } + /** + * Generate command line from run configuration. + * It can be overridden if commandline shouldn't be based on the run configuration or when it requires some additional changes + * before patchers applying. + * + * @return generated command line + */ + @NotNull public GeneralCommandLine generateCommandLine() { GeneralCommandLine commandLine = createPythonCommandLine(myConfig.getProject(), myConfig, isDebug(), myRunWithPty); diff --git a/python/src/com/jetbrains/python/run/PythonScriptCommandLineState.java b/python/src/com/jetbrains/python/run/PythonScriptCommandLineState.java index 39ea59f68eda..8025e4285db1 100644 --- a/python/src/com/jetbrains/python/run/PythonScriptCommandLineState.java +++ b/python/src/com/jetbrains/python/run/PythonScriptCommandLineState.java @@ -230,7 +230,7 @@ public class PythonScriptCommandLineState extends PythonCommandLineState { ParamsGroup moduleParameters = parametersList.getParamsGroup(GROUP_MODULE); assert moduleParameters != null; - moduleParameters.addParameter("-m"); + moduleParameters.addParameter(MODULE_PARAMETER); moduleParameters.addParameters(myConfig.getScriptName()); } else { diff --git a/python/src/com/jetbrains/python/testing/PyTestsShared.kt b/python/src/com/jetbrains/python/testing/PyTestsShared.kt index 87cd78b6dbb1..e4e5b9ed9841 100644 --- a/python/src/com/jetbrains/python/testing/PyTestsShared.kt +++ b/python/src/com/jetbrains/python/testing/PyTestsShared.kt @@ -234,8 +234,8 @@ abstract class PyTestExecutionEnvironment(confi override fun getTestSpecs(): MutableList = java.util.ArrayList(configuration.getTestSpec()) - override fun generateCommandLine(patchers: Array?): GeneralCommandLine { - val line = super.generateCommandLine(patchers) + override fun generateCommandLine(): GeneralCommandLine { + val line = super.generateCommandLine() line.workDirectory = java.io.File(configuration.workingDirectorySafe) return line } diff --git a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java index fcea305d3e30..140a4fdac817 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java +++ b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java @@ -97,6 +97,7 @@ public abstract class PythonTestCommandLineStateBase