Skip to content

Commit

Permalink
fix: use ordering of PRs ignoring bad ones (#3275)
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr authored Dec 3, 2024
1 parent 778cc1b commit 0ab452b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 134 deletions.
58 changes: 41 additions & 17 deletions conda_forge_tick/migrators/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import datetime
import logging
import random
import re
import typing
from pathlib import Path
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
49 changes: 0 additions & 49 deletions conda_forge_tick/migrators/migration_yaml.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import logging
import os
import random
import re
import time
import typing
Expand Down Expand Up @@ -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."""
Expand Down
49 changes: 1 addition & 48 deletions conda_forge_tick/migrators/noarch_python_min.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import functools
import logging
import os
import random
import textwrap
import typing
from typing import Sequence
Expand All @@ -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__)

Expand Down Expand Up @@ -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,
)
21 changes: 1 addition & 20 deletions conda_forge_tick/migrators/replacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import re
import typing
from typing import Any, Sequence
from typing import Any

import networkx as nx

Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit 0ab452b

Please sign in to comment.