@@ -28,7 +28,7 @@ import io
2828import os
2929
3030DEFAULT_VERSION = "1.9.0"
31-
31+ DEVNULL = open ( os . devnull , "w" )
3232
3333def options ():
3434 parser = argparse .ArgumentParser (add_help = False )
@@ -79,7 +79,8 @@ def get_version():
7979 return None
8080
8181
82- def install (version : str ):
82+ def install (version : str , quiet : bool ):
83+ info_out = DEVNULL if quiet else sys .stderr
8384 url = url_template .format (version = version )
8485 if install_dir .exists ():
8586 shutil .rmtree (install_dir )
@@ -88,19 +89,20 @@ def install(version: str):
8889 if ripunzip is None and platform .system () == "Windows" and windows_ripunzip .exists ():
8990 ripunzip = windows_ripunzip
9091 if ripunzip :
91- print (f"downloading and extracting { url } using ripunzip" , file = sys .stderr )
92- subprocess .run ([ripunzip , "unzip-uri" , url ], cwd = install_dir , check = True )
92+ print (f"downloading and extracting { url } using ripunzip" , file = info_out )
93+ subprocess .run ([ripunzip , "unzip-uri" , url ], stdout = info_out , stderr = info_out , cwd = install_dir ,
94+ check = True )
9395 return
9496 with io .BytesIO () as buffer :
95- print (f"downloading { url } " , file = sys . stderr )
97+ print (f"downloading { url } " , file = info_out )
9698 with urllib .request .urlopen (url ) as response :
9799 while True :
98100 bytes = response .read ()
99101 if not bytes :
100102 break
101103 buffer .write (bytes )
102104 buffer .seek (0 )
103- print (f"extracting kotlin-compiler-{ version } .zip" , file = sys . stderr )
105+ print (f"extracting kotlin-compiler-{ version } .zip" , file = info_out )
104106 with ZipFilePreservingPermissions (buffer ) as archive :
105107 archive .extractall (install_dir )
106108
@@ -138,7 +140,8 @@ def main(opts, forwarded_opts):
138140 else :
139141 selected_version = current_version or DEFAULT_VERSION
140142 if selected_version != current_version :
141- install (selected_version )
143+ # don't print information about install procedure unless explicitly using --select
144+ install (selected_version , quiet = opts .select is None )
142145 version_file .write_text (selected_version )
143146 if opts .version or (opts .select and not forwarded_opts ):
144147 print (f"info: kotlinc-jvm { selected_version } (codeql dev wrapper)" , file = sys .stderr )
@@ -149,8 +152,8 @@ def main(opts, forwarded_opts):
149152if __name__ == "__main__" :
150153 try :
151154 main (* options ())
152- except Exception as e :
153- print (f"{ e . __class__ . __name__ } : { e } " , file = sys .stderr )
155+ except Error as e :
156+ print (f"Error : { e } " , file = sys .stderr )
154157 sys .exit (1 )
155158 except KeyboardInterrupt :
156159 sys .exit (1 )
0 commit comments