forked from wearepal/data-science-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_pyi.py
27 lines (20 loc) · 857 Bytes
/
gen_pyi.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
"""Generate pyi files from pyi.in files"""
from pathlib import Path
import json
from tools.code_template import CodeTemplate
WARNING_STR = """# ========================================================= #
# This file has been generated automatically!!!!
# DO NOT EDIT IT!
# ========================================================= #
"""
def main() -> None:
variables_path = Path(".") / "matplotlib-stubs" / "shared.json"
pattern_path = Path(".") / "matplotlib-stubs" / "pyplot.pyi.in"
output_path = Path(".") / "matplotlib-stubs" / "pyplot.pyi"
generator = CodeTemplate.from_file(pattern_path)
with variables_path.open("r") as fp:
variables = json.load(fp)
with output_path.open("w") as fp:
fp.write(WARNING_STR + generator.substitute(variables))
if __name__ == "__main__":
main()