Skip to content

Commit 16f0482

Browse files
committed
Update PIP using built-in PIP
1 parent 7cdcde3 commit 16f0482

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

pioinstaller/penv.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def create_core_penv(penv_dir=None, ignore_pythons=None):
6969
get_penv_bin_dir(penv_dir), "python.exe" if util.IS_WINDOWS else "python"
7070
)
7171
init_state(python_exe, penv_dir)
72-
install_pip(python_exe, penv_dir)
72+
update_pip(python_exe, penv_dir)
7373
click.echo("Virtual environment has been successfully created!")
7474
return result_dir
7575

@@ -107,7 +107,7 @@ def create_with_local_venv(python_exe, penv_dir):
107107
util.safe_remove_dir(penv_dir)
108108
log.debug("Creating virtual environment: %s", " ".join(command))
109109
try:
110-
subprocess.check_output(command, stderr=subprocess.PIPE)
110+
subprocess.run(command, check=True)
111111
return penv_dir
112112
except Exception as e: # pylint:disable=broad-except
113113
last_error = e
@@ -128,7 +128,7 @@ def create_with_remote_venv(python_exe, penv_dir):
128128
raise exception.PIOInstallerException("Could not find virtualenv script")
129129
command = [python_exe, venv_script_path, penv_dir]
130130
log.debug("Creating virtual environment: %s", " ".join(command))
131-
subprocess.check_output(command, stderr=subprocess.PIPE)
131+
subprocess.run(command, check=True)
132132
return penv_dir
133133

134134

@@ -178,26 +178,36 @@ def save_state(state, penv_dir=None):
178178
return state_path
179179

180180

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")
183183
try:
184184
log.debug("Creating pip.conf file in %s", penv_dir)
185185
with open(os.path.join(penv_dir, "pip.conf"), "w") as fp:
186186
fp.write("\n".join(["[global]", "user=no"]))
187187

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)
193205

194-
log.debug("Installing pip")
195-
subprocess.check_output([python_exe, get_pip_path], stderr=subprocess.PIPE)
196206
click.echo("PIP has been successfully updated!")
197207
return True
198208
except Exception as e: # pylint:disable=broad-except
199209
log.debug(
200-
"Could not install pip. Error: %s",
210+
"Could not install PIP. Error: %s",
201211
str(e),
202212
)
203213
return False

0 commit comments

Comments
 (0)