From 0ab452b14bc500fa9f9f5aba4d015d17ab77a455 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Tue, 3 Dec 2024 13:24:27 -0600 Subject: [PATCH] fix: use ordering of PRs ignoring bad ones (#3275) --- conda_forge_tick/migrators/core.py | 58 +++++++++++++------ conda_forge_tick/migrators/migration_yaml.py | 49 ---------------- .../migrators/noarch_python_min.py | 49 +--------------- conda_forge_tick/migrators/replacement.py | 21 +------ 4 files changed, 43 insertions(+), 134 deletions(-) diff --git a/conda_forge_tick/migrators/core.py b/conda_forge_tick/migrators/core.py index 2cb03e4e6..7714d341b 100644 --- a/conda_forge_tick/migrators/core.py +++ b/conda_forge_tick/migrators/core.py @@ -3,6 +3,7 @@ import copy import datetime import logging +import random import re import typing from pathlib import Path @@ -14,7 +15,6 @@ from conda_forge_tick.contexts import ClonedFeedstockContext, FeedstockContext from conda_forge_tick.lazy_json_backends import LazyJson from conda_forge_tick.make_graph import make_outputs_lut_from_graph -from conda_forge_tick.path_lengths import cyclic_topological_sort from conda_forge_tick.update_recipe import update_build_number, v1_recipe from conda_forge_tick.utils import ( frozen_to_json_friendly, @@ -574,24 +574,48 @@ def order( graph: nx.DiGraph, total_graph: nx.DiGraph, ) -> Sequence["PackageName"]: - """Order to run migrations in + """Run the order by number of decedents, ties are resolved by package name""" - Parameters - ---------- - graph : nx.DiGraph - The graph of migratable PRs - - Returns - ------- + if hasattr(self, "name"): + assert isinstance(self.name, str) + migrator_name = self.name.lower().replace(" ", "") + else: + migrator_name = self.__class__.__name__.lower() - """ - top_level = { - node - for node in graph - if not list(graph.predecessors(node)) - or list(graph.predecessors(node)) == [node] - } - return cyclic_topological_sort(graph, top_level) + def _not_has_error(node): + if migrator_name in total_graph.nodes[node]["payload"].get( + "pr_info", + {}, + ).get("pre_pr_migrator_status", {}) and ( + total_graph.nodes[node]["payload"] + .get("pr_info", {}) + .get( + "pre_pr_migrator_attempts", + {}, + ) + .get( + migrator_name, + self.max_solver_attempts, + ) + >= self.max_solver_attempts + ): + return 0 + else: + return 1 + + return sorted( + graph, + key=lambda x: ( + _not_has_error(x), + ( + random.uniform(0, 1) + if not _not_has_error(x) + else len(nx.descendants(total_graph, x)) + ), + x, + ), + reverse=True, + ) def set_build_number(self, filename: str | Path) -> None: """Bump the build number of the specified recipe. diff --git a/conda_forge_tick/migrators/migration_yaml.py b/conda_forge_tick/migrators/migration_yaml.py index 705dadd82..8fbb76b19 100644 --- a/conda_forge_tick/migrators/migration_yaml.py +++ b/conda_forge_tick/migrators/migration_yaml.py @@ -1,7 +1,6 @@ import copy import logging import os -import random import re import time import typing @@ -389,54 +388,6 @@ def migrator_uid(self, attrs: "AttrsTypedDict") -> "MigrationUidTypedDict": n["name"] = self.name return n - def order( - self, - graph: nx.DiGraph, - total_graph: nx.DiGraph, - ) -> Sequence["PackageName"]: - """Run the order by number of decedents, ties are resolved by package name""" - - if hasattr(self, "name"): - assert isinstance(self.name, str) - migrator_name = self.name.lower().replace(" ", "") - else: - migrator_name = self.__class__.__name__.lower() - - def _not_has_error(node): - if migrator_name in total_graph.nodes[node]["payload"].get( - "pr_info", - {}, - ).get("pre_pr_migrator_status", {}) and ( - total_graph.nodes[node]["payload"] - .get("pr_info", {}) - .get( - "pre_pr_migrator_attempts", - {}, - ) - .get( - migrator_name, - 3, - ) - >= self.max_solver_attempts - ): - return 0 - else: - return 1 - - return sorted( - graph, - key=lambda x: ( - _not_has_error(x), - ( - random.uniform(0, 1) - if not _not_has_error(x) - else len(nx.descendants(total_graph, x)) - ), - x, - ), - reverse=True, - ) - class MigrationYamlCreator(Migrator): """Migrator creating migration yaml files.""" diff --git a/conda_forge_tick/migrators/noarch_python_min.py b/conda_forge_tick/migrators/noarch_python_min.py index a79c3258b..03dec1d18 100644 --- a/conda_forge_tick/migrators/noarch_python_min.py +++ b/conda_forge_tick/migrators/noarch_python_min.py @@ -1,7 +1,6 @@ import functools import logging import os -import random import textwrap import typing from typing import Sequence @@ -21,7 +20,7 @@ from conda_forge_tick.os_utils import pushd if typing.TYPE_CHECKING: - from ..migrators_types import AttrsTypedDict, PackageName + from ..migrators_types import AttrsTypedDict logger = logging.getLogger(__name__) @@ -502,49 +501,3 @@ def migrator_uid(self, attrs): n = super().migrator_uid(attrs) n["name"] = self.name return n - - def order( - self, - graph: nx.DiGraph, - total_graph: nx.DiGraph, - ) -> Sequence["PackageName"]: - if hasattr(self, "name"): - assert isinstance(self.name, str) - migrator_name = self.name.lower().replace(" ", "") - else: - migrator_name = self.__class__.__name__.lower() - - def _not_has_error(node): - if migrator_name in total_graph.nodes[node]["payload"].get( - "pr_info", - {}, - ).get("pre_pr_migrator_status", {}) and ( - total_graph.nodes[node]["payload"] - .get("pr_info", {}) - .get( - "pre_pr_migrator_attempts", - {}, - ) - .get( - migrator_name, - self.max_solver_attempts, - ) - >= self.max_solver_attempts - ): - return 0 - else: - return 1 - - return sorted( - graph, - key=lambda x: ( - _not_has_error(x), - ( - random.uniform(0, 1) - if not _not_has_error(x) - else len(nx.descendants(total_graph, x)) - ), - x, - ), - reverse=True, - ) diff --git a/conda_forge_tick/migrators/replacement.py b/conda_forge_tick/migrators/replacement.py index f1f154160..e1f99cf44 100644 --- a/conda_forge_tick/migrators/replacement.py +++ b/conda_forge_tick/migrators/replacement.py @@ -2,7 +2,7 @@ import os import re import typing -from typing import Any, Sequence +from typing import Any import networkx as nx @@ -78,25 +78,6 @@ def __init__( self._reset_effective_graph() - def order( - self, - graph: nx.DiGraph, - total_graph: nx.DiGraph, - ) -> Sequence["PackageName"]: - """Order to run migrations in - - Parameters - ---------- - graph : nx.DiGraph - The graph of migratable PRs - - Returns - ------- - graph : nx.DiGraph - The ordered graph. - """ - return graph - def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool: requirements = attrs.get("requirements", {}) rq = (