-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate-cindex
executable file
·40 lines (28 loc) · 1.06 KB
/
generate-cindex
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
#!/usr/bin/env python3
"""This script generates ``cindex.pyi`` from ``clang.cindex``."""
import argparse
import sys
import typing
from clang import cindex
import generate_common
class Context(typing.NamedTuple):
output: typing.TextIO
@classmethod
def from_args(cls) -> 'Context':
p = argparse.ArgumentParser()
p.add_argument('--output', '-o', type=str, default='types-clang/clang-stubs/cindex.pyi')
args = p.parse_args()
return cls(output=sys.stdout if args.output == '-' else open(args.output, 'w+'))
def __enter__(self) -> 'Context':
return self
def __exit__(self, exc_type, exc_value, exc_trace) -> None:
if self.output != sys.stdout:
self.output.close()
def main() -> None:
env = generate_common.create_jinja_env('../../templates/types-clang')
with Context.from_args() as context:
template = env.get_template('cindex.pyi.jinja2')
context.output.write(template.render(cindex=cindex))
context.output.write('\n')
if __name__ == '__main__':
sys.exit(main())