Skip to content

Commit

Permalink
Fix combining of --editable and --force flag (#1124)
Browse files Browse the repository at this point in the history
* Fix combining of `--editable` and `--force` flag

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

* fixup! Fix combining of `--editable` and `--force` flag
  • Loading branch information
potiuk authored Dec 2, 2023
1 parent 9bcd490 commit f0486c2
Show file tree
Hide file tree
Showing 8 changed files with 45 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()
21 changes: 21 additions & 0 deletions testdata/empty_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[build-system]
requires = [
"setuptools",
"wheel",
]

[project]
name = "empty-project"
version = "0.1.0"
description = "Empty Python Project"
authors = [{ name = "My Name", email = "me@example.com" }]
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
scripts.empty-project = "empty_project.main:cli"
11 changes: 11 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,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, root, capsys):
empty_project_path_as_string = (root / "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 f0486c2

Please sign in to comment.