Fix uninject removing shared dependencies from other injected packages
Summary
When multiple injected packages share a dependency in the same pipx venv,
pipx uninject could uninstall that shared dependency, even if it is still
required by other injected packages. This could break the remaining packages.
This PR makes uninject more conservative when cleaning up dependencies.
Changes
-
In
uninject_dep, after uninstalling the injected package, we still compute the set of packages that became "not required" usingvenv.list_installed_packages(not_required=True), but before uninstalling them we:- Build a set of dependencies still required by:
- the main package of the venv, and
- all other injected packages (excluding the one being uninjected).
- Only uninstall dependencies that are not in this "protected" set.
- Build a set of dependencies still required by:
-
The user-facing behaviour is unchanged when there are no shared dependencies, but shared dependencies used by other packages in the venv are now preserved.
-
Added a regression test
test_uninject_keeps_shared_dependenciesto ensure that uninjection of one injected package does not remove another injected package from the same venv. -
Added a changelog fragment describing the bugfix.
Testing
Local (Windows 11):
python -m nox -s tests-3.10 -- -k "uninject"
Result:
- All
uninject-related tests pass:- 4 passed, 1 skipped (the global test skipped on Windows).
- The
covernox session fails locally because only a subset of tests is run (global coverage 56% < fail-under=70). I expect full coverage to be validated by the CI when running the complete test suite.