-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_stdlib_list.py
52 lines (39 loc) · 1.48 KB
/
update_stdlib_list.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
#!/usr/bin/env python3
"""
Adapted from https://github.com/PyCQA/isort/blob/d15f36360ca381d7e7093b66922aa5a7e3b9de9c/scripts/mkstdlibs.py
Licensed under the MIT License (MIT)
Copyright (c) 2013 Timothy Edmund Crosley
https://github.com/PyCQA/isort/blob/main/LICENSE
"""
# 3rd party
from sphinx.ext.intersphinx import fetch_inventory
URL = "https://docs.python.org/{}/objects.inv"
VERSIONS = [('2', '7'), ('3', '6'), ('3', '7'), ('3', '8'), ('3', '9'), ('3', "10"), ('3', "11"), ('3', "12")]
class FakeConfig:
intersphinx_timeout = None
tls_verify = True
user_agent = ''
class FakeApp:
srcdir = ''
config = FakeConfig()
# Any modules we want to enforce across Python versions stdlib can be included in set init
all_modules = {"_ast", "posixpath", "ntpath", "sre_constants", "sre_parse", "sre_compile", "sre"}
for version_info in VERSIONS:
version = '.'.join(version_info)
url = URL.format(version)
invdata = fetch_inventory(FakeApp(), '', url)
for module in invdata["py:module"]:
root, *_ = module.split('.')
if root not in ["__future__", "__main__"]:
all_modules.add(root)
with open("dep_checker/_stdlib_list.py", 'w', encoding="UTF-8") as stdlib_file:
docstring = """
The contents of this file are generated by `update_stdlib_list.py`.
Do not edit by hand!
Rerun that script if changes are required.
"""
stdlib_file.write(f'"""{docstring}"""\n\n')
stdlib_file.write("stdlib = {\n")
for module in sorted(all_modules):
stdlib_file.write(f' "{module}",\n')
stdlib_file.write("}\n")