Skip to content

Commit 96a0a06

Browse files
author
Chad Smith
authored
remove venv if any exception occurs (#194)
1 parent f1adeba commit 96a0a06

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pipx: execute binaries from Python packages in isolated environments
2222
<a href="https://travis-ci.org/pipxproject/pipx"><img src="https://travis-ci.org/pipxproject/pipx.svg?branch=master" /></a>
2323

2424
<a href="https://pypi.python.org/pypi/pipx/">
25-
<img src="https://img.shields.io/badge/pypi-0.13.2.0-blue.svg" /></a>
25+
<img src="https://img.shields.io/badge/pypi-0.13.2.1-blue.svg" /></a>
2626
<a href="https://github.com/ambv/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
2727
</p>
2828

automation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
@nox.session(python=["3.6", "3.7"])
88
def develop(session):
9-
session.install("-e", ".", ".[dev]", ".[docs]")
9+
session.install(".[dev]", ".[docs]")
10+
session.install("-e", ".")
1011

1112

1213
@nox.session(python=python)

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.13.2.1
2+
- Remove virtual environment if installation did not complete (#193)
3+
14
0.13.2.0
25
- Add shell autocompletions. Also add `pipx completions` command to print instructions on how to add pipx completions to your shell.
36
- Un-deprecate `ensurepath`. Use `userpath` internally instead of instructing users to run the `userpath` cli command.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ See Contributing for how to update this file.
1919
<a href="https://travis-ci.org/pipxproject/pipx"><img src="https://travis-ci.org/pipxproject/pipx.svg?branch=master" /></a>
2020

2121
<a href="https://pypi.python.org/pypi/pipx/">
22-
<img src="https://img.shields.io/badge/pypi-0.13.2.0-blue.svg" /></a>
22+
<img src="https://img.shields.io/badge/pypi-0.13.2.1-blue.svg" /></a>
2323
<a href="https://github.com/ambv/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
2424
</p>
2525

pipx/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ def stylize_text(x):
2929

3030
bold = mkcolorfunc(c.bold)
3131
red = mkcolorfunc(c.red)
32-
cyan = mkcolorfunc(c.cyan)
32+
blue = mkcolorfunc(c.cyan)
33+
cyan = mkcolorfunc(c.blue)
3334
green = mkcolorfunc(c.green)

pipx/commands.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,23 +307,24 @@ def install(
307307
print(
308308
f"{package!r} already seems to be installed. "
309309
f"Not modifying existing installation in {str(venv_dir)!r}. "
310-
"Pass '--force' to force installation"
310+
"Pass '--force' to force installation."
311311
)
312312
return
313313

314314
venv = Venv(venv_dir, python=python, verbose=verbose)
315-
venv.create_venv(venv_args, pip_args)
316315
try:
316+
venv.create_venv(venv_args, pip_args)
317317
venv.install_package(package_or_url, pip_args)
318-
except PipxError:
319-
venv.remove_venv()
320-
raise
321318

322-
if venv.get_venv_metadata_for_package(package).package_version is None:
323-
venv.remove_venv()
324-
raise PipxError(f"Could not find package {package}. Is the name correct?")
319+
if venv.get_venv_metadata_for_package(package).package_version is None:
320+
venv.remove_venv()
321+
raise PipxError(f"Could not find package {package}. Is the name correct?")
325322

326-
_run_post_install_actions(venv, package, local_bin_dir, venv_dir, include_deps)
323+
_run_post_install_actions(venv, package, local_bin_dir, venv_dir, include_deps)
324+
except (Exception, KeyboardInterrupt):
325+
print("")
326+
venv.remove_venv()
327+
raise
327328

328329

329330
def _run_post_install_actions(

pipx/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
mkdir,
3131
autocomplete_list_of_installed_packages as _autocomplete_list_of_installed_packages,
3232
)
33+
from .colors import bold, green
3334

34-
__version__ = "0.13.2.0"
35+
__version__ = "0.13.2.1"
3536

3637

3738
def print_version() -> None:
@@ -484,9 +485,10 @@ def setup(args):
484485
exit(0)
485486

486487
if "verbose" in args and args.verbose:
487-
logging.basicConfig(
488-
level=logging.DEBUG, format="pipx (%(funcName)s:%(lineno)d): %(message)s"
489-
)
488+
pipx_str = bold(green("pipx >")) if sys.stdout.isatty() else "pipx >"
489+
format_str = f"{pipx_str} (%(funcName)s:%(lineno)d): %(message)s"
490+
491+
logging.basicConfig(level=logging.DEBUG, format=format_str)
490492
else:
491493
logging.basicConfig(level=logging.WARNING, format="%(message)s")
492494

0 commit comments

Comments
 (0)