/** * Patches the command line parameters applying patchers from first to last, and then runs it. * * @param patchers any number of patchers; any patcher may be null, and the whole argument may be * null. * @return handler of the started process * @throws ExecutionException */ protected ProcessHandler startProcess(CommandLinePatcher... patchers) throws ExecutionException { GeneralCommandLine commandLine = generateCommandLine(patchers); // Extend command line PythonRunConfigurationExtensionsManager.getInstance() .patchCommandLine( myConfig, getRunnerSettings(), commandLine, getEnvironment().getRunner().getRunnerId()); Sdk sdk = PythonSdkType.findSdkByPath(myConfig.getInterpreterPath()); final ProcessHandler processHandler; if (PySdkUtil.isRemote(sdk)) { PyRemotePathMapper pathMapper = createRemotePathMapper(); processHandler = createRemoteProcessStarter() .startRemoteProcess(sdk, commandLine, myConfig.getProject(), pathMapper); } else { EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(commandLine); processHandler = doCreateProcess(commandLine); ProcessTerminatedListener.attach(processHandler); } // attach extensions PythonRunConfigurationExtensionsManager.getInstance() .attachExtensionsToProcess(myConfig, processHandler, getRunnerSettings()); return processHandler; }
public GeneralCommandLine generateCommandLine() { GeneralCommandLine commandLine = createPythonCommandLine(myConfig.getProject(), myConfig); buildCommandLineParameters(commandLine); customizeEnvironmentVars(commandLine.getEnvironment(), myConfig.isPassParentEnvs()); return commandLine; }
@Nullable private PyRemotePathMapper createRemotePathMapper() { if (myConfig.getMappingSettings() == null) { return null; } else { return PyRemotePathMapper.fromSettings( myConfig.getMappingSettings(), PyRemotePathMapper.PyPathMappingType.USER_DEFINED); } }
protected void addTracebackFilter( Project project, ConsoleView consoleView, ProcessHandler processHandler) { if (PySdkUtil.isRemote(myConfig.getSdk())) { assert processHandler instanceof RemoteProcessControl; consoleView.addMessageFilter( new PyRemoteTracebackFilter( project, myConfig.getWorkingDirectory(), (RemoteProcessControl) processHandler)); } else { consoleView.addMessageFilter( new PythonTracebackFilter(project, myConfig.getWorkingDirectorySafe())); } consoleView.addMessageFilter( createUrlFilter(processHandler)); // Url filter is always nice to have }
public boolean isMultiprocessDebug() { if (myMultiprocessDebug != null) { return myMultiprocessDebug; } else { return PyDebuggerOptionsProvider.getInstance(myConfig.getProject()).isAttachToSubprocess(); } }
protected String getInterpreterPath() throws ExecutionException { String interpreterPath = myConfig.getInterpreterPath(); if (interpreterPath == null) { throw new ExecutionException("Cannot find Python interpreter for this run configuration"); } return interpreterPath; }
private TextConsoleBuilder createConsoleBuilder(Project project) { if (isDebug()) { return new PyDebugConsoleBuilder( project, PythonSdkType.findSdkByPath(myConfig.getInterpreterPath())); } else { return TextConsoleBuilderFactory.getInstance().createBuilder(project); } }
public ExecutionResult execute(Executor executor, CommandLinePatcher... patchers) throws ExecutionException { final ProcessHandler processHandler = startProcess(patchers); final ConsoleView console = createAndAttachConsole(myConfig.getProject(), processHandler, executor); List<AnAction> actions = Lists.newArrayList(createActions(console, processHandler)); return new DefaultExecutionResult( console, processHandler, actions.toArray(new AnAction[actions.size()])); }
public Sdk getSdk() { return myConfig.getSdk(); }
@Nullable public PythonSdkFlavor getSdkFlavor() { return PythonSdkFlavor.getFlavor(myConfig.getInterpreterPath()); }