7
7
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
8
#
9
9
# ==-------------------------------------------------------------------------==#
10
- from argparse import ArgumentParser
10
+ from argparse import ArgumentParser , Namespace
11
11
from pathlib import Path
12
+ from typing import Dict
12
13
import sys
13
14
import yaml
14
15
15
16
16
- def load_api (hname ) :
17
+ def load_api (hname : str ) -> Dict :
17
18
p = Path (Path (__file__ ).parent , Path (hname ).with_suffix (".yml" ))
18
19
api = p .read_text (encoding = "utf-8" )
19
20
return yaml .load (api , Loader = yaml .FullLoader )
20
21
21
22
22
23
# TODO: we may need to get more sophisticated for less generic implementations.
23
24
# Does libc/src/{hname minus .h suffix}/{fname}.cpp exist?
24
- def is_implemented (hname , fname ) :
25
+ def is_implemented (hname : str , fname : str ) -> bool :
25
26
return Path (
26
- Path (__file__ ).resolve (). parent .parent .parent ,
27
+ Path (__file__ ).parent .parent .parent ,
27
28
"src" ,
28
29
hname .rstrip (".h" ),
29
30
fname + ".cpp" ,
30
31
).exists ()
31
32
32
33
33
- def print_functions (header , functions ):
34
+ def print_functions (header : str , functions : Dict ):
34
35
for key in sorted (functions .keys ()):
35
36
print (f" * - { key } " )
36
37
@@ -46,7 +47,7 @@ def print_functions(header, functions):
46
47
print (" -" )
47
48
48
49
49
- def print_header (header , api ):
50
+ def print_header (header : str , api : Dict ):
50
51
fns = f"{ header } Functions"
51
52
print (fns )
52
53
print ("=" * (len (fns )))
@@ -65,13 +66,10 @@ def print_header(header, api):
65
66
print_functions (header , api ["functions" ])
66
67
67
68
68
- def get_possible_choices ():
69
- return [p .with_suffix (".h" ).name for p in Path (__file__ ).parent .glob ("*.yml" )]
70
-
71
-
72
- def parse_args ():
69
+ def parse_args () -> Namespace :
73
70
parser = ArgumentParser ()
74
- parser .add_argument ("header_name" , choices = get_possible_choices ())
71
+ choices = [p .with_suffix (".h" ).name for p in Path (__file__ ).parent .glob ("*.yml" )]
72
+ parser .add_argument ("header_name" , choices = choices )
75
73
return parser .parse_args ()
76
74
77
75
0 commit comments