Search in sources :

Example 1 with BuildoutFacet

use of com.jetbrains.python.buildout.BuildoutFacet in project intellij-community by JetBrains.

the class SphinxBaseCommand method createCommandLine.

protected GeneralCommandLine createCommandLine(Module module, List<String> params) throws ExecutionException {
    Sdk sdk = PythonSdkType.findPythonSdk(module);
    if (sdk == null) {
        throw new ExecutionException("No sdk specified");
    }
    ReSTService service = ReSTService.getInstance(module);
    String sdkHomePath = sdk.getHomePath();
    GeneralCommandLine cmd = new GeneralCommandLine();
    if (sdkHomePath != null) {
        final String runnerName = "sphinx-quickstart" + (SystemInfo.isWindows ? ".exe" : "");
        String executablePath = PythonSdkType.getExecutablePath(sdkHomePath, runnerName);
        if (executablePath != null) {
            cmd.setExePath(executablePath);
        } else {
            cmd = PythonHelper.LOAD_ENTRY_POINT.newCommandLine(sdkHomePath, Lists.<String>newArrayList());
        }
    }
    cmd.setWorkDirectory(service.getWorkdir().isEmpty() ? module.getProject().getBaseDir().getPath() : service.getWorkdir());
    PythonCommandLineState.createStandardGroups(cmd);
    ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
    assert scriptParams != null;
    if (params != null) {
        for (String p : params) {
            scriptParams.addParameter(p);
        }
    }
    final Map<String, String> env = cmd.getEnvironment();
    setPythonIOEncoding(env, "utf-8");
    setPythonUnbuffered(env);
    if (sdkHomePath != null) {
        resetHomePathChanges(sdkHomePath, env);
    }
    env.put("PYCHARM_EP_DIST", "Sphinx");
    env.put("PYCHARM_EP_NAME", "sphinx-quickstart");
    List<String> pathList = Lists.newArrayList(PythonCommandLineState.getAddedPaths(sdk));
    pathList.addAll(PythonCommandLineState.collectPythonPath(module));
    PythonCommandLineState.initPythonPath(cmd, true, pathList, sdkHomePath);
    PythonSdkType.patchCommandLineForVirtualenv(cmd, sdkHomePath, true);
    BuildoutFacet facet = BuildoutFacet.getInstance(module);
    if (facet != null) {
        facet.patchCommandLineForBuildout(cmd);
    }
    return cmd;
}
Also used : ParamsGroup(com.intellij.execution.configurations.ParamsGroup) BuildoutFacet(com.jetbrains.python.buildout.BuildoutFacet) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ReSTService(com.jetbrains.python.ReSTService) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with BuildoutFacet

use of com.jetbrains.python.buildout.BuildoutFacet in project intellij-community by JetBrains.

the class PythonTask method createCommandLine.

public GeneralCommandLine createCommandLine() {
    GeneralCommandLine cmd = new GeneralCommandLine();
    if (myWorkingDirectory != null) {
        cmd.setWorkDirectory(myWorkingDirectory);
    }
    String homePath = mySdk.getHomePath();
    if (homePath != null) {
        homePath = FileUtil.toSystemDependentName(homePath);
    }
    PythonCommandLineState.createStandardGroups(cmd);
    ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
    assert scriptParams != null;
    Map<String, String> env = cmd.getEnvironment();
    if (!SystemInfo.isWindows && !PySdkUtil.isRemote(mySdk)) {
        cmd.setExePath("bash");
        ParamsGroup bashParams = cmd.getParametersList().addParamsGroupAt(0, "Bash");
        bashParams.addParameter("-cl");
        NotNullFunction<String, String> escaperFunction = StringUtil.escaper(false, "|>$\"'& ");
        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);
        }
        bashParams.addParameter(paramString.toString());
    } else {
        cmd.setExePath(homePath);
        if (myHelper != null) {
            myHelper.addToGroup(scriptParams, cmd);
        } else {
            scriptParams.addParameter(myRunnerScript);
        }
        scriptParams.addParameters(myParameters.stream().filter(o -> o != null).collect(Collectors.toList()));
    }
    PythonEnvUtil.setPythonUnbuffered(env);
    if (homePath != null) {
        PythonEnvUtil.resetHomePathChanges(homePath, env);
    }
    List<String> pythonPath = setupPythonPath();
    PythonCommandLineState.initPythonPath(cmd, true, pythonPath, homePath);
    BuildoutFacet facet = BuildoutFacet.getInstance(myModule);
    if (facet != null) {
        facet.patchCommandLineForBuildout(cmd);
    }
    return cmd;
}
Also used : ParamsGroup(com.intellij.execution.configurations.ParamsGroup) BuildoutFacet(com.jetbrains.python.buildout.BuildoutFacet) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Example 3 with BuildoutFacet

