public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
Date: Fri, 16 Feb 2024 20:39:43 +0000 (UTC)	[thread overview]
Message-ID: <1708114369.c0300517671076db453204c796637e206bf977e5.sam@gentoo> (raw)

commit:     c0300517671076db453204c796637e206bf977e5
Author:     John Turner <jturner.usa <AT> gmail <DOT> com>
AuthorDate: Tue Feb 13 19:31:01 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 16 20:12:49 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=c0300517

dependencies.py: unify get_*depend methods

Instead of having separate functions for each DEPEND kind, the unified
method returns a dict with all of the packages *DEPEND values inside
of it. The dict can be indexed with a string or a field of the
DependencyKind enum.

This will be espeically useful for a future change that adds the
ability to filter out specific DEPEND kinds from the query.

The Dependencies class did not search IDEPEND dependencies, the
unified method searches all dependency kinds defined in the
DependencyKind enum, which includes IDEPEND!

Signed-off-by: John Turner <jturner.usa <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index dd30312..4564d8c 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -11,7 +11,9 @@ __all__ = ("Dependencies",)
 # Imports
 # =======
 
+import itertools
 from enum import StrEnum
+from typing import List, Dict
 
 import portage
 from portage.dep import paren_reduce
@@ -100,22 +102,19 @@ class Dependencies(Query):
         except portage.exception.InvalidPackageName as err:
             raise errors.GentoolkitInvalidCPV(err)
 
-    def get_depend(self, **kwargs):
-        """Get the contents of DEPEND and parse it with self.parser."""
-        return self._get_depend(("DEPEND",), **kwargs)
+    def get_raw_depends(self) -> str:
+        return self._get_depend([depkind for depkind in DependencyKind], raw=True)
 
-    def get_pdepend(self, **kwargs):
-        """Get the contents of PDEPEND and parse it with self.parser."""
-        return self._get_depend(("PDEPEND",), **kwargs)
+    def get_depends(self) -> Dict[DependencyKind, List[Atom]]:
+        depends = dict()
+        for depkind in DependencyKind:
+            depend = self._get_depend([depkind])
+            depends[depkind] = depend
+        return depends
 
-    def get_rdepend(self, **kwargs):
-        """Get the contents of RDEPEND and parse it with self.parser."""
-        return self._get_depend(("RDEPEND",), **kwargs)
-
-    def get_all_depends(self, **kwargs):
-        """Get the contents of ?DEPEND and parse it with self.parser."""
-        env_vars = ("DEPEND", "PDEPEND", "RDEPEND", "BDEPEND")
-        return self._get_depend(env_vars, **kwargs)
+    def get_all_depends(self) -> List[Atom]:
+        # flatten Dict[DependencyKind, List[Atom]] into a List[Atom]
+        return list(itertools.chain.from_iterable(self.get_depends().values()))
 
     def graph_depends(
         self,
@@ -246,8 +245,7 @@ class Dependencies(Query):
 
         pkgdep = None
         for pkgdep in pkgset:
-            raw_depends = pkgdep.get_all_depends(raw=True)
-            if self.cp not in raw_depends:
+            if self.cp not in pkgdep.get_raw_depends():
                 # fast path for obviously non-matching packages. This saves
                 # us the work of instantiating a whole Atom() for *every*
                 # dependency of *every* package in pkgset.
@@ -255,7 +253,7 @@ class Dependencies(Query):
             try:
                 all_depends = depcache[pkgdep]
             except KeyError:
-                all_depends = uniqify(pkgdep.get_all_depends())
+                all_depends = pkgdep.get_all_depends()
                 depcache[pkgdep] = all_depends
 
             dep_is_displayed = False


             reply	other threads:[~2024-02-16 20:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16 20:39 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-05-03  5:55 [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/ Sam James
2024-03-07 18:49 Sam James
2024-03-07 15:08 Sam James
2024-02-17  0:01 Sam James
2024-02-16 20:39 Sam James
2024-02-16 20:39 Sam James
2022-12-14  9:24 Sam James
2022-07-10  7:53 Brian Dolbec
2022-07-10  7:53 Brian Dolbec
2021-09-21 21:01 Matt Turner
2020-10-13 14:14 Brian Dolbec
2020-10-09  6:29 Georgy Yakovlev
2020-04-24  8:06 Michał Górny
2019-07-29  0:51 Zac Medico
2019-05-11 22:43 Virgil Dupras
2018-09-17 23:32 Virgil Dupras
2017-09-06 18:33 Paul Varner
2016-09-15 16:02 Brian Dolbec
2016-08-16 16:05 Paul Varner
2016-07-25 18:04 Paul Varner
2016-07-08 15:37 Brian Dolbec
2015-10-22 16:13 Paul Varner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1708114369.c0300517671076db453204c796637e206bf977e5.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox