diff --git a/.gitignore b/.gitignore index 8233c4d398..fbc7e56f46 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ docs/docs.md pipx.1 .pipx_tests /.coverage* -testdata +/testdata +!/testdata/empty_project +/.idea diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c43662f80..5ee639dae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/src/pipx/commands/install.py b/src/pipx/commands/install.py index 2f51b9d663..66cfac1f14 100644 --- a/src/pipx/commands/install.py +++ b/src/pipx/commands/install.py @@ -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( diff --git a/testdata/empty_project/README.md b/testdata/empty_project/README.md new file mode 100644 index 0000000000..90b452a4d9 --- /dev/null +++ b/testdata/empty_project/README.md @@ -0,0 +1 @@ +Empty project used for testing only diff --git a/testdata/empty_project/empty_project.egg-info/PKG-INFO b/testdata/empty_project/empty_project.egg-info/PKG-INFO new file mode 100644 index 0000000000..e280426a26 --- /dev/null +++ b/testdata/empty_project/empty_project.egg-info/PKG-INFO @@ -0,0 +1,6 @@ +Metadata-Version: 2.1 +Name: empty-project +Version: 0.1.0 +Summary: Empty Python Project +Author-email: My Name +Requires-Python: >=3.11 diff --git a/testdata/empty_project/empty_project.egg-info/SOURCES.txt b/testdata/empty_project/empty_project.egg-info/SOURCES.txt new file mode 100644 index 0000000000..5b69222f8f --- /dev/null +++ b/testdata/empty_project/empty_project.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +README.md +pyproject.toml +empty_project/__init__.py +empty_project/main.py +empty_project.egg-info/PKG-INFO +empty_project.egg-info/SOURCES.txt +empty_project.egg-info/dependency_links.txt +empty_project.egg-info/entry_points.txt +empty_project.egg-info/top_level.txt diff --git a/testdata/empty_project/empty_project.egg-info/dependency_links.txt b/testdata/empty_project/empty_project.egg-info/dependency_links.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testdata/empty_project/empty_project.egg-info/entry_points.txt b/testdata/empty_project/empty_project.egg-info/entry_points.txt new file mode 100644 index 0000000000..241d78952e --- /dev/null +++ b/testdata/empty_project/empty_project.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +empty-project = empty_project.main:cli diff --git a/testdata/empty_project/empty_project.egg-info/top_level.txt b/testdata/empty_project/empty_project.egg-info/top_level.txt new file mode 100644 index 0000000000..d0f95c92ed --- /dev/null +++ b/testdata/empty_project/empty_project.egg-info/top_level.txt @@ -0,0 +1 @@ +empty_project diff --git a/testdata/empty_project/empty_project/__init__.py b/testdata/empty_project/empty_project/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testdata/empty_project/empty_project/main.py b/testdata/empty_project/empty_project/main.py new file mode 100644 index 0000000000..cd9ac48059 --- /dev/null +++ b/testdata/empty_project/empty_project/main.py @@ -0,0 +1,6 @@ +def main(): + pass + + +if __name__ == "__main__": + main() diff --git a/testdata/empty_project/pyproject.toml b/testdata/empty_project/pyproject.toml new file mode 100644 index 0000000000..40a135f216 --- /dev/null +++ b/testdata/empty_project/pyproject.toml @@ -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 = "me@example.com" }] +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" diff --git a/tests/test_install.py b/tests/test_install.py index 1ece9bdc4f..939e00a382 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -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")) @@ -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