inst/builder.py: Split function in three to reduce indentation levels

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

@ -23,76 +23,86 @@ from britney2.installability.solver import InstallabilitySolver
def build_installability_tester(suite_info, archs): def build_installability_tester(suite_info, archs):
"""Create the installability tester""" """Create the installability tester"""
solvers = get_dependency_solvers
builder = InstallabilityTesterBuilder() builder = InstallabilityTesterBuilder()
for (suite, arch) in product(suite_info, archs): for (suite, arch) in product(suite_info, archs):
packages_s_a = suite.binaries[arch][0] _build_inst_tester_on_suite_arch(builder, suite_info, suite, arch)
is_target = suite.suite_class.is_target
bin_prov = [s.binaries[arch] for s in suite_info]
for pkgdata in packages_s_a.values():
pkg_id = pkgdata.pkg_id
if not builder.add_binary(pkg_id,
essential=pkgdata.is_essential,
in_testing=is_target):
continue
if pkgdata.conflicts: return builder.build()
conflicts = []
conflicts_parsed = apt_pkg.parse_depends(pkgdata.conflicts, False)
# Breaks/Conflicts are so simple that we do not need to keep align the relation def _build_inst_tester_on_suite_arch(builder, suite_info, suite, arch):
# with the suite. This enables us to do a few optimizations. packages_s_a = suite.binaries[arch][0]
for dep_binaries_s_a, dep_provides_s_a in bin_prov: is_target = suite.suite_class.is_target
for block in (relation for relation in conflicts_parsed): bin_prov = [s.binaries[arch] for s in suite_info]
# if a package satisfies its own conflicts relation, then it is using §7.6.2 solvers = get_dependency_solvers
conflicts.extend(s.pkg_id for s in solvers(block, dep_binaries_s_a, dep_provides_s_a) for pkgdata in packages_s_a.values():
if s.pkg_id != pkg_id) pkg_id = pkgdata.pkg_id
else: if not builder.add_binary(pkg_id,
conflicts = None essential=pkgdata.is_essential,
in_testing=is_target):
if pkgdata.depends: continue
depends = []
possible_dep_ranges = {} if pkgdata.conflicts:
for block in apt_pkg.parse_depends(pkgdata.depends, False): conflicts = []
sat = {s.pkg_id for binaries_s_a, provides_s_a in bin_prov conflicts_parsed = apt_pkg.parse_depends(pkgdata.conflicts, False)
for s in solvers(block, binaries_s_a, provides_s_a)} # Breaks/Conflicts are so simple that we do not need to keep align the relation
# with the suite. This enables us to do a few optimizations.
if len(block) != 1: for dep_binaries_s_a, dep_provides_s_a in bin_prov:
depends.append(sat) for block in (relation for relation in conflicts_parsed):
else: # if a package satisfies its own conflicts relation, then it is using §7.6.2
# This dependency might be a part conflicts.extend(s.pkg_id for s in solvers(block, dep_binaries_s_a, dep_provides_s_a)
# of a version-range a la: if s.pkg_id != pkg_id)
# else:
# Depends: pkg-a (>= 1), conflicts = None
# pkg-a (<< 2~)
# if pkgdata.depends:
# In such a case we want to reduce depends = _compute_depends(pkgdata, bin_prov, solvers)
# that to a single clause for else:
# efficiency. depends = None
#
# In theory, it could also happen builder.set_relations(pkg_id, depends, conflicts)
# with "non-minimal" dependencies
# a la:
# def _compute_depends(pkgdata, bin_prov, solvers):
# Depends: pkg-a, pkg-a (>= 1) depends = []
# possible_dep_ranges = {}
# But dpkg is known to fix that up for block in apt_pkg.parse_depends(pkgdata.depends, False):
# at build time, so we will sat = {s.pkg_id for binaries_s_a, provides_s_a in bin_prov
# probably only see "ranges" here. for s in solvers(block, binaries_s_a, provides_s_a)}
key = block[0][0]
if key in possible_dep_ranges: if len(block) != 1:
possible_dep_ranges[key] &= sat depends.append(sat)
else: else:
possible_dep_ranges[key] = sat # This dependency might be a part
# of a version-range a la:
if possible_dep_ranges: #
depends.extend(possible_dep_ranges.values()) # Depends: pkg-a (>= 1),
# pkg-a (<< 2~)
#
# In such a case we want to reduce
# that to a single clause for
# efficiency.
#
# In theory, it could also happen
# with "non-minimal" dependencies
# a la:
#
# Depends: pkg-a, pkg-a (>= 1)
#
# But dpkg is known to fix that up
# at build time, so we will
# probably only see "ranges" here.
key = block[0][0]
if key in possible_dep_ranges:
possible_dep_ranges[key] &= sat
else: else:
depends = None possible_dep_ranges[key] = sat
builder.set_relations(pkg_id, depends, conflicts) if possible_dep_ranges:
depends.extend(possible_dep_ranges.values())
return builder.build() return depends
class InstallabilityTesterBuilder(object): class InstallabilityTesterBuilder(object):

Loading…
Cancel
Save