Coverage for src/debputy/bug1120283.py: 100%
9 statements
« prev ^ index » next coverage.py v7.8.2, created at 2026-01-04 10:15 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2026-01-04 10:15 +0000
1"""Version 2 of patch in bug #1120283 for python-debian.
3A new debian.deb822 will hopefully one day replace this file.
4"""
6import collections.abc
8from debian.debian_support import DpkgArchTable
9from debian.deb822 import PkgRelation
12def holds_on_arch(
13 relation: "PkgRelation.ParsedRelation",
14 arch: str,
15 table: DpkgArchTable,
16) -> bool:
17 """Is relation active on the given architecture?
19 >>> table = DpkgArchTable.load_arch_table()
20 >>> rel = PkgRelation.parse_relations("foo [armel linux-any]")[0][0]
21 >>> holds_on_arch(rel, "amd64", table)
22 True
23 >>> holds_on_arch(rel, "hurd-i386", table)
24 False
25 """
26 archs = relation["arch"]
27 return archs is None or table.architecture_is_concerned(
28 arch, tuple(("" if a.enabled else "!") + a.arch for a in archs)
29 )
32def holds_with_profiles(
33 relation: "PkgRelation.ParsedRelation",
34 profiles: collections.abc.Container[str],
35) -> bool:
36 """Is relation active under the given profiles?
38 >>> relation = PkgRelation.parse_relations("foo <a !b> <c>")[0][0]
39 >>> holds_with_profiles(relation, ("a", "b"))
40 False
41 >>> holds_with_profiles(relation, ("c", ))
42 True
43 """
44 restrictions = relation["restrictions"]
45 return restrictions is None or any(
46 all(term.enabled == (term.profile in profiles) for term in restriction_list)
47 for restriction_list in restrictions
48 )