introduced pycharm_load_entry_point instead of searching for executable through local file system

so Pyramid run configuration and Sphinx-quickstart works with remote interpreter
(PY-13043 Pyramid: not able to run pyramid run configuration on remote interpreter)
This commit is contained in:
Ekaterina Tuzova
2014-05-23 17:33:14 +04:00
parent 1a0533bf03
commit 0fcb1c3fc5
6 changed files with 36 additions and 56 deletions

View File

@@ -18,19 +18,16 @@ package com.jetbrains.rest;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
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.util.SystemInfo;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.packaging.PyPackageManagerImpl;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.Nullable;
/**
* User : catherine
@@ -54,8 +51,7 @@ public class RestPythonUtil {
PyPackageManagerImpl manager = (PyPackageManagerImpl)PyPackageManager.getInstance(sdk);
try {
final PyPackage sphinx = manager.findPackage("Sphinx");
String quickStart = findQuickStart(sdk);
presentation.setEnabled(sphinx != null && quickStart != null);
presentation.setEnabled(sphinx != null);
}
catch (PyExternalProcessException ignored) {
}
@@ -64,10 +60,4 @@ public class RestPythonUtil {
}
return presentation;
}
@Nullable
public static String findQuickStart(final Sdk sdkHome) {
final String runnerName = "sphinx-quickstart" + (SystemInfo.isWindows ? ".exe" : "");
return PythonSdkType.getExecutablePath(sdkHome, runnerName);
}
}

View File

@@ -22,7 +22,6 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import com.jetbrains.rest.RestPythonUtil;
import com.jetbrains.rest.RestTokenTypes;
import com.jetbrains.rest.RestUtil;
import com.jetbrains.rest.psi.RestReferenceTarget;
@@ -48,11 +47,8 @@ public class SphinxDirectiveCompletionContributor extends CompletionContributor
@NotNull CompletionResultSet result) {
Sdk sdk = ProjectRootManager.getInstance(parameters.getPosition().getProject()).getProjectSdk();
if (sdk != null) {
String sphinx = RestPythonUtil.findQuickStart(sdk);
if (sphinx != null) {
for (String tag : RestUtil.SPHINX_DIRECTIVES) {
result.addElement(LookupElementBuilder.create(tag));
}
for (String tag : RestUtil.SPHINX_DIRECTIVES) {
result.addElement(LookupElementBuilder.create(tag));
}
}
}

View File

@@ -21,8 +21,6 @@ import com.intellij.codeInspection.ui.ListEditForm;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.JDOMExternalizableStringList;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -34,7 +32,10 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.HashSet;
import com.jetbrains.python.ReSTService;
import com.jetbrains.python.psi.*;
import com.jetbrains.rest.*;
import com.jetbrains.rest.RestBundle;
import com.jetbrains.rest.RestFile;
import com.jetbrains.rest.RestTokenTypes;
import com.jetbrains.rest.RestUtil;
import com.jetbrains.rest.psi.RestDirectiveBlock;
import com.jetbrains.rest.psi.RestRole;
import com.jetbrains.rest.quickfixes.AddIgnoredRoleFix;
@@ -96,17 +97,15 @@ public class RestRoleInspection extends RestInspection {
for (PyFunction function : functions) {
if (!"setup".equals(function.getName())) continue;
PyStatementList stList = function.getStatementList();
if (stList != null) {
PyStatement[] statements = stList.getStatements();
for (PyElement statement : statements) {
if (statement instanceof PyExpressionStatement)
statement = ((PyExpressionStatement)statement).getExpression();
if (statement instanceof PyCallExpression) {
if (((PyCallExpression)statement).isCalleeText("add_role")) {
PyExpression arg = ((PyCallExpression)statement).getArguments()[0];
if (arg instanceof PyStringLiteralExpression)
mySphinxRoles.add(((PyStringLiteralExpression)arg).getStringValue());
}
PyStatement[] statements = stList.getStatements();
for (PyElement statement : statements) {
if (statement instanceof PyExpressionStatement)
statement = ((PyExpressionStatement)statement).getExpression();
if (statement instanceof PyCallExpression) {
if (((PyCallExpression)statement).isCalleeText("add_role")) {
PyExpression arg = ((PyCallExpression)statement).getArguments()[0];
if (arg instanceof PyStringLiteralExpression)
mySphinxRoles.add(((PyStringLiteralExpression)arg).getStringValue());
}
}
}
@@ -124,14 +123,8 @@ public class RestRoleInspection extends RestInspection {
if (RestUtil.PREDEFINED_ROLES.contains(node.getText()) || myIgnoredRoles.contains(node.getRoleName()))
return;
Sdk sdk = ProjectRootManager.getInstance(node.getProject()).getProjectSdk();
if (sdk != null) {
String sphinx = RestPythonUtil.findQuickStart(sdk);
if (sphinx != null) {
if (RestUtil.SPHINX_ROLES.contains(node.getText()) || RestUtil.SPHINX_ROLES.contains(":py"+node.getText())
|| mySphinxRoles.contains(node.getRoleName())) return;
}
}
if (RestUtil.SPHINX_ROLES.contains(node.getText()) || RestUtil.SPHINX_ROLES.contains(":py"+node.getText())
|| mySphinxRoles.contains(node.getRoleName())) return;
Set<String> definedRoles = new HashSet<String>();

View File

@@ -31,13 +31,13 @@ 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.ReSTService;
import com.jetbrains.python.buildout.BuildoutFacet;
import com.jetbrains.python.run.PythonCommandLineState;
import com.jetbrains.python.run.PythonProcessRunner;
import com.jetbrains.python.run.PythonTracebackFilter;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.rest.RestPythonUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -152,17 +152,20 @@ public class SphinxBaseCommand {
ParamsGroup script_params = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
assert script_params != null;
String commandPath = getCommandPath(sdk);
String commandPath = PythonHelpersLocator.getHelperPath("pycharm/pycharm_load_entry_point.py");
if (commandPath == null) {
throw new ExecutionException("Cannot find sphinx-quickstart.");
}
cmd.setExePath(commandPath);
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);
}
}
cmd.addParameters("Sphinx", "sphinx-quickstart");
cmd.setPassParentEnvironment(true);
setPythonIOEncoding(cmd.getEnvironment(), "utf-8");
@@ -171,9 +174,9 @@ public class SphinxBaseCommand {
List<String> pathList = Lists.newArrayList(PythonCommandLineState.getAddedPaths(sdk));
pathList.addAll(PythonCommandLineState.collectPythonPath(module));
PythonCommandLineState.initPythonPath(cmd, true, pathList, sdk.getHomePath());
PythonCommandLineState.initPythonPath(cmd, true, pathList, sdkHomePath);
PythonSdkType.patchCommandLineForVirtualenv(cmd, sdk.getHomePath(), true);
PythonSdkType.patchCommandLineForVirtualenv(cmd, sdkHomePath, true);
BuildoutFacet facet = BuildoutFacet.getInstance(module);
if (facet != null) {
facet.patchCommandLineForBuildout(cmd);
@@ -182,8 +185,4 @@ public class SphinxBaseCommand {
return cmd;
}
@Nullable
private static String getCommandPath(Sdk sdk) {
return RestPythonUtil.findQuickStart(sdk);
}
}