Skip to content

Commit f0486c2

Browse files
authored
Fix combining of --editable and --force flag (#1124)
* 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
1 parent 9bcd490 commit f0486c2

File tree

8 files changed

+45
-2
lines changed

8 files changed

+45
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ docs/docs.md
1717
pipx.1
1818
.pipx_tests
1919
/.coverage*
20-
testdata
20+
/testdata
21+
!/testdata/empty_project
22+
/.idea

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## dev
22

3+
- Fix combining of --editable and --force flag
4+
35
## 1.3.0
46

57
- Check whether pip module exists in shared lib before performing any actions, such as `reinstall-all`.

src/pipx/commands/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def install(
5858
)
5959
if force:
6060
print(f"Installing to existing venv {venv.name!r}")
61-
pip_args += ["--force-reinstall"]
61+
pip_args = ["--force-reinstall"] + pip_args
6262
else:
6363
print(
6464
pipx_wrap(

testdata/empty_project/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Empty project used for testing only

testdata/empty_project/empty_project/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
pass
3+
4+
5+
if __name__ == "__main__":
6+
main()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[build-system]
2+
requires = [
3+
"setuptools",
4+
"wheel",
5+
]
6+
7+
[project]
8+
name = "empty-project"
9+
version = "0.1.0"
10+
description = "Empty Python Project"
11+
authors = [{ name = "My Name", email = "[email protected]" }]
12+
requires-python = ">=3.8"
13+
classifiers = [
14+
"Programming Language :: Python :: 3 :: Only",
15+
"Programming Language :: Python :: 3.8",
16+
"Programming Language :: Python :: 3.9",
17+
"Programming Language :: Python :: 3.10",
18+
"Programming Language :: Python :: 3.11",
19+
"Programming Language :: Python :: 3.12",
20+
]
21+
scripts.empty-project = "empty_project.main:cli"

tests/test_install.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ def test_force_install_changes(pipx_temp_env, capsys):
285285
assert "2022.1.7" not in captured.out
286286

287287

288+
def test_force_install_changes_editable(pipx_temp_env, root, capsys):
289+
empty_project_path_as_string = (root / "testdata" / "empty_project").as_posix()
290+
assert not run_pipx_cli(["install", "--editable", empty_project_path_as_string])
291+
captured = capsys.readouterr()
292+
assert "empty-project" in captured.out
293+
294+
assert not run_pipx_cli(["install", "--editable", empty_project_path_as_string, "--force"])
295+
captured = capsys.readouterr()
296+
assert "Installing to existing venv 'empty-project'" in captured.out
297+
298+
288299
def test_preinstall(pipx_temp_env, caplog):
289300
assert not run_pipx_cli(["install", "--preinstall", "black", "nox"])
290301
assert "black" in caplog.text

0 commit comments

Comments
 (0)