diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py index 2eebcfd4..b696b630 100644 --- a/pym/gentoolkit/eclean/search.py +++ b/pym/gentoolkit/eclean/search.py @@ -17,6 +17,7 @@ from portage.dep import Atom, use_reduce from portage.dep._slot_operator import strip_slots from portage.dep.libc import find_libc_deps, strip_libc_deps +from portage.exception import InvalidDependString import gentoolkit.pprinter as pp from gentoolkit.eclean.exclude import ( @@ -526,13 +527,51 @@ def _check_excludes(self, exclude, clean_me): return clean_me, saved -def _deps_equal(deps_a, eapi_a, deps_b, eapi_b, libc_deps, uselist=None): - """Compare two dependency lists given a set of USE flags""" +def _deps_equal(deps_a, eapi_a, deps_b, eapi_b, libc_deps, uselist=None, cpv=None): + """Compare two dependency lists given a set of USE flags + + @param deps_a: binpkg DEPEND string (for InvalidDependString errors) + @rtype: string + @param eapi_a: EAPI + @rtype: string + @param deps_b: ebuild DEPEND string (for InvalidDependString errors) + @rtype: string + @param eapi_b: EAPI + @rtype: string + @param libc_deps: List of libc packages (or atoms if realized is passed). + @rtype: list + @param uselist: use flag list + @rtype: frozenset + @param cpv: Cat/Pkg-version + @rtype: string + """ if deps_a == deps_b: return True + try: + deps_a = use_reduce(deps_a, uselist=uselist, eapi=eapi_a, token_class=Atom) + except InvalidDependString: # the binpkg depend string is bad + print( + pp.warn( + "Warning: Invalid binpkg DEPEND string found for: %s, %s" + " | tagging for removal" % (cpv, deps_a) + ), + file=sys.stderr, + ) + return False + try: + deps_b = use_reduce(deps_b, uselist=uselist, eapi=eapi_b, token_class=Atom) + except InvalidDependString as er: # the ebuild depend string is bad + print( + pp.warn("Warning: Invalid ebuild DEPEND String found for: %s" % cpv), + file=sys.stderr, + ) + print( + pp.warn("Warning: DEPEND string for ebuild: %s" % deps_b), + file=sys.stderr, + ) + print(er, file=sys.stderr) + return True - deps_a = use_reduce(deps_a, uselist=uselist, eapi=eapi_a, token_class=Atom) - deps_b = use_reduce(deps_b, uselist=uselist, eapi=eapi_b, token_class=Atom) strip_libc_deps(deps_a, libc_deps) strip_libc_deps(deps_b, libc_deps) strip_slots(deps_a) @@ -552,7 +591,6 @@ def findPackages( ) -> tuple[dict[str, list[str]], dict[str, list[str]]]: """Find obsolete binary packages. - @param invalid_paths: @param options: dict of options determined at runtime @type options: dict @param exclude: exclusion dict (as defined in the exclude.parseExcludeFile class) @@ -571,8 +609,8 @@ def findPackages( @param var_dbapi: defaults to portage.db[portage.root]["vartree"].dbapi Can be overridden for tests. - @return binary packages to remove. e.g. {'cat/pkg-ver': [filepath]} - @rtype: dict + @return binary packages to remove. e.g. {'cat/pkg-ver': [filepath]}, invalid_paths + @rtype: dict, dict """ if exclude is None: exclude = {} @@ -656,13 +694,16 @@ def findPackages( binpkg_metadata = dict(zip(keys, bin_dbapi.aux_get(cpv, keys))) ebuild_metadata = dict(zip(keys, port_dbapi.aux_get(cpv, keys))) + deps_binpkg = " ".join(binpkg_metadata[key] for key in dep_keys) + deps_ebuild = " ".join(ebuild_metadata[key] for key in dep_keys) if _deps_equal( - " ".join(binpkg_metadata[key] for key in dep_keys), + deps_binpkg, binpkg_metadata["EAPI"], - " ".join(ebuild_metadata[key] for key in dep_keys), + deps_ebuild, ebuild_metadata["EAPI"], libc_deps, frozenset(binpkg_metadata["USE"].split()), + cpv, ): continue diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/rebuild.py index 074e2f5c..f4a348a4 100644 --- a/pym/gentoolkit/enalyze/rebuild.py +++ b/pym/gentoolkit/enalyze/rebuild.py @@ -167,7 +167,7 @@ def __init__(self): "pretend": False, "prefix": False, "portage": True, - "slot": False + "slot": False, # "unset": False } self.module_opts = { diff --git a/pym/gentoolkit/test/eclean/test_search.py b/pym/gentoolkit/test/eclean/test_search.py index 32d360cc..0bbad46b 100755 --- a/pym/gentoolkit/test/eclean/test_search.py +++ b/pym/gentoolkit/test/eclean/test_search.py @@ -26,8 +26,11 @@ ) import gentoolkit.eclean.search as search from gentoolkit.eclean.search import DistfilesSearch +from gentoolkit.eclean.search import _deps_equal from gentoolkit.eclean.exclude import parseExcludeFile +from portage.dep import Atom + """Tests for eclean's distfiles search functions.""" @@ -670,12 +673,166 @@ def test_remove_protected(self): ) +class TestDepsEqual(unittest.TestCase): + + def test_deps_equal(self): + # def _deps_equal(deps_a, eapi_a, deps_b, eapi_b, libc_deps, uselist=None, cpv=None): + all_tests = [ + # 1 equal + ( + "x11-misc/xdg-user-dirs-gtk-0.11", + { + "deps_a": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_a": "8", + "deps_b": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_b": "8", + "libc_deps": {Atom("sys-libs/glibc:2.2")}, + "uselist": frozenset( + { + "elibc_glibc", + "amd64", + "abi_x86_64", + "kernel_linux", + "userland_GNU", + } + ), + }, + True, + ), + # 2 ebuild different gtk+ dep + ( + "x11-misc/xdg-user-dirs-gtk-0.11", + { + "deps_a": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_a": "8", + "deps_b": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.2:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_b": "8", + "libc_deps": {Atom("sys-libs/glibc:2.2")}, + "uselist": frozenset( + { + "elibc_glibc", + "amd64", + "abi_x86_64", + "kernel_linux", + "userland_GNU", + } + ), + }, + False, + ), + # 3 different eapi, but is not currently tested + ( + "x11-misc/xdg-user-dirs-gtk-0.11", + { + "deps_a": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_a": "7", + "deps_b": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_b": "8", + "libc_deps": {Atom("sys-libs/glibc:2.2")}, + "uselist": frozenset( + { + "elibc_glibc", + "amd64", + "abi_x86_64", + "kernel_linux", + "userland_GNU", + } + ), + }, + True, + ), + # 4 valid/False + ( + "x11-misc/xdg-user-dirs-0.18", + { + "deps_a": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_a": "8", + "deps_b": "gtk? ( x11-misc/xdg-user-dirs-gtk )", + "eapi_b": "8", + "libc_deps": {Atom("sys-libs/glibc:2.2")}, + "uselist": frozenset( + { + "elibc_glibc", + "amd64", + "abi_x86_64", + "kernel_linux", + "userland_GNU", + } + ), + }, + False, + ), + # 5 ebuild InvalidDependString + ( + "x11-misc/xdg-user-dirs-0.18", + { + "deps_a": "dev-libs/glib:2 >=x11-libs/gtk+-3.5.1:3 >=x11-misc/xdg-user-dirs-0.14", + "eapi_a": "8", + "deps_b": "gtk? ( )", + "eapi_b": "8", + "libc_deps": {Atom("sys-libs/glibc:2.2")}, + "uselist": frozenset( + { + "elibc_glibc", + "amd64", + "abi_x86_64", + "kernel_linux", + "userland_GNU", + } + ), + }, + True, + ), + # 6 binpkg InvalidDependString + ( + "x11-misc/xdg-user-dirs-0.18", + { + "deps_a": "gtk? ( )", + "eapi_a": "8", + "deps_b": "gtk? ( x11-misc/xdg-user-dirs-gtk )", + "eapi_b": "8", + "libc_deps": {Atom("sys-libs/glibc:2.2")}, + "uselist": frozenset( + { + "elibc_glibc", + "amd64", + "abi_x86_64", + "kernel_linux", + "userland_GNU", + } + ), + }, + False, + ), + ] + x = 1 + for test in all_tests: + cpv = test[0] + data = test[1] + # print(x, cpv) # for debug testing + self.assertEqual( + _deps_equal( + data["deps_a"], + data["eapi_a"], + data["deps_b"], + data["eapi_b"], + data["libc_deps"], + data["uselist"], + cpv, + ), + test[2], + ) + x += 1 + # print("####################") # for debug testing + + def test_main(): suite = unittest.TestLoader() suite.loadTestsFromTestCase(TestCheckLimits) suite.loadTestsFromTestCase(TestFetchRestricted) suite.loadTestsFromTestCase(TestNonDestructive) suite.loadTestsFromTestCase(TestRemoveProtected) + suite.loadTestsFromTestCase(TestDepsEqual) unittest.TextTestRunner(verbosity=2).run(suite)