Skip to content

Commit

Permalink
equery/depends: print output in module rather than with a callback
Browse files Browse the repository at this point in the history
The depends module can now iterate over the results of the
graph_reverse_depends function and print the items as they are
yielded.

Before, it passed in a callback printer function, and expected the
Dependencies class to call it correctly.

This setup is nicer because it does not tie together this module and
the Dependencies class, and the old setup most likely existed due to
performance and interactivity concerns which are now fixed by turning
graph_reverse_depends into an iterator.
  • Loading branch information
Jturnerusa committed Mar 6, 2024
1 parent 8ccb4b4 commit 51f41b8
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pym/gentoolkit/equery/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from gentoolkit.dependencies import Dependencies
from gentoolkit.equery import format_options, mod_usage, CONFIG
from gentoolkit.helpers import get_cpvs, get_installed_cpvs
from gentoolkit.cpv import CPV
from gentoolkit.package import PackageFormatter, Package

# =======
Expand All @@ -27,7 +26,7 @@
QUERY_OPTS = {
"include_masked": False,
"only_direct": True,
"max_depth": -1,
"max_depth": None,
"package_format": None,
}

Expand Down Expand Up @@ -94,9 +93,9 @@ def format_depend(self, dep, dep_is_displayed):
if dep_is_displayed and not self.verbose:
return

depth = getattr(dep, "depth", 0)
depth = dep.depth
indent = " " * depth
mdep = dep.matching_dep
mdep = dep.depatom
use_conditional = ""

if QUERY_OPTS["package_format"] != None:
Expand Down Expand Up @@ -226,17 +225,25 @@ def main(input_args):

if CONFIG["verbose"]:
print(" * These packages depend on %s:" % pp.emph(pkg.cpv))
if pkg.graph_reverse_depends(
pkgset=sorted(pkggetter(), key=CPV),
max_depth=QUERY_OPTS["max_depth"],

first_run = False

last_seen = None
for pkgdep in pkg.graph_reverse_depends(
pkgset=sorted(pkggetter()),
only_direct=QUERY_OPTS["only_direct"],
printer_fn=dep_print,
max_depth=QUERY_OPTS["max_depth"],
):
if last_seen is None or last_seen != pkgdep:
seen = False
else:
seen = True
printer(pkgdep, dep_is_displayed=seen)
last_seen = pkgdep
if last_seen is not None:
got_match = True

first_run = False

if not got_match:
if got_match is None:
sys.exit(1)


Expand Down

0 comments on commit 51f41b8

Please sign in to comment.