PY-72443 fix module => package mapping for some of the popular ml libs

GitOrigin-RevId: 962d57b87333c8c196dbd52bcfd4b5a41ba7317b
This commit is contained in:
Vladimir Koshelev
2024-05-03 12:27:42 +02:00
committed by intellij-monorepo-bot
parent dfc0946c45
commit 8754f98cbe
8 changed files with 155 additions and 21 deletions

View File

@@ -4773,10 +4773,11 @@ bson pymongo
dotenv python-dotenv
avro avro-python3
modeltranslation django-modeltranslation
torch torch-nightly
can python-can
github PyGithub
gitlab python-gitlab
tensorflow tensorflow-gpu
aocd advent-of-code-data
slugify python-slugify
slugify python-slugify
huggingface_hub huggingface-hub
tensorflow_text tensorflow-text
tensorflow_graphics tensorflow-graphics

View File

@@ -17,8 +17,7 @@ object PyPsiPackageUtil {
/**
* Contains mapping "importable top-level package" -> "package names on PyPI".
*/
@JvmField
val PACKAGES_TOPLEVEL: Map<String, String> = loadPackageAliases()
private val PACKAGES_TOPLEVEL: Map<String, String> = loadPackageAliases()
@JvmStatic
fun findPackage(packages: List<PyPackage>, name: String): PyPackage? {
@@ -31,8 +30,8 @@ object PyPsiPackageUtil {
return null
}
fun moduleToPackageName(module: String): String {
return PACKAGES_TOPLEVEL.getOrDefault(module, module)
fun moduleToPackageName(module: String, default: String = module): String {
return PACKAGES_TOPLEVEL.getOrDefault(module, default)
}
private fun loadPackageAliases(): Map<String, String> {

View File

@@ -100,7 +100,7 @@ object PyTypeShed {
return true
}
val possiblePackage = name.firstComponent ?: return false
val alternativePossiblePackages = PyPsiPackageUtil.PACKAGES_TOPLEVEL[possiblePackage] ?: ""
val alternativePossiblePackages = PyPsiPackageUtil.moduleToPackageName(possiblePackage, default = "")
val packageManager = PyPackageManagers.getInstance().forSdk(sdk)
val installedPackages = if (ApplicationManager.getApplication().isHeadlessEnvironment && !PlatformUtils.isFleetBackend()) {