Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eclean: output InvalidDepstring info in findPackages #43

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 50 additions & 9 deletions pym/gentoolkit/eclean/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pym/gentoolkit/enalyze/rebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __init__(self):
"pretend": False,
"prefix": False,
"portage": True,
"slot": False
"slot": False,
# "unset": False
}
self.module_opts = {
Expand Down
157 changes: 157 additions & 0 deletions pym/gentoolkit/test/eclean/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""


Expand Down Expand Up @@ -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)


Expand Down
Loading