use of com.jetbrains.python.buildout.BuildoutFacet in project intellij-community by JetBrains.

the class PydevConsoleRunnerFactory method createConsoleRunner.

@Override
@NotNull
public PydevConsoleRunnerImpl createConsoleRunner(@NotNull Project project, @Nullable Module contextModule) {
    Pair<Sdk, Module> sdkAndModule = PydevConsoleRunner.findPythonSdkAndModule(project, contextModule);
    Module module = sdkAndModule.second;
    Sdk sdk = sdkAndModule.first;
    assert sdk != null;
    PyConsoleOptions.PyConsoleSettings settingsProvider = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
    PathMapper pathMapper = PydevConsoleRunner.getPathMapper(project, sdk, settingsProvider);
    String[] setupFragment;
    Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.shouldAddContentRoots(), settingsProvider.shouldAddSourceRoots());
    if (pathMapper != null) {
        pythonPath = pathMapper.convertToRemote(pythonPath);
    }
    String customStartScript = settingsProvider.getCustomStartScript();
    if (customStartScript.trim().length() > 0) {
        customStartScript = "\n" + customStartScript;
    }
    String workingDir = settingsProvider.getWorkingDirectory();
    if (StringUtil.isEmpty(workingDir)) {
        if (module != null && ModuleRootManager.getInstance(module).getContentRoots().length > 0) {
            workingDir = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath();
        } else {
            if (ModuleManager.getInstance(project).getModules().length > 0) {
                VirtualFile[] roots = ModuleRootManager.getInstance(ModuleManager.getInstance(project).getModules()[0]).getContentRoots();
                if (roots.length > 0) {
                    workingDir = roots[0].getPath();
                }
            }
        }
    }
    if (pathMapper != null && workingDir != null) {
        workingDir = pathMapper.convertToRemote(workingDir);
    }
    String selfPathAppend = PydevConsoleRunner.constructPyPathAndWorkingDirCommand(pythonPath, workingDir, customStartScript);
    BuildoutFacet facet = null;
    if (module != null) {
        facet = BuildoutFacet.getInstance(module);
    }
    if (facet != null) {
        List<String> path = facet.getAdditionalPythonPath();
        if (pathMapper != null) {
            path = pathMapper.convertToRemote(path);
        }
        String prependStatement = facet.getPathPrependStatement(path);
        setupFragment = new String[] { prependStatement, selfPathAppend };
    } else {
        setupFragment = new String[] { selfPathAppend };
    }
    Map<String, String> envs = Maps.newHashMap(settingsProvider.getEnvs());
    putIPythonEnvFlag(project, envs);
    Consumer<String> rerunAction = title -> {
        PydevConsoleRunnerImpl runner = createConsoleRunner(project, module);
        runner.setConsoleTitle(title);
        runner.run();
    };
    return createConsoleRunner(project, sdk, workingDir, envs, PyConsoleType.PYTHON, settingsProvider, rerunAction, setupFragment);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleManager(com.intellij.openapi.module.ModuleManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Collection(java.util.Collection) Maps(com.google.common.collect.Maps) Sdk(com.intellij.openapi.projectRoots.Sdk) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) PythonEnvUtil(com.jetbrains.python.sdk.PythonEnvUtil) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair) BuildoutFacet(com.jetbrains.python.buildout.BuildoutFacet) Project(com.intellij.openapi.project.Project) PathMapper(com.intellij.util.PathMapper) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) PathMapper(com.intellij.util.PathMapper) BuildoutFacet(com.jetbrains.python.buildout.BuildoutFacet) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuildoutFacet (com.jetbrains.python.buildout.BuildoutFacet)3 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 ParamsGroup (com.intellij.execution.configurations.ParamsGroup)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 Maps (com.google.common.collect.Maps)1 ExecutionException (com.intellij.execution.ExecutionException)1 Module (com.intellij.openapi.module.Module)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 Project (com.intellij.openapi.project.Project)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 Pair (com.intellij.openapi.util.Pair)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Consumer (com.intellij.util.Consumer)1 PathMapper (com.intellij.util.PathMapper)1 ReSTService (com.jetbrains.python.ReSTService)1 PythonCommandLineState (com.jetbrains.python.run.PythonCommandLineState)1 PythonEnvUtil (com.jetbrains.python.sdk.PythonEnvUtil)1 Collection (java.util.Collection)1 List (java.util.List)1