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) { // It should be called first before IpnbConnectionManager#startIpythonServer() final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk); final PyPackage ipython = packages != null ? PyPackageUtil.findPackage(packages, "ipython") : null; final PyPackage jupyter = packages != null ? PyPackageUtil.findPackage(packages, "jupyter") : null; if (jupyter == null && ipython != null && VersionComparatorUtil.compare(ipython.getVersion(), "3.0") <= 0) { return false; } } } } return true; }
/** * Here we check if a given file belongs to our plugin. We take this road because we need the * actual file and not a filename to check files without extension. * * <p>A file is checked according to the rules defined in the facet settings. A file can be set to * ignored, accepted or auto. Auto means that the content is checked. * * @param file The file to check * @return True if BashSupport wants to take that file */ public boolean isMyFileType(VirtualFile file) { if (file == null) { return false; } if (file.isDirectory()) { return false; } if (extensionList.contains(file.getExtension())) { return true; } else if (!file.isInLocalFileSystem()) { return false; } else if (StringUtils.isEmpty(file.getExtension())) { BashFacet facet = null; try { // no extensions, special checks (looking at the content, etc) // guess project Project project = ProjectUtil.guessProjectForFile(file); if (project == null) { return false; } DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project); if (dumbService == null || dumbService.isDumb()) { return false; } DirectoryIndex directoryIndex = DirectoryIndex.getInstance(project); if (directoryIndex == null || !directoryIndex.isInitialized()) { return false; } Module module = ModuleUtil.findModuleForFile(file, project); if (module == null) { return false; } facet = BashFacet.getInstance(module); if (facet == null) { return false; } BashFacetConfiguration config = facet.getConfiguration(); FileMode mode = config.findMode(file); if (mode == FileMode.accept()) { return true; } else if (mode == FileMode.ignore()) { return false; } else if (mode == FileMode.auto()) { return BashContentUtil.isProbablyBashFile( VfsUtil.virtualToIoFile(file), MIN_FILE_PROBABILIY, ProjectUtil.guessProjectForFile(file)); } } catch (Exception e) { // ignore this LOG.warn("Could not check the file type due to exception", e); } } return false; }