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 DE63C158015 for ; Sat, 30 Dec 2023 10:45:07 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 917E52BC017; Sat, 30 Dec 2023 10:45:06 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 74A1E2BC01D for ; Sat, 30 Dec 2023 10:45:06 +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) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8AE0633BE3B for ; Sat, 30 Dec 2023 10:45:05 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8D8D099E for ; Sat, 30 Dec 2023 10:45:03 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1703853190.ab02bcd54d02aebbe0ac84943beb92fee615ea0b.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/scripts/ X-VCS-Repository: proj/pkgcore/pkgdev X-VCS-Files: src/pkgdev/scripts/pkgdev_bugs.py X-VCS-Directories: src/pkgdev/scripts/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: ab02bcd54d02aebbe0ac84943beb92fee615ea0b X-VCS-Branch: main Date: Sat, 30 Dec 2023 10:45:03 +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: 26bad958-609d-4ce4-8f26-1b4cd006b0dc X-Archives-Hash: df1b574349fdc916c4669ce788b20338 commit: ab02bcd54d02aebbe0ac84943beb92fee615ea0b Author: Arthur Zamarin gentoo org> AuthorDate: Fri Dec 29 09:29:15 2023 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Fri Dec 29 12:33:10 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=ab02bcd5 bugs: improve best match finder Use ``find_best_match`` for finding the best match, for the targets list (instead of just selecting the max for each target). Apply this for stabilization groups and cmd line packages. We do need to opt out the preference for semi-stable over non-stable, as we want to stabilize those requested. Signed-off-by: Arthur Zamarin gentoo.org> src/pkgdev/scripts/pkgdev_bugs.py | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/pkgdev/scripts/pkgdev_bugs.py b/src/pkgdev/scripts/pkgdev_bugs.py index 7c11d31..21f242f 100644 --- a/src/pkgdev/scripts/pkgdev_bugs.py +++ b/src/pkgdev/scripts/pkgdev_bugs.py @@ -8,7 +8,6 @@ from collections import defaultdict from datetime import datetime from functools import partial from itertools import chain -from pathlib import Path from urllib.parse import urlencode from pkgcheck import const as pkgcheck_const @@ -282,7 +281,7 @@ class DependencyGraph: data={attr: str(getattr(pkg, attr.lower())) for attr in pkg.eapi.dep_keys}, ) - def find_best_match(self, restrict, pkgset: list[package]) -> package: + def find_best_match(self, restrict, pkgset: list[package], prefer_semi_stable=True) -> package: restrict = boolean.AndRestriction( *restrict, packages.PackageRestriction("properties", values.ContainmentMatch("live", negate=True)), @@ -295,18 +294,18 @@ class DependencyGraph: if intersect := tuple(filter(restrict.match, all_pkgs)): return max(intersect) matches = sorted(filter(restrict.match, pkgset), reverse=True) - for match in matches: - if not all(keyword.startswith("~") for keyword in match.keywords): - return match + if prefer_semi_stable: + for match in matches: + if not all(keyword.startswith("~") for keyword in match.keywords): + return match return matches[0] def extend_targets_stable_groups(self, groups): stabilization_groups = self.options.repo.stabilization_groups - search_repo = self.options.search_repo for group in groups: for pkg in stabilization_groups[group]: try: - yield None, self.find_best_match([pkg], search_repo.match(pkg)).versioned_atom + yield None, pkg except (ValueError, IndexError): self.err.write(f"Unable to find match for {pkg.unversioned_atom}") @@ -339,9 +338,18 @@ class DependencyGraph: results[match].add(keyword) yield from results.items() - def build_full_graph(self, targets: list[package]): - self.targets = tuple(targets) - check_nodes = [(pkg, set()) for pkg in targets] + def load_targets(self, targets: list[tuple[str, str]]): + result = [] + search_repo = self.options.search_repo + for _, target in targets: + try: + result.append(self.find_best_match([target], search_repo.match(target), False)) + except ValueError: + raise ValueError(f"Restriction {target} has no match in repository") + self.targets = tuple(result) + + def build_full_graph(self): + check_nodes = [(pkg, set()) for pkg in self.targets] vertices: dict[package, GraphNode] = {} edges = [] @@ -373,7 +381,7 @@ class DependencyGraph: for src, dst in edges: vertices[src].edges.add(vertices[dst]) self.starting_nodes = { - vertices[starting_node] for starting_node in targets if starting_node in vertices + vertices[starting_node] for starting_node in self.targets if starting_node in vertices } def output_dot(self, dot_file): @@ -538,14 +546,6 @@ def _load_from_stdin(out: Formatter, err: Formatter): raise arghparse.ArgumentError(None, "reading from stdin is only valid when piping data in") -def _parse_targets(search_repo, targets): - for _, target in targets: - try: - yield max(search_repo.itermatch(target)) - except ValueError: - raise ValueError(f"Restriction {target} has no match in repository") - - @bugs.bind_main_func def main(options, out: Formatter, err: Formatter): search_repo = options.search_repo @@ -554,8 +554,8 @@ def main(options, out: Formatter, err: Formatter): options.targets.extend(d.extend_targets_stable_groups(options.sets or ())) if not options.targets: options.targets = list(_load_from_stdin(out, err)) - targets = list(_parse_targets(search_repo, options.targets)) - d.build_full_graph(targets) + d.load_targets(options.targets) + d.build_full_graph() d.merge_stabilization_groups() d.merge_cycles() d.merge_new_keywords_children()