Add extension point to provide custom Python flavors
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 6 Sep 2016 21:39:05 +0000 (23:39 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 6 Sep 2016 21:39:05 +0000 (23:39 +0200)
python/src/META-INF/python-core-common.xml
python/src/com/jetbrains/python/sdk/PySdkUtil.java
python/src/com/jetbrains/python/sdk/flavors/PythonFlavorProvider.java [new file with mode: 0644]
python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java

index ddbefb39366523aafb0253c6a2e909f6b6beca79..af172075a9843868364c26dede9475aaae62e892 100644 (file)
     <extensionPoint qualifiedName="Pythonid.runConfigurationEditorExtension" interface="com.jetbrains.python.run.PyRunConfigurationEditorExtension"/>
     <extensionPoint qualifiedName="Pythonid.pyCustomSdkUiProvider" interface="com.jetbrains.python.sdk.PyCustomSdkUiProvider"/>
     <extensionPoint qualifiedName="Pythonid.pep8ProblemSuppressor" interface="com.jetbrains.python.validation.Pep8ProblemSuppressor"/>
+    <extensionPoint qualifiedName="Pythonid.pythonFlavorProvider" interface="com.jetbrains.python.sdk.flavors.PythonFlavorProvider"/>
   </extensionPoints>
 
   <extensions defaultExtensionNs="Pythonid">
index afd2f51c3d87636aa30576f4094dadfba44500cb..3dd46f8f85057e12e400ada1653976c1e0a70965 100644 (file)
@@ -33,6 +33,7 @@ import com.intellij.psi.PsiFile;
 import com.intellij.remote.RemoteSdkAdditionalData;
 import com.intellij.util.SystemProperties;
 import com.intellij.util.containers.HashMap;
+import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -123,9 +124,12 @@ public class PySdkUtil {
     final Map<String, String> env = extraEnv != null ? mergeEnvVariables(expandedCmdEnv, extraEnv) : expandedCmdEnv;
     PythonEnvUtil.resetHomePathChanges(homePath, env);
     try {
-
-      final GeneralCommandLine commandLine = cmd.withWorkDirectory(homePath).withEnvironment(env);
-      final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine);
+      final GeneralCommandLine cmdLine = cmd.withWorkDirectory(homePath).withEnvironment(env);
+      final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(cmdLine.getExePath());
+      if (flavor != null) {
+        flavor.patchHelperCommandLine(cmdLine);
+      }
+      final CapturingProcessHandler processHandler = new CapturingProcessHandler(cmdLine);
       if (stdin != null) {
         final OutputStream processInput = processHandler.getProcessInput();
         assert processInput != null;
diff --git a/python/src/com/jetbrains/python/sdk/flavors/PythonFlavorProvider.java b/python/src/com/jetbrains/python/sdk/flavors/PythonFlavorProvider.java
new file mode 100644 (file)
index 0000000..211e1d1
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.sdk.flavors;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author traff
+ */
+public interface PythonFlavorProvider {
+  ExtensionPointName<PythonFlavorProvider> EP_NAME = ExtensionPointName.create("Pythonid.pythonFlavorProvider");
+
+  @Nullable
+  PythonSdkFlavor getFlavor(boolean platformIndependent);
+}
index e0ada9d3900739df1f53ea48eddccbc57d3e0652..8f79b8df4d7cd3d8f0f716a5a61132d87722a26d 100644 (file)
@@ -19,14 +19,13 @@ import com.google.common.collect.Lists;
 import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.process.ProcessOutput;
 import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.projectRoots.SdkAdditionalData;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
 import com.intellij.util.PatternUtil;
 import com.jetbrains.python.psi.LanguageLevel;
 import com.jetbrains.python.sdk.PySdkUtil;
@@ -90,8 +89,16 @@ public abstract class PythonSdkFlavor {
       result.add(UnixPythonSdkFlavor.INSTANCE);
     }
 
-    if (addPlatformIndependent)
+    if (addPlatformIndependent) {
       result.addAll(getPlatformIndependentFlavors());
+    }
+
+    for (PythonFlavorProvider provider : Extensions.getExtensions(PythonFlavorProvider.EP_NAME)) {
+      PythonSdkFlavor flavor = provider.getFlavor(addPlatformIndependent);
+      if (flavor != null) {
+        result.add(flavor);
+      }
+    }
 
     return result;
   }