66import tempfile
77import zipfile
88from pathlib import Path
9+ from tempfile import mkdtemp
910from typing import List , Set , Tuple
1011
1112from libcst import MetadataWrapper , parse_module
@@ -40,26 +41,26 @@ def download_stubs(download_folder: Path, file_filter: List[str]) -> None:
4041 )
4142
4243 # Extract the upstream pyi files
43- with tempfile . TemporaryDirectory () as temp_folder_str :
44- temp_folder = Path (temp_folder_str )
45- print (f"Created temporary directory { temp_folder } " )
46- for download in download_folder .glob ("*.whl" ):
47- print (f"Extracting file { download } " )
48- with zipfile .ZipFile (download , "r" ) as zip_ref :
49- zip_ref .extractall (temp_folder )
50-
51- # Take every pyi file from all folders and move it to "PyQt6-stubs"
52- for folder in temp_folder .glob ("*" ):
53- print (f"Scanning folder for pyi files { folder } " )
54- for extracted_file in folder .glob ("*.pyi" ):
55- if file_filter and extracted_file .stem not in file_filter :
56- print (f"Skipping file: { extracted_file } " )
57- continue
58- copy_file = SRC_DIR / extracted_file .name
59- shutil .copyfile (extracted_file , copy_file )
60- subprocess .check_call (["git" , "add" , str (copy_file )])
61-
62- add_uic_stubs (temp_folder )
44+ temp_folder_str = mkdtemp ( dir = download_folder )
45+ temp_folder = Path (temp_folder_str )
46+ print (f"Created temporary directory { temp_folder } " )
47+ for download in download_folder .glob ("*.whl" ):
48+ print (f"Extracting file { download } " )
49+ with zipfile .ZipFile (download , "r" ) as zip_ref :
50+ zip_ref .extractall (temp_folder )
51+
52+ # Take every pyi file from all folders and move it to "PyQt6-stubs"
53+ for folder in temp_folder .glob ("*" ):
54+ print (f"Scanning folder for pyi files { folder } " )
55+ for extracted_file in folder .glob ("*.pyi" ):
56+ if file_filter and extracted_file .stem not in file_filter :
57+ print (f"Skipping file: { extracted_file } " )
58+ continue
59+ copy_file = SRC_DIR / extracted_file .name
60+ shutil .copyfile (extracted_file , copy_file )
61+ subprocess .check_call (["git" , "add" , str (copy_file )])
62+
63+ add_uic_stubs (temp_folder )
6364
6465
6566def add_uic_stubs (temp_folder : Path ) -> None :
@@ -72,34 +73,35 @@ def add_uic_stubs(temp_folder: Path) -> None:
7273 Expects the temporary folder into which upstream PyQt6 was downloaded.
7374 """
7475 uic_files = temp_folder .joinpath ("PyQt6" ).joinpath ("uic" ).rglob ("*.py" )
75- with tempfile . TemporaryDirectory () as gen_stub_temp_folder :
76- options = Options (
77- pyversion = sys .version_info [:2 ],
78- no_import = False ,
79- doc_dir = "" ,
80- search_path = [],
81- interpreter = "" ,
82- parse_only = False ,
83- ignore_errors = False ,
84- include_private = False ,
85- output_dir = gen_stub_temp_folder ,
86- modules = [],
87- packages = [],
88- files = [str (file ) for file in uic_files ],
89- verbose = False ,
90- quiet = False ,
91- export_less = False ,
92- )
93- generate_stubs (options )
94- uic_path = SRC_DIR / "uic"
95- shutil .rmtree (uic_path )
96- shutil .copytree (Path (gen_stub_temp_folder ) / "PyQt6" / "uic" , uic_path )
76+ gen_stub_temp_folder = mkdtemp ( dir = temp_folder )
77+ options = Options (
78+ pyversion = sys .version_info [:2 ],
79+ no_import = False ,
80+ doc_dir = "" ,
81+ search_path = [],
82+ interpreter = "" ,
83+ parse_only = False ,
84+ ignore_errors = False ,
85+ include_private = False ,
86+ output_dir = gen_stub_temp_folder ,
87+ modules = [],
88+ packages = [],
89+ files = [str (file ) for file in uic_files ],
90+ verbose = False ,
91+ quiet = False ,
92+ export_less = False ,
93+ )
94+ generate_stubs (options )
95+ uic_path = SRC_DIR / "uic"
96+ shutil .rmtree (uic_path )
97+ shutil .copytree (Path (gen_stub_temp_folder ) / "PyQt6" / "uic" , uic_path )
9798
9899
99- if __name__ == "__main__" :
100+ def generate_stubs_from_upstream ():
101+ files = []
100102 for arg in sys .argv [1 :]:
101103 print (f"Adding file to process list: { arg } " )
102- files = sys . argv [ 1 :]
104+ files . append ( arg )
103105
104106 # Create PyQt6-stubs folder if necessary
105107 SRC_DIR .mkdir (exist_ok = True )
@@ -154,3 +156,7 @@ def add_uic_stubs(temp_folder: Path) -> None:
154156 subprocess .check_call (
155157 ["black" , "--safe" , "--quiet" , "-l 10000" , str (SRC_DIR )]
156158 )
159+
160+
161+ if __name__ == "__main__" :
162+ generate_stubs_from_upstream ()
0 commit comments