-
-
Notifications
You must be signed in to change notification settings - Fork 587
/
Copy pathmkstdlibs.py
executable file
·61 lines (49 loc) · 1.55 KB
/
mkstdlibs.py
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
#!/usr/bin/env python3
import re
from stdlibs import py38, py39, py310, py311, py312, py313
URL = "https://docs.python.org/{}/objects.inv"
PATH = "isort/stdlibs/py{}.py"
VERSIONS = [
py38,
py39,
py310,
py311,
py312,
py313,
]
DOCSTRING = """
File contains the standard library of Python {}.
DO NOT EDIT. If the standard library changes, a new list should be created
using the mkstdlibs.py script.
"""
class FakeConfig:
intersphinx_timeout = None
tls_verify = True
user_agent = ""
tls_cacerts = None
class FakeApp:
srcdir = ""
config = FakeConfig()
for version_module in VERSIONS:
version_match = re.match(
r"^stdlibs\.py(?P<major>\d)(?P<minor>\d+)$",
version_module.__name__,
)
version_info = (version_match.groupdict()["major"], version_match.groupdict()["minor"])
# Any modules we want to enforce across Python versions stdlib can be included in set init
modules = {"_ast", "posixpath", "ntpath", "sre_constants", "sre_parse", "sre_compile", "sre"}
modules.update(
{
module_name
for module_name in version_module.module_names
if not module_name.startswith("_")
}
)
path = PATH.format("".join(version_info))
with open(path, "w") as stdlib_file:
docstring = DOCSTRING.format(".".join(version_info))
stdlib_file.write(f'"""{docstring}"""\n\n')
stdlib_file.write("stdlib = {\n")
for module in sorted(modules):
stdlib_file.write(f' "{module}",\n')
stdlib_file.write("}\n")