-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathknown_modules.py
More file actions
174 lines (159 loc) · 4.25 KB
/
known_modules.py
File metadata and controls
174 lines (159 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""Known Python module names for fuzzy matching import suggestions.
This module provides a curated list of popular Python package import names
for suggesting corrections when a user mistypes an import statement.
Sources:
- Python standard library (typeshed/stdlib/VERSIONS)
- Top 100 PyPI packages by downloads (https://github.com/hugovk/top-pypi-packages)
Note: These are import names, not PyPI package names.
"""
from __future__ import annotations
from typing import Final
from mypy.modulefinder import StdlibVersions
POPULAR_THIRD_PARTY_MODULES: Final[frozenset[str]] = frozenset(
{
# Cloud
"boto3",
"botocore",
"aiobotocore",
"s3transfer",
"s3fs",
"awscli",
# HTTP / Networking
"urllib3",
"requests",
"certifi",
"idna",
"charset_normalizer",
"httpx",
"httpcore",
"aiohttp",
"yarl",
"multidict",
"requests_oauthlib",
"oauthlib",
"h11",
# Typing / Extensions
"typing_extensions",
"annotated_types",
"typing_inspection",
# Core Utilities
"setuptools",
"packaging",
"pip",
"wheel",
"virtualenv",
"platformdirs",
"filelock",
"zipp",
"importlib_metadata",
# Data Science / Numerical
"numpy",
"pandas",
"scipy",
"pyarrow",
# Serialization / Config
"yaml",
"pydantic",
"pydantic_core",
"attrs",
"tomli",
"jsonschema",
"jsonschema_specifications",
"jmespath",
# Cryptography / Security
"cryptography",
"cffi",
"pycparser",
"rsa",
"pyjwt",
"pyasn1",
"pyasn1_modules",
# Date / Time
"dateutil",
"pytz",
"tzdata",
# Google / gRPC
"google",
"grpc",
"grpc_status",
"grpc_tools",
"protobuf",
"googleapis_common_protos",
# Testing
"pytest",
"pluggy",
"iniconfig",
# CLI / Terminal
"click",
"colorama",
"rich",
"tqdm",
# Web Frameworks
"starlette",
# Templates / Markup
"jinja2",
"markupsafe",
"pygments",
"markdown_it",
"mdurl",
# Async
"anyio",
"greenlet",
"aiosignal",
"aiohappyeyeballs",
"frozenlist",
# Database
"sqlalchemy",
# Parsing / XML
"pyparsing",
"et_xmlfile",
# OpenTelemetry
"opentelemetry",
# Other Popular Modules
"six",
"fsspec",
"wrapt",
"propcache",
"rpds",
"pathspec",
"PIL",
"psutil",
"referencing",
"trove_classifiers",
"openpyxl",
"dotenv",
"yandexcloud",
"cachetools",
}
)
_known_modules_cache: frozenset[str] | None = None
def reset_known_modules_cache() -> None:
global _known_modules_cache
_known_modules_cache = None
def get_stdlib_modules(
stdlib_versions: StdlibVersions, python_version: tuple[int, int] | None = None
) -> frozenset[str]:
modules: set[str] = set()
for module, (min_ver, max_ver) in stdlib_versions.items():
if python_version is not None:
if python_version < min_ver:
continue
if max_ver is not None and python_version > max_ver:
continue
top_level = module.split(".")[0]
# Skip private and very short modules to avoid false positives and noise
if top_level.startswith("_") or len(top_level) <= 2:
continue
modules.add(top_level)
return frozenset(modules)
def get_known_modules(
stdlib_versions: StdlibVersions | None = None, python_version: tuple[int, int] | None = None
) -> frozenset[str]:
global _known_modules_cache
if _known_modules_cache is not None:
return _known_modules_cache
modules: set[str] = set(POPULAR_THIRD_PARTY_MODULES)
if stdlib_versions is not None:
modules = modules.union(get_stdlib_modules(stdlib_versions, python_version))
_known_modules_cache = frozenset(modules)
return _known_modules_cache