mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external tool macro for directory containing Python interpreter (PY-6533)
This commit is contained in:
@@ -129,7 +129,8 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
|
||||
"SelectionStartLine",
|
||||
"SelectionEndLine",
|
||||
"SelectionStartColumn",
|
||||
"SelectionEndColumn"
|
||||
"SelectionEndColumn",
|
||||
"PyInterpreterDirectory"
|
||||
);
|
||||
|
||||
public PathMacrosImpl() {
|
||||
|
||||
@@ -473,6 +473,8 @@
|
||||
<postStartupActivity implementation="com.jetbrains.python.packaging.PyPIPackagesUpdater"/>
|
||||
<postStartupActivity implementation="com.jetbrains.python.testing.PyTestRunnerUpdater"/>
|
||||
|
||||
<macro implementation="com.jetbrains.python.sdk.InterpreterDirectoryMacro"/>
|
||||
|
||||
<!-- User skeletons -->
|
||||
<codeInsight.lineMarkerProvider language="Python" implementationClass="com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsLineMarkerProvider"/>
|
||||
|
||||
@@ -504,7 +506,6 @@
|
||||
<!-- Packaging -->
|
||||
<moduleService serviceInterface="com.jetbrains.python.packaging.PyPackageRequirementsSettings"
|
||||
serviceImplementation="com.jetbrains.python.packaging.PyPackageRequirementsSettings"/>
|
||||
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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;
|
||||
|
||||
import com.intellij.ide.macro.Macro;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
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.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class InterpreterDirectoryMacro extends Macro {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "PyInterpreterDirectory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "The directory containing the Python interpreter selected for the project";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String expand(DataContext dataContext) throws ExecutionCancelledException {
|
||||
Module module = LangDataKeys.MODULE.getData(dataContext);
|
||||
if (module == null) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) {
|
||||
return null;
|
||||
}
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
if (modules.length == 0) {
|
||||
return null;
|
||||
}
|
||||
module = modules[0];
|
||||
}
|
||||
Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk != null) {
|
||||
VirtualFile homeDir = sdk.getHomeDirectory();
|
||||
if (homeDir == null) {
|
||||
return null;
|
||||
}
|
||||
String path = PathUtil.getLocalPath(homeDir.getParent());
|
||||
if (path != null) {
|
||||
return FileUtil.toSystemDependentName(path);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user