Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1611.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`pipx reinstall`: An exception will now be raised if package is pinned. `--unpin` option is introduced to allow reinstalling pinned package
4 changes: 4 additions & 0 deletions src/pipx/commands/reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def reinstall(
verbose: bool,
force_reinstall_shared_libs: bool = False,
python_flag_passed: bool = False,
unpin: bool = False,
) -> ExitCode:
"""Returns pipx exit code."""
if not venv_dir.exists():
Expand Down Expand Up @@ -54,6 +55,9 @@ def reinstall(
else:
package_or_url = venv.main_package_name

if venv.pipx_metadata.main_package.pinned and not unpin:
raise PipxError(f"{error} Package {venv_dir} is pinned. Pass --unpin to unpin and reinstall it.")

uninstall(venv_dir, local_bin_dir, local_man_dir, verbose)

# in case legacy original dir name
Expand Down
2 changes: 2 additions & 0 deletions src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def run_pipx_command(args: argparse.Namespace, subparsers: Dict[str, argparse.Ar
python=args.python,
verbose=verbose,
python_flag_passed=python_flag_passed,
unpin=args.unpin,
)
elif args.command == "reinstall-all":
return commands.reinstall_all(
Expand Down Expand Up @@ -731,6 +732,7 @@ def _add_reinstall(subparsers, venv_completer: VenvCompleter, shared_parser: arg
parents=[shared_parser],
)
p.add_argument("package").completer = venv_completer
p.add_argument("--unpin", action="store_true", help="Unpin and reinstall the package if it is pinned.")
add_python_options(p)


Expand Down
12 changes: 12 additions & 0 deletions tests/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,15 @@ def test_reinstall_with_path(pipx_temp_env, capsys, tmp_path):
captured = capsys.readouterr()

assert "Expected the name of an installed package" in captured.err.replace("\n", " ")


def test_reinstall_pinned_package(pipx_temp_env, capsys):
assert not run_pipx_cli(["install", "black"])
assert not run_pipx_cli(["pin", "black"])
assert run_pipx_cli(["reinstall", "black"])
captured = capsys.readouterr()
assert "--unpin to unpin" in captured.err

assert not run_pipx_cli(["reinstall", "--unpin", "black"])
captured = capsys.readouterr()
assert "installed package black" in captured.out