void (@NotNull PyQualifiedExpression importedExpression) { for (PyInspectionExtension extension : PyInspectionExtension.EP_NAME.getExtensionList()) { if (extension.ignorePackageNameInRequirements(importedExpression)) { return; } } final PyExpression packageReferenceExpression = PyPsiUtils.getFirstQualifier(importedExpression); final String packageName = packageReferenceExpression.getName(); if (packageName != null && !myIgnoredPackages.contains(packageName)) { final String possiblePyPIPackageNames = PyPsiPackageUtil.PACKAGES_TOPLEVEL.getOrDefault(packageName, ""); if (!ApplicationManager.getApplication().isUnitTestMode() && !PyPIPackageUtil.INSTANCE.isInPyPI(packageName) && !PyPIPackageUtil.INSTANCE.isInPyPI(possiblePyPIPackageNames)) return; if (PyPackageUtil.SETUPTOOLS.equals(packageName)) return; final Collection<String> stdlibPackages = PyStdlibUtil.getPackages(); if (stdlibPackages != null && stdlibPackages.contains(packageName)) return; final Module module = ModuleUtilCore.findModuleForPsiElement(packageReferenceExpression); if (module == null) return; final Sdk sdk = PythonSdkUtil.findPythonSdk(module); if (sdk == null) return; final PyPackageManager packageManager = PyPackageManager.getInstance(sdk); final Collection<PyRequirement> requirements = getRequirementsInclTransitive(packageManager, module); if (requirements == null) return; for (PyRequirement req : requirements) { final String name = req.getName(); if (name.equalsIgnoreCase(packageName) || name.equalsIgnoreCase(possiblePyPIPackageNames)) { return; } final String nameWhereUnderscoreReplacedWithHyphen = name.replaceAll("_", "-"); if (nameWhereUnderscoreReplacedWithHyphen.equalsIgnoreCase(possiblePyPIPackageNames)) { return; } final String nameWhereHyphenReplacedWithUnderscore = name.replaceAll("-", "_"); if (nameWhereHyphenReplacedWithUnderscore.equalsIgnoreCase(packageName) || nameWhereHyphenReplacedWithUnderscore.equalsIgnoreCase(possiblePyPIPackageNames)) { return; } } if (!ApplicationManager.getApplication().isUnitTestMode()) { final PsiReference reference = packageReferenceExpression.getReference(); if (reference != null) { final PsiElement element = reference.resolve(); if (element instanceof PsiDirectory && ModuleUtilCore.moduleContainsFile(module, ((PsiDirectory)element).getVirtualFile(), false)) { return; } else if (element != null) { final PsiFile file = element.getContainingFile(); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); if (ModuleUtilCore.moduleContainsFile(module, virtualFile, false)) { return; } } } } } final LocalQuickFix[] fixes = { new PyGenerateRequirementsFileQuickFix(module), new IgnoreRequirementFix(Collections.singleton(packageName))}; registerProblem(packageReferenceExpression, PyPsiBundle.message("INSP.requirements.package.containing.module.not.listed.in.project.requirements", packageName), ProblemHighlightType.WEAK_WARNING, null, fixes); } }