Skip to content

Commit

Permalink
Fix combining of --editable and --force flag
Browse files Browse the repository at this point in the history
The 1.3.0 version of `pipx` (with #933) introduced a but where
the `--force-reinstall` flag caused failure when also
the `--editable` flag was used - because it was adding the
`--force-reinstall` flag after `--editable` one (and `--editable`
flag expects url/path to the Python package to install to follow it.

The change fixes it by adding the `--force-reinstall` flag at the
beginning rather than at the end of arguments to avoid this
kind of problem also in case other flags might have similar problem.

Fixes: #1122
  • Loading branch information
potiuk committed Dec 2, 2023
1 parent 1349fcf commit 83b9450
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ docs/docs.md
pipx.1
.pipx_tests
/.coverage*
testdata
/testdata
!/testdata/empty_project
/.idea
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## dev

- Fix combining of --editable and --force flag

## 1.3.0

- Check whether pip module exists in shared lib before performing any actions, such as `reinstall-all`.
Expand Down
2 changes: 1 addition & 1 deletion src/pipx/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def install(
)
if force:
print(f"Installing to existing venv {venv.name!r}")
pip_args += ["--force-reinstall"]
pip_args = ["--force-reinstall"] + pip_args
else:
print(
pipx_wrap(
Expand Down
1 change: 1 addition & 0 deletions testdata/empty_project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Empty project used for testing only
Empty file.
6 changes: 6 additions & 0 deletions testdata/empty_project/empty_project/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
pass


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions testdata/empty_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
requires = [
"setuptools",
"wheel",
]

[project]
name = "empty-project"
version = "0.1.0"
description = "Empty Python Project"
authors = [{ name = "My Name", email = "[email protected]" }]
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
scripts.empty-project = "empty_project.main:cli"
13 changes: 13 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

TEST_DATA_PATH = "./testdata/test_package_specifier"

SOURCE_DIR = Path(__file__).parent.parent.resolve()


def test_help_text(monkeypatch, capsys):
mock_exit = mock.Mock(side_effect=ValueError("raised in test to exit early"))
Expand Down Expand Up @@ -285,6 +287,17 @@ def test_force_install_changes(pipx_temp_env, capsys):
assert "2022.1.7" not in captured.out


def test_force_install_changes_editable(pipx_temp_env, capsys):
empty_project_path_as_string = (SOURCE_DIR / "testdata" / "empty_project").as_posix()
assert not run_pipx_cli(["install", "--editable", empty_project_path_as_string])
captured = capsys.readouterr()
assert "empty-project" in captured.out

assert not run_pipx_cli(["install", "--editable", empty_project_path_as_string, "--force"])
captured = capsys.readouterr()
assert "Installing to existing venv 'empty-project'" in captured.out


def test_preinstall(pipx_temp_env, caplog):
assert not run_pipx_cli(["install", "--preinstall", "black", "nox"])
assert "black" in caplog.text
Expand Down

0 comments on commit 83b9450

Please sign in to comment.