本文整理汇总了Java中com.jetbrains.python.sdk.PythonSdkType类的典型用法代码示例。如果您正苦于以下问题:Java PythonSdkType类的具体用法?Java PythonSdkType怎么用?Java PythonSdkType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonSdkType类属于com.jetbrains.python.sdk包,在下文中一共展示了PythonSdkType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSphinxQuickStartRequiredAction
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
public static Presentation updateSphinxQuickStartRequiredAction(final AnActionEvent e) {
final Presentation presentation = e.getPresentation();
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project != null) {
Module module = e.getData(LangDataKeys.MODULE);
if (module == null) {
Module[] modules = ModuleManager.getInstance(project).getModules();
module = modules.length == 0 ? null : modules [0];
}
if (module != null) {
Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk != null) {
PyPackageManager manager = PyPackageManager.getInstance(sdk);
try {
final PyPackage sphinx = manager.findPackage("Sphinx", false);
presentation.setEnabled(sphinx != null);
}
catch (ExecutionException ignored) {
}
}
}
}
return presentation;
}
示例2: proposeImportFix
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Nullable
public static AutoImportQuickFix proposeImportFix(final PyElement node, PsiReference reference) {
final String text = reference.getElement().getText();
final String refText = reference.getRangeInElement().substring(text); // text of the part we're working with
// don't propose meaningless auto imports if no interpreter is configured
final Module module = ModuleUtilCore.findModuleForPsiElement(node);
if (module != null && PythonSdkType.findPythonSdk(module) == null) {
return null;
}
// don't show auto-import fix if we're trying to reference a variable which is defined below in the same scope
ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(node, ScopeOwner.class);
if (scopeOwner != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(refText)) {
return null;
}
AutoImportQuickFix fix = addCandidates(node, reference, refText, null);
if (fix != null) return fix;
final String packageName = PyPackageAliasesProvider.commonImportAliases.get(refText);
if (packageName != null) {
fix = addCandidates(node, reference, packageName, refText);
if (fix != null) return fix;
}
return null;
}
示例3: visitPyTargetExpression
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Override
public void visitPyTargetExpression(final PyTargetExpression node) {
String targetName = node.getName();
if (PyNames.NONE.equals(targetName)) {
final VirtualFile vfile = node.getContainingFile().getVirtualFile();
if (vfile != null && !vfile.getUrl().contains("/" + PythonSdkType.SKELETON_DIR_NAME + "/")){
getHolder().createErrorAnnotation(node, (myOp == Operation.Delete) ? DELETING_NONE : ASSIGNMENT_TO_NONE);
}
}
if (PyNames.DEBUG.equals(targetName)) {
if (LanguageLevel.forElement(node).isPy3K()) {
getHolder().createErrorAnnotation(node, "assignment to keyword");
}
else {
getHolder().createErrorAnnotation(node, "cannot assign to __debug__");
}
}
}
示例4: visitPyFile
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Override
public void visitPyFile(PyFile node) {
super.visitPyFile(node);
if (PlatformUtils.isPyCharm()) {
final Module module = ModuleUtilCore.findModuleForPsiElement(node);
if (module != null) {
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk == null) {
registerProblem(node, "No Python interpreter configured for the project", new ConfigureInterpreterFix());
}
else if (PythonSdkType.isInvalid(sdk)) {
registerProblem(node, "Invalid Python interpreter selected for the project", new ConfigureInterpreterFix());
}
}
}
}
示例5: isIpythonNewFormat
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
public static boolean isIpythonNewFormat(@NotNull final VirtualFile virtualFile) {
final Project project = ProjectUtil.guessProjectForFile(virtualFile);
if (project != null) {
final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
if (module != null) {
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk != null) {
try {
final PyPackage ipython = PyPackageManager.getInstance(sdk).findPackage("ipython", true);
if (ipython != null && VersionComparatorUtil.compare(ipython.getVersion(), "3.0") <= 0) {
return false;
}
}
catch (ExecutionException ignored) {
}
}
}
}
return true;
}
示例6: addRelativeImportResultsFromSkeletons
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
/**
* Resolve relative imports from sdk root to the skeleton dir
*/
private void addRelativeImportResultsFromSkeletons(@NotNull final PsiFile foothold) {
final boolean inSource = FileIndexFacade.getInstance(foothold.getProject()).isInContent(foothold.getVirtualFile());
if (inSource) return;
PsiDirectory containingDirectory = foothold.getContainingDirectory();
if (myRelativeLevel > 0) {
containingDirectory = ResolveImportUtil.stepBackFrom(foothold, myRelativeLevel);
}
if (containingDirectory != null) {
final QualifiedName containingQName = QualifiedNameFinder.findCanonicalImportPath(containingDirectory, null);
if (containingQName != null && containingQName.getComponentCount() > 0) {
final QualifiedName absoluteQName = containingQName.append(myQualifiedName.toString());
final QualifiedNameResolverImpl absoluteVisitor =
(QualifiedNameResolverImpl)new QualifiedNameResolverImpl(absoluteQName).fromElement(foothold);
final Sdk sdk = PythonSdkType.getSdk(foothold);
if (sdk == null) return;
final VirtualFile skeletonsDir = PySdkUtil.findSkeletonsDir(sdk);
if (skeletonsDir == null) return;
final PsiDirectory directory = myContext.getPsiManager().findDirectory(skeletonsDir);
final PsiElement psiElement = absoluteVisitor.resolveModuleAt(directory);
if (psiElement != null)
myLibResults.add(psiElement);
}
}
}
示例7: excludeSdkTestsScope
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Nullable
public static GlobalSearchScope excludeSdkTestsScope(Project project, Sdk sdk) {
if (sdk != null && sdk.getSdkType() instanceof PythonSdkType) {
VirtualFile libDir = findLibDir(sdk);
if (libDir != null) {
// superset of test dirs found in Python 2.5 to 3.1
List<VirtualFile> testDirs = findTestDirs(libDir, "test", "bsddb/test", "ctypes/test", "distutils/tests", "email/test",
"importlib/test", "json/tests", "lib2to3/tests", "sqlite3/test", "tkinter/test",
"idlelib/testcode.py");
if (!testDirs.isEmpty()) {
GlobalSearchScope scope = buildUnionScope(project, testDirs);
return GlobalSearchScope.notScope(scope);
}
}
}
return null;
}
示例8: findVirtualEnvLibDir
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
public static VirtualFile findVirtualEnvLibDir(Sdk sdk) {
VirtualFile[] classVFiles = sdk.getRootProvider().getFiles(OrderRootType.CLASSES);
String homePath = sdk.getHomePath();
if (homePath != null) {
File root = PythonSdkType.getVirtualEnvRoot(homePath);
if (root != null) {
File libRoot = new File(root, "lib");
File[] versionRoots = libRoot.listFiles();
if (versionRoots != null && versionRoots.length == 1) {
libRoot = versionRoots[0];
}
for (VirtualFile file : classVFiles) {
if (FileUtil.pathsEqual(file.getPath(), libRoot.getPath())) {
return file;
}
}
}
}
return null;
}
示例9: findSdkForNonModuleFile
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
Project project = psiFile.getProject();
Sdk sdk = null;
final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
if (vfile != null) { // reality
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
sdk = projectRootManager.getProjectSdk();
if (sdk == null) {
final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof JdkOrderEntry) {
sdk = ((JdkOrderEntry)orderEntry).getJdk();
}
else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
}
}
}
}
return sdk;
}
示例10: getBuiltInCache
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Nullable
private static PyBuiltinCache getBuiltInCache(PyQualifiedExpression element) {
final PsiElement realContext = PyPsiUtils.getRealContext(element);
PsiFileSystemItem psiFile = realContext.getContainingFile();
if (psiFile == null) {
return null;
}
Sdk sdk = PyBuiltinCache.findSdkForFile(psiFile);
if (sdk != null && sdk.getSdkType() instanceof PythonSdkType) {
// this case is already handled by PythonBuiltinReferenceResolveProvider
return null;
}
Sdk pythonSdk = PySdkUtils.getPythonSdk(psiFile.getProject());
return pythonSdk != null
? PythonSdkPathCache.getInstance(psiFile.getProject(), pythonSdk).getBuiltins()
: null;
}
示例11: generateBuiltinSkeletons
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
public void generateBuiltinSkeletons(@NotNull Sdk sdk) throws InvalidSdkException {
//noinspection ResultOfMethodCallIgnored
new File(mySkeletonsPath).mkdirs();
String binaryPath = sdk.getHomePath();
if (binaryPath == null) throw new InvalidSdkException("Broken home path for " + sdk.getName());
long startTime = System.currentTimeMillis();
final ProcessOutput runResult = getProcessOutput(
new File(binaryPath).getParent(),
new String[]{
binaryPath,
PythonHelpersLocator.getHelperPath(GENERATOR3),
"-d", mySkeletonsPath, // output dir
"-b", // for builtins
},
PythonSdkType.getVirtualEnvExtraEnv(binaryPath), MINUTE * 5
);
runResult.checkSuccess(LOG);
LOG.info("Rebuilding builtin skeletons took " + (System.currentTimeMillis() - startTime) + " ms");
}
示例12: createVirtualEnv
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@NotNull
public static String createVirtualEnv(@NotNull String destinationDir, String version) throws ExecutionException {
final String condaExecutable = PyCondaPackageService.getCondaExecutable();
if (condaExecutable == null) throw new PyExecutionException("Cannot find conda", "Conda", Collections.<String>emptyList(), new ProcessOutput());
final ArrayList<String> parameters = Lists.newArrayList(condaExecutable, "create", "-p", destinationDir,
"python=" + version, "-y");
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
final Process process = commandLine.createProcess();
final CapturingProcessHandler handler = new CapturingProcessHandler(process);
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
final ProcessOutput result = handler.runProcessWithProgressIndicator(indicator);
if (result.isCancelled()) {
throw new RunCanceledByUserException();
}
final int exitCode = result.getExitCode();
if (exitCode != 0) {
final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ?
"Permission denied" : "Non-zero exit code";
throw new PyExecutionException(message, "Conda", parameters, result);
}
final String binary = PythonSdkType.getPythonExecutable(destinationDir);
final String binaryFallback = destinationDir + File.separator + "bin" + File.separator + "python";
return (binary != null) ? binary : binaryFallback;
}
示例13: forSdk
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@NotNull
public synchronized PyPackageManager forSdk(Sdk sdk) {
final String name = sdk.getName();
PyPackageManagerImpl manager = myInstances.get(name);
if (manager == null) {
if (PythonSdkType.isRemote(sdk)) {
manager = new PyRemotePackageManagerImpl(sdk);
}
else if (PyCondaPackageManagerImpl.isCondaVEnv(sdk) && PyCondaPackageService.getCondaExecutable() != null) {
manager = new PyCondaPackageManagerImpl(sdk);
}
else {
manager = new PyPackageManagerImpl(sdk);
}
myInstances.put(name, manager);
}
return manager;
}
示例14: updateProjectSdk
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Override
public void updateProjectSdk(
Project project,
BlazeContext context,
ProjectViewSet projectViewSet,
BlazeVersionData blazeVersionData,
BlazeProjectData blazeProjectData) {
if (!blazeProjectData.workspaceLanguageSettings.isWorkspaceType(WorkspaceType.PYTHON)) {
return;
}
Sdk currentSdk = ProjectRootManager.getInstance(project).getProjectSdk();
if (currentSdk != null && currentSdk.getSdkType() instanceof PythonSdkType) {
return;
}
Sdk sdk = getOrCreatePythonSdk();
if (sdk != null) {
setProjectSdk(project, sdk);
}
}
示例15: findErrorSolution
import com.jetbrains.python.sdk.PythonSdkType; //导入依赖的package包/类
@Nullable
private static String findErrorSolution(@NotNull PyExecutionException e, @Nullable String cause, @Nullable Sdk sdk) {
if (cause != null) {
if (StringUtil.containsIgnoreCase(cause, "SyntaxError")) {
final LanguageLevel languageLevel = PythonSdkType.getLanguageLevelForSdk(sdk);
return "Make sure that you use a version of Python supported by this package. Currently you are using Python " +
languageLevel + ".";
}
}
if (SystemInfo.isLinux && (containsInOutput(e, "pyconfig.h") || containsInOutput(e, "Python.h"))) {
return "Make sure that you have installed Python development packages for your operating system.";
}
if ("pip".equals(e.getCommand()) && sdk != null) {
return "Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' " +
"installed for your Python interpreter located at '" + sdk.getHomePath() + "'.";
}
return null;
}