From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A21AD158090 for ; Fri, 16 Feb 2024 20:39:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 56BDFE29DB; Fri, 16 Feb 2024 20:39:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3EDFEE29DB for ; Fri, 16 Feb 2024 20:39:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6C02C34164C for ; Fri, 16 Feb 2024 20:39:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3D2201301 for ; Fri, 16 Feb 2024 20:39:43 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1708114369.c0300517671076db453204c796637e206bf977e5.sam@gentoo> Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/ X-VCS-Repository: proj/gentoolkit X-VCS-Files: pym/gentoolkit/dependencies.py X-VCS-Directories: pym/gentoolkit/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: c0300517671076db453204c796637e206bf977e5 X-VCS-Branch: master Date: Fri, 16 Feb 2024 20:39:43 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: b87f24d3-c969-4816-bdd5-2158a9f88746 X-Archives-Hash: c59edeb0e74fb6adf022fdc2c3dac21b commit: c0300517671076db453204c796637e206bf977e5 Author: John Turner gmail com> AuthorDate: Tue Feb 13 19:31:01 2024 +0000 Commit: Sam James gentoo 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 gmail.com> Signed-off-by: Sam James 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