Files

35 lines
944 B
Python

from typing import List
def pkg_diff(target: List[str], actual: List[str]) -> tuple[List[str], List[str]]:
"""Compute a diff between target packages and installed packages
Args:
target: The target packages
actual: The actually installed packages
Returns:
A tuple with first the missing (not installed) packages
and second the extraneous (to be uninstalled) packages
"""
removed = []
diffed_out = []
for pkg in actual:
try:
diffed_out.append(target.index(pkg))
except Exception:
removed.append(pkg)
diffed_out.reverse()
new_pkgs = []
if len(diffed_out) > 0:
curr = diffed_out.pop()
for i, pkg in enumerate(target):
if i != curr:
new_pkgs.append(pkg)
else:
if len(diffed_out) > 0:
curr = diffed_out.pop()
return (new_pkgs, removed)