use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PythonSdkUpdater method filterRootPaths.
/**
* Filters valid paths from an initial set of Python paths and returns them as virtual files.
*/
@NotNull
public static List<VirtualFile> filterRootPaths(@NotNull Sdk sdk, @NotNull List<String> paths, @Nullable Project project) {
final PythonSdkAdditionalData pythonAdditionalData = PyUtil.as(sdk.getSdkAdditionalData(), PythonSdkAdditionalData.class);
final Collection<VirtualFile> excludedPaths = pythonAdditionalData != null ? pythonAdditionalData.getExcludedPathFiles() : Collections.emptyList();
final Set<VirtualFile> moduleRoots = new HashSet<>();
if (project != null) {
final Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
moduleRoots.addAll(PyUtil.getSourceRoots(module));
}
}
final List<VirtualFile> results = Lists.newArrayList();
for (String path : paths) {
if (path != null && !FileUtilRt.extensionEquals(path, "egg-info")) {
final VirtualFile virtualFile = StandardFileSystems.local().refreshAndFindFileByPath(path);
if (virtualFile != null) {
final VirtualFile rootFile = PythonSdkType.getSdkRootVirtualFile(virtualFile);
if (!excludedPaths.contains(rootFile) && !moduleRoots.contains(rootFile)) {
results.add(rootFile);
continue;
}
}
}
LOG.info("Bogus sys.path entry " + path);
}
return results;
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PythonDocTestConfigurationProducer method isAvailable.
protected boolean isAvailable(@NotNull final Location location) {
final Module module = location.getModule();
if (!isPythonModule(module))
return false;
final PsiElement element = location.getPsiElement();
if (element instanceof PsiFile) {
final PyDocTestVisitor visitor = new PyDocTestVisitor();
element.accept(visitor);
return visitor.hasTests;
} else
return true;
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PythonNoseTestConfigurationProducer method isAvailable.
protected boolean isAvailable(@NotNull final Location location) {
final PsiElement element = location.getPsiElement();
Module module = location.getModule();
if (module == null) {
final Module[] modules = ModuleManager.getInstance(location.getProject()).getModules();
if (modules.length == 0)
return false;
module = modules[0];
}
final Sdk sdk = PythonSdkType.findPythonSdk(module);
return (PythonTestConfigurationsModel.PYTHONS_NOSETEST_NAME.equals(TestRunnerService.getInstance(module).getProjectConfiguration()) && sdk != null);
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class PyTestConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(AbstractPythonLegacyTestRunConfiguration<PyTestRunConfiguration> configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final PsiElement element = sourceElement.get();
final Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (!(configuration instanceof PyTestRunConfiguration)) {
return false;
}
if (module == null) {
return false;
}
if (!(TestRunnerService.getInstance(module).getProjectConfiguration().equals(PythonTestConfigurationsModel.PY_TEST_NAME))) {
return false;
}
final PsiFileSystemItem file = element instanceof PsiDirectory ? (PsiDirectory) element : element.getContainingFile();
if (file == null) {
return false;
}
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return false;
}
if (file instanceof PyFile || file instanceof PsiDirectory) {
final List<PyStatement> testCases = PyTestUtil.getPyTestCasesFromFile(file, TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()));
if (testCases.isEmpty()) {
return false;
}
} else {
return false;
}
final Sdk sdk = PythonSdkType.findPythonSdk(context.getModule());
if (sdk == null) {
return false;
}
configuration.setUseModuleSdk(true);
configuration.setModule(ModuleUtilCore.findModuleForPsiElement(element));
((PyTestRunConfiguration) configuration).setTestToRun(virtualFile.getPath());
final String keywords = getKeywords(element, sdk);
if (keywords != null) {
((PyTestRunConfiguration) configuration).useKeyword(true);
((PyTestRunConfiguration) configuration).setKeywords(keywords);
configuration.setName("py.test in " + keywords);
} else {
configuration.setName("py.test in " + file.getName());
}
return true;
}
use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.
the class ConfigFilesTreeBuilder method buildTree.
public Set<PsiFile> buildTree(DefaultMutableTreeNode root, ConfigFileSearcher... searchers) {
final Set<PsiFile> psiFiles = new com.intellij.util.containers.HashSet<>();
final MultiMap<Module, PsiFile> files = new MultiMap<>();
final MultiMap<VirtualFile, PsiFile> jars = new MultiMap<>();
final MultiMap<VirtualFile, PsiFile> virtualFiles = new MultiMap<>();
for (ConfigFileSearcher searcher : searchers) {
files.putAllValues(searcher.getFilesByModules());
jars.putAllValues(searcher.getJars());
virtualFiles.putAllValues(searcher.getVirtualFiles());
}
psiFiles.addAll(buildModuleNodes(files, jars, root));
for (Map.Entry<VirtualFile, Collection<PsiFile>> entry : virtualFiles.entrySet()) {
DefaultMutableTreeNode node = createFileNode(entry.getKey());
List<PsiFile> list = new ArrayList<>(entry.getValue());
Collections.sort(list, FILE_COMPARATOR);
for (PsiFile file : list) {
node.add(createFileNode(file));
}
root.add(node);
}
return psiFiles;
}
Aggregations