Skip to content

Commit efc044a

Browse files
EpiX-1oz123
authored andcommitted
Bugfix: Make sure ensure_python() installs Python when conditions are met
Previously, even when PIPENV_YES was set or the user confirmed the installation, the presence of an unnecessary else statement caused ensure_python() to exit early without attempting the Python installation.
1 parent c3774cc commit efc044a

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

pipenv/utils/virtualenv.py

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -326,41 +326,35 @@ def abort(msg=""):
326326
elif not project.s.PIPENV_YES:
327327
# Non-interactive session without PIPENV_YES, proceed with installation
328328
abort()
329-
else:
330-
# Tell the user we're installing Python.
331-
console.print(
332-
f"[bold]Installing [green]CPython[/green] {version} with {installer.cmd}[/bold]"
333-
)
334-
console.print("(this may take a few minutes)[bold]...[/bold]")
335-
with console.status(
336-
"Installing python...", spinner=project.s.PIPENV_SPINNER
337-
):
338-
try:
339-
c = installer.install(version)
340-
except InstallerError as e:
341-
err.print(
342-
environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed...")
343-
)
344-
err.print("Something went wrong...")
345-
err.print(f"[cyan]{e.err}[/cyan]")
346-
else:
347-
console.print(
348-
environments.PIPENV_SPINNER_OK_TEXT.format("Success!")
349-
)
350-
# Print the results, in a beautiful blue...
351-
err.print(f"[cyan]{c.stdout}[/cyan]")
352-
# Find the newly installed Python, hopefully.
353-
version = str(version)
354-
path_to_python = find_a_system_python(version)
329+
330+
# Tell the user we're installing Python.
331+
console.print(
332+
f"[bold]Installing [green]CPython[/green] {version} with {installer.cmd}[/bold]"
333+
)
334+
console.print("(this may take a few minutes)[bold]...[/bold]")
335+
with console.status("Installing python...", spinner=project.s.PIPENV_SPINNER):
355336
try:
356-
assert python_version(path_to_python) == version
357-
except AssertionError:
358-
err.print(
359-
"[bold][red]Warning:[/red][/bold]"
360-
" The Python you just installed is not available "
361-
"on your [bold]PATH[/bold], apparently."
362-
)
363-
sys.exit(1)
337+
c = installer.install(version)
338+
except InstallerError as e:
339+
err.print(environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed..."))
340+
err.print("Something went wrong...")
341+
err.print(f"[cyan]{e.err}[/cyan]")
342+
else:
343+
console.print(environments.PIPENV_SPINNER_OK_TEXT.format("Success!"))
344+
# Print the results, in a beautiful blue...
345+
err.print(f"[cyan]{c.stdout}[/cyan]")
346+
# Find the newly installed Python, hopefully.
347+
version = str(version)
348+
path_to_python = find_a_system_python(version)
349+
try:
350+
assert python_version(path_to_python) == version
351+
except AssertionError:
352+
err.print(
353+
"[bold][red]Warning:[/red][/bold]"
354+
" The Python you just installed is not available "
355+
"on your [bold]PATH[/bold], apparently."
356+
)
357+
sys.exit(1)
364358
return path_to_python
365359

366360

0 commit comments

Comments
 (0)