Commit 10957d5a by David Hotham Committed by Bjorn Neergaard

Don't uninstall packages that should be kept

parent 196d6660
...@@ -74,6 +74,7 @@ class Transaction: ...@@ -74,6 +74,7 @@ class Transaction:
operations.append(Install(result_package, priority=priority)) operations.append(Install(result_package, priority=priority))
if with_uninstalls: if with_uninstalls:
uninstalls: set[str] = set()
for current_package in self._current_packages: for current_package in self._current_packages:
found = any( found = any(
current_package.name == result_package.name current_package.name == result_package.name
...@@ -83,11 +84,12 @@ class Transaction: ...@@ -83,11 +84,12 @@ class Transaction:
if not found: if not found:
for installed_package in self._installed_packages: for installed_package in self._installed_packages:
if installed_package.name == current_package.name: if installed_package.name == current_package.name:
uninstalls.add(installed_package.name)
operations.append(Uninstall(current_package)) operations.append(Uninstall(current_package))
if synchronize: if synchronize:
current_package_names = { result_package_names = {
current_package.name for current_package in self._current_packages result_package.name for result_package, _ in self._result_packages
} }
# We preserve pip/setuptools/wheel when not managed by poetry, this is # We preserve pip/setuptools/wheel when not managed by poetry, this is
# done to avoid externally managed virtual environments causing # done to avoid externally managed virtual environments causing
...@@ -96,9 +98,12 @@ class Transaction: ...@@ -96,9 +98,12 @@ class Transaction:
"pip", "pip",
"setuptools", "setuptools",
"wheel", "wheel",
} - current_package_names } - result_package_names
for installed_package in self._installed_packages: for installed_package in self._installed_packages:
if installed_package.name in uninstalls:
continue
if ( if (
self._root_package self._root_package
and installed_package.name == self._root_package.name and installed_package.name == self._root_package.name
...@@ -108,7 +113,8 @@ class Transaction: ...@@ -108,7 +113,8 @@ class Transaction:
if installed_package.name in preserved_package_names: if installed_package.name in preserved_package_names:
continue continue
if installed_package.name not in current_package_names: if installed_package.name not in result_package_names:
uninstalls.add(installed_package.name)
operations.append(Uninstall(installed_package)) operations.append(Uninstall(installed_package))
return sorted( return sorted(
......
...@@ -121,6 +121,31 @@ def test_it_should_remove_installed_packages_if_required(): ...@@ -121,6 +121,31 @@ def test_it_should_remove_installed_packages_if_required():
) )
def test_it_should_not_remove_installed_packages_that_are_in_result():
transaction = Transaction(
[],
[
(Package("a", "1.0.0"), 1),
(Package("b", "2.0.0"), 2),
(Package("c", "3.0.0"), 0),
],
installed_packages=[
Package("a", "1.0.0"),
Package("b", "2.0.0"),
Package("c", "3.0.0"),
],
)
check_operations(
transaction.calculate_operations(synchronize=True),
[
{"job": "install", "package": Package("a", "1.0.0"), "skipped": True},
{"job": "install", "package": Package("b", "2.0.0"), "skipped": True},
{"job": "install", "package": Package("c", "3.0.0"), "skipped": True},
],
)
def test_it_should_update_installed_packages_if_sources_are_different(): def test_it_should_update_installed_packages_if_sources_are_different():
transaction = Transaction( transaction = Transaction(
[Package("a", "1.0.0")], [Package("a", "1.0.0")],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment