25
25
from serializer import symbols_merger , symbols
26
26
27
27
STDLIB_PATH = "../resources/typeshed/stdlib"
28
+ STUBS_PATH = "../resources/typeshed/stubs"
28
29
CURRENT_PATH = os .path .dirname (__file__ )
30
+ THIRD_PARTIES_STUBS = os .listdir (os .path .join (CURRENT_PATH , STUBS_PATH ))
29
31
30
32
31
33
def get_options (python_version = (3 , 8 )):
@@ -60,13 +62,34 @@ def load_single_module(module_fqn: str, category="stdlib"):
60
62
61
63
62
64
def walk_typeshed_stdlib (opt : options .Options = get_options ()):
63
- source_list = []
64
65
generate_python2_stdlib = opt .python_version < (3 , 0 )
65
66
relative_path = STDLIB_PATH if not generate_python2_stdlib else f"{ STDLIB_PATH } /@python2"
67
+ source_list , source_paths = get_sources (relative_path , generate_python2_stdlib )
68
+ build_result = build .build (source_list , opt )
69
+ return build_result , source_paths
70
+
71
+
72
+ def walk_typeshed_third_parties (opt : options .Options = get_options ()):
73
+ source_list = []
74
+ source_paths = set ()
75
+ generate_python2 = opt .python_version < (3 , 0 )
76
+ for third_party_stub in THIRD_PARTIES_STUBS :
77
+ stub_path = os .path .join (STUBS_PATH , third_party_stub )
78
+ relative_path = stub_path if not generate_python2 else f"{ stub_path } /@python2"
79
+ src_list , src_paths = get_sources (relative_path , generate_python2 )
80
+ source_list .extend (src_list )
81
+ source_paths = source_paths .union (src_paths )
82
+ build_result = build .build (source_list , opt )
83
+ return build_result , source_paths
84
+
85
+
86
+ def get_sources (relative_path : str , generate_python2 : bool ):
87
+ source_list = []
88
+ source_paths = set ()
66
89
path = os .path .join (CURRENT_PATH , relative_path )
67
90
for root , dirs , files in os .walk (path ):
68
91
package_name = root .replace (path , "" ).replace ("\\ " , "." ).replace ("/" , "." ).lstrip ("." )
69
- if not generate_python2_stdlib and "python2" in package_name :
92
+ if not generate_python2 and "python2" in package_name :
70
93
# Avoid python2 stubs
71
94
continue
72
95
for file in files :
@@ -80,8 +103,8 @@ def walk_typeshed_stdlib(opt: options.Options = get_options()):
80
103
file_path = f"{ root } /{ file } "
81
104
source = build .BuildSource (file_path , module = fq_module_name )
82
105
source_list .append (source )
83
- build_result = build . build ( source_list , opt )
84
- return build_result
106
+ source_paths . add ( source . path )
107
+ return source_list , source_paths
85
108
86
109
87
110
def serialize_typeshed_stdlib (output_dir_name = "output" , python_version = (3 , 8 ), is_debug = False ):
@@ -92,7 +115,7 @@ def serialize_typeshed_stdlib(output_dir_name="output", python_version=(3, 8), i
92
115
"""
93
116
output_dir_name = output_dir_name if python_version >= (3 , 0 ) else f"{ output_dir_name } @python2"
94
117
opt = get_options (python_version )
95
- build_result = walk_typeshed_stdlib (opt )
118
+ build_result , _ = walk_typeshed_stdlib (opt )
96
119
for file in build_result .files :
97
120
module_symbol = symbols .ModuleSymbol (build_result .files .get (file ))
98
121
symbols .save_module (module_symbol , is_debug = is_debug , debug_dir = output_dir_name )
@@ -105,14 +128,15 @@ def serialize_typeshed_stdlib_multiple_python_version():
105
128
serialize_typeshed_stdlib (f"output3{ minor } " , (3 , minor ), is_debug = True )
106
129
107
130
108
- def save_merged_symbols (is_debug = False ):
109
- merged_modules = symbols_merger .merge_multiple_python_versions ()
131
+ def save_merged_symbols (is_debug = False , is_third_parties = False ):
132
+ merged_modules = symbols_merger .merge_multiple_python_versions (is_third_parties )
110
133
for mod in merged_modules :
111
- symbols .save_module (merged_modules [mod ], is_debug = is_debug , debug_dir = "output_merge" )
134
+ symbols .save_module (merged_modules [mod ], is_debug = is_debug , debug_dir = "output_merge" , is_stdlib = not is_third_parties )
112
135
113
136
114
137
def main ():
115
138
save_merged_symbols ()
139
+ save_merged_symbols (is_third_parties = True )
116
140
117
141
118
142
if __name__ == '__main__' :
0 commit comments