Skip to content

Commit 255a83f

Browse files
pipx reinstall: An exception will now be raised if package is pinned (#1674)
* feat: add --unpin option to reinstall command to allow reinstalling pinned package * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix assertion message in reinstall test Updated error message assertion for reinstall test. * Remove --unpin * Update test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7ebb996 commit 255a83f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

changelog.d/1611.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`pipx reinstall`: An exception will now be raised if package is pinned.

src/pipx/commands/reinstall.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def reinstall(
5454
else:
5555
package_or_url = venv.main_package_name
5656

57+
if venv.pipx_metadata.main_package.pinned:
58+
raise PipxError(f"{error} Package {venv_dir} is pinned. Run `pipx unpin {venv_dir.name}` to unpin it first.")
59+
5760
uninstall(venv_dir, local_bin_dir, local_man_dir, verbose)
5861

5962
# in case legacy original dir name

tests/test_reinstall.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,16 @@ def test_reinstall_with_path(pipx_temp_env, capsys, tmp_path):
6868
captured = capsys.readouterr()
6969

7070
assert "Expected the name of an installed package" in captured.err.replace("\n", " ")
71+
72+
73+
def test_reinstall_pinned_package(pipx_temp_env, capsys):
74+
assert not run_pipx_cli(["install", "black"])
75+
assert not run_pipx_cli(["pin", "black"])
76+
assert run_pipx_cli(["reinstall", "black"])
77+
captured = capsys.readouterr()
78+
assert "pinned" in captured.err
79+
80+
assert not run_pipx_cli(["unpin", "black"])
81+
assert not run_pipx_cli(["reinstall", "black"])
82+
captured = capsys.readouterr()
83+
assert "installed package black" in captured.out

0 commit comments

Comments
 (0)