@@ -28,7 +28,6 @@ import io
28
28
import os
29
29
30
30
DEFAULT_VERSION = "1.9.0"
31
- DEVNULL = open (os .devnull , "w" )
32
31
33
32
def options ():
34
33
parser = argparse .ArgumentParser (add_help = False )
@@ -80,7 +79,12 @@ def get_version():
80
79
81
80
82
81
def 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 )
84
88
url = url_template .format (version = version )
85
89
if install_dir .exists ():
86
90
shutil .rmtree (install_dir )
@@ -89,20 +93,20 @@ def install(version: str, quiet: bool):
89
93
if ripunzip is None and platform .system () == "Windows" and windows_ripunzip .exists ():
90
94
ripunzip = windows_ripunzip
91
95
if ripunzip :
92
- print (f"downloading and extracting { url } using ripunzip" , file = info_out )
96
+ info (f"downloading and extracting { url } using ripunzip" )
93
97
subprocess .run ([ripunzip , "unzip-uri" , url ], stdout = info_out , stderr = info_out , cwd = install_dir ,
94
98
check = True )
95
99
return
96
100
with io .BytesIO () as buffer :
97
- print (f"downloading { url } " , file = info_out )
101
+ info (f"downloading { url } " )
98
102
with urllib .request .urlopen (url ) as response :
99
103
while True :
100
104
bytes = response .read ()
101
105
if not bytes :
102
106
break
103
107
buffer .write (bytes )
104
108
buffer .seek (0 )
105
- print (f"extracting kotlin-compiler-{ version } .zip" , file = info_out )
109
+ info (f"extracting kotlin-compiler-{ version } .zip" )
106
110
with ZipFilePreservingPermissions (buffer ) as archive :
107
111
archive .extractall (install_dir )
108
112
0 commit comments