@@ -69,7 +69,7 @@ def create_core_penv(penv_dir=None, ignore_pythons=None):
69
69
get_penv_bin_dir (penv_dir ), "python.exe" if util .IS_WINDOWS else "python"
70
70
)
71
71
init_state (python_exe , penv_dir )
72
- install_pip (python_exe , penv_dir )
72
+ update_pip (python_exe , penv_dir )
73
73
click .echo ("Virtual environment has been successfully created!" )
74
74
return result_dir
75
75
@@ -107,7 +107,7 @@ def create_with_local_venv(python_exe, penv_dir):
107
107
util .safe_remove_dir (penv_dir )
108
108
log .debug ("Creating virtual environment: %s" , " " .join (command ))
109
109
try :
110
- subprocess .check_output (command , stderr = subprocess . PIPE )
110
+ subprocess .run (command , check = True )
111
111
return penv_dir
112
112
except Exception as e : # pylint:disable=broad-except
113
113
last_error = e
@@ -128,7 +128,7 @@ def create_with_remote_venv(python_exe, penv_dir):
128
128
raise exception .PIOInstallerException ("Could not find virtualenv script" )
129
129
command = [python_exe , venv_script_path , penv_dir ]
130
130
log .debug ("Creating virtual environment: %s" , " " .join (command ))
131
- subprocess .check_output (command , stderr = subprocess . PIPE )
131
+ subprocess .run (command , check = True )
132
132
return penv_dir
133
133
134
134
@@ -178,26 +178,36 @@ def save_state(state, penv_dir=None):
178
178
return state_path
179
179
180
180
181
- def install_pip (python_exe , penv_dir ):
182
- click .echo ("Updating Python package manager (PIP) in a virtual environment" )
181
+ def update_pip (python_exe , penv_dir ):
182
+ click .echo ("Updating Python package manager (PIP) in the virtual environment" )
183
183
try :
184
184
log .debug ("Creating pip.conf file in %s" , penv_dir )
185
185
with open (os .path .join (penv_dir , "pip.conf" ), "w" ) as fp :
186
186
fp .write ("\n " .join (["[global]" , "user=no" ]))
187
187
188
- log .debug ("Downloading 'get-pip.py' installer..." )
189
- get_pip_path = os .path .join (
190
- os .path .dirname (penv_dir ), ".cache" , "tmp" , os .path .basename (PIP_URL )
191
- )
192
- util .download_file (PIP_URL , get_pip_path )
188
+ try :
189
+ log .debug ("Updating PIP ..." )
190
+ subprocess .run (
191
+ [python_exe , "-m" , "pip" , "install" , "-U" , "pip" ], check = True
192
+ )
193
+ except subprocess .CalledProcessError as e :
194
+ log .debug (
195
+ "Could not update PIP. Error: %s" ,
196
+ str (e ),
197
+ )
198
+ log .debug ("Downloading 'get-pip.py' installer..." )
199
+ get_pip_path = os .path .join (
200
+ os .path .dirname (penv_dir ), ".cache" , "tmp" , os .path .basename (PIP_URL )
201
+ )
202
+ util .download_file (PIP_URL , get_pip_path )
203
+ log .debug ("Installing PIP ..." )
204
+ subprocess .run ([python_exe , get_pip_path ], check = True )
193
205
194
- log .debug ("Installing pip" )
195
- subprocess .check_output ([python_exe , get_pip_path ], stderr = subprocess .PIPE )
196
206
click .echo ("PIP has been successfully updated!" )
197
207
return True
198
208
except Exception as e : # pylint:disable=broad-except
199
209
log .debug (
200
- "Could not install pip . Error: %s" ,
210
+ "Could not install PIP . Error: %s" ,
201
211
str (e ),
202
212
)
203
213
return False
0 commit comments