Partly separate the solver from the inst_tester

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 6 years ago
parent c0ecdd82fb
commit 07a407e810
No known key found for this signature in database
GPG Key ID: A65B78DBE67C7AAC

@ -198,6 +198,7 @@ from britney2.consts import (SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS
from britney2.excuse import Excuse
from britney2.hints import HintParser
from britney2.installability.builder import build_installability_tester
from britney2.installability.solver import InstallabilitySolver
from britney2.migrationitem import MigrationItem
from britney2.policies import PolicyVerdict
from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, BuildDependsPolicy
@ -2205,6 +2206,7 @@ class Britney(object):
rescheduled_packages = packages
maybe_rescheduled_packages = []
output_logger = self.output_logger
solver = InstallabilitySolver(self.pkg_universe, self._inst_tester)
for y in sorted((y for y in packages), key=attrgetter('uvname')):
updates, rms, _, _ = self._compute_groups(y.package, y.suite, y.architecture, y.is_removal)
@ -2221,7 +2223,7 @@ class Britney(object):
output_logger.info("recur: [] %s %d/0", ",".join(x.uvname for x in selected), len(packages))
while rescheduled_packages:
groups = {group_info[x] for x in rescheduled_packages}
worklist = self._inst_tester.solve_groups(groups)
worklist = solver.solve_groups(groups)
rescheduled_packages = []
worklist.reverse()

@ -17,7 +17,7 @@ from collections import defaultdict
from itertools import product
from britney2.utils import ifilter_except, iter_except, get_dependency_solvers
from britney2.installability.solver import InstallabilitySolver
from britney2.installability.tester import InstallabilityTester
from britney2.installability.universe import BinaryPackageRelation, BinaryPackageUniverse
@ -310,7 +310,7 @@ class InstallabilityTesterBuilder(object):
universe = BinaryPackageUniverse(relations)
solver = InstallabilitySolver(universe,
solver = InstallabilityTester(universe,
self._testing,
self._broken,
self._essentials,

@ -18,7 +18,6 @@ import logging
from collections import deque
from britney2.utils import (ifilter_only, iter_except)
from britney2.installability.tester import InstallabilityTester
def compute_scc(graph):
@ -130,27 +129,20 @@ def compute_scc(graph):
return result
class InstallabilitySolver(InstallabilityTester):
class InstallabilitySolver(object):
def __init__(self, universe, testing, broken, essentials, eqv_table):
def __init__(self, universe, inst_tester):
"""Create a new installability solver
universe is a BinaryPackageUniverse.
testing is a (mutable) set of package tuples that determines
which of the packages in universe are currently in testing.
broken is a (mutable) set of package tuples that are known to
be uninstallable.
Package tuple: (pkg_name, pkg_version, pkg_arch)
- NB: arch:all packages are "re-mapped" to given architecture.
(simplifies caches and dependency checking)
"""
super().__init__(universe, testing, broken, essentials, eqv_table)
self._universe = universe
self._inst_tester = inst_tester
logger_name = ".".join((self.__class__.__module__, self.__class__.__name__))
self.logger = logging.getLogger(logger_name)
def solve_groups(self, groups):
sat_in_testing = self._testing.isdisjoint
sat_in_testing = self._inst_tester.any_of_these_are_in_testing
universe = self._universe
result = []
emitted = set()
@ -212,7 +204,7 @@ class InstallabilitySolver(InstallabilityTester):
for rdep in universe.reverse_dependencies_of(r):
for depgroup in universe.dependencies_of(rdep):
rigid = depgroup - going_out
if not sat_in_testing(rigid):
if sat_in_testing(rigid):
# (partly) satisfied by testing, assume it is okay
continue
if rdep in ptable:
@ -231,7 +223,7 @@ class InstallabilitySolver(InstallabilityTester):
# binary provided by this item).
for depgroup in universe.dependencies_of(a):
rigid = depgroup - going_out
if not sat_in_testing(rigid):
if sat_in_testing(rigid):
# (partly) satisfied by testing, assume it is okay
continue
# okay - we got three cases now.

@ -4,7 +4,7 @@ import unittest
from collections import OrderedDict
from . import new_pkg_universe_builder
from britney2.installability.solver import compute_scc
from britney2.installability.solver import compute_scc, InstallabilitySolver
class TestInstTester(unittest.TestCase):
@ -433,7 +433,8 @@ class TestInstTester(unittest.TestCase):
try:
sys.setrecursionlimit(recursion_limit)
_, inst_tester = builder.build()
universe, inst_tester = builder.build()
solver = InstallabilitySolver(universe, inst_tester)
groups = []
for pkg in pkgs:
@ -441,7 +442,7 @@ class TestInstTester(unittest.TestCase):
groups.append(group)
expected = {g[0] for g in groups}
actual = inst_tester.solve_groups(groups)
actual = solver.solve_groups(groups)
assert actual
assert expected == set(actual[0])
assert len(actual) == 1
@ -478,7 +479,8 @@ class TestInstTester(unittest.TestCase):
pkgg.depends_on(pkgh)
pkgh.depends_on(pkge).depends_on(pkgi)
_, inst_tester = builder.build()
universe, inst_tester = builder.build()
solver = InstallabilitySolver(universe, inst_tester)
expected = [
# SSC 3 first
{pkgi.pkg_id.package_name},
@ -493,7 +495,7 @@ class TestInstTester(unittest.TestCase):
for node in ssc:
groups.append((node, {builder.pkg_id(node)}, {}))
actual = [set(x) for x in inst_tester.solve_groups(groups)]
actual = [set(x) for x in solver.solve_groups(groups)]
print("EXPECTED: %s" % str(expected))
print("ACTUAL : %s" % str(actual))
assert expected == actual

Loading…
Cancel
Save