@@ -28,7 +28,6 @@ import io
2828import os
2929
3030DEFAULT_VERSION = "1.9.0"
31- DEVNULL = open (os .devnull , "w" )
3231
3332def options ():
3433 parser = argparse .ArgumentParser (add_help = False )
@@ -80,7 +79,12 @@ def get_version():
8079
8180
8281def install (version : str , quiet : bool ):
83- info_out = DEVNULL if quiet else sys .stderr
82+ if quiet :
83+ info_out = subprocess .DEVNULL
84+ info = lambda * args : None
85+ else :
86+ info_out = sys .stderr
87+ info = lambda * args : print (* args , file = sys .stderr )
8488 url = url_template .format (version = version )
8589 if install_dir .exists ():
8690 shutil .rmtree (install_dir )
@@ -89,20 +93,20 @@ def install(version: str, quiet: bool):
8993 if ripunzip is None and platform .system () == "Windows" and windows_ripunzip .exists ():
9094 ripunzip = windows_ripunzip
9195 if ripunzip :
92- print (f"downloading and extracting { url } using ripunzip" , file = info_out )
96+ info (f"downloading and extracting { url } using ripunzip" )
9397 subprocess .run ([ripunzip , "unzip-uri" , url ], stdout = info_out , stderr = info_out , cwd = install_dir ,
9498 check = True )
9599 return
96100 with io .BytesIO () as buffer :
97- print (f"downloading { url } " , file = info_out )
101+ info (f"downloading { url } " )
98102 with urllib .request .urlopen (url ) as response :
99103 while True :
100104 bytes = response .read ()
101105 if not bytes :
102106 break
103107 buffer .write (bytes )
104108 buffer .seek (0 )
105- print (f"extracting kotlin-compiler-{ version } .zip" , file = info_out )
109+ info (f"extracting kotlin-compiler-{ version } .zip" )
106110 with ZipFilePreservingPermissions (buffer ) as archive :
107111 archive .extractall (install_dir )
108112
0 commit comments