Debian Codegraph @

scripts/mkstdlibs.py

raw
1 #!/usr/bin/env python3
2 import re
3
4 from stdlibs import py38, py39, py310, py311, py312, py313, py314, py315
5
6 PATH = "isort/stdlibs/py{}.py"
7 VERSIONS = [
8 py38,
9 py39,
10 py310,
11 py311,
12 py312,
13 py313,
14 py314,
15 py315,
16 ]
17
18 DOCSTRING = """
19 File contains the standard library of Python {}.
20
21 DO NOT EDIT. If the standard library changes, a new list should be created
22 using the mkstdlibs.py script.
23 """
24
25
26 for version_module in VERSIONS:
27 version_match = re.match(
28 r"^stdlibs\.py(?P<major>\d)(?P<minor>\d+)$",
29 version_module.__name__,
30 )
31 version_info = (version_match.groupdict()["major"], version_match.groupdict()["minor"])
32
33 path = PATH.format("".join(version_info))
34 with open(path, "w") as stdlib_file:
35 docstring = DOCSTRING.format(".".join(version_info))
36 stdlib_file.write(f'"""{docstring}"""\n\n')
37 stdlib_file.write("stdlib = {\n")
38 for module in sorted(version_module.module_names):
39 stdlib_file.write(f' "{module}",\n')
40 stdlib_file.write("}\n")