• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 21803785359

08 Feb 2026 07:13PM UTC coverage: 43.3% (-37.0%) from 80.277%
21803785359

Pull #23085

github

web-flow
Merge 7c1cd926d into 40389cc58
Pull Request #23085: A helper method for indexing paths by source root

2 of 6 new or added lines in 1 file covered. (33.33%)

17114 existing lines in 539 files now uncovered.

26075 of 60219 relevant lines covered (43.3%)

0.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/python/pants/backend/python/providers/python_build_standalone/constraints.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
1✔
4

5
import operator
1✔
6
from collections.abc import Callable, Iterable
1✔
7
from typing import Protocol, cast
1✔
8

9
from packaging.version import Version
1✔
10

11
_OPERATORS = (
1✔
12
    (">=", operator.ge),
13
    ("<=", operator.le),
14
    ("==", operator.eq),
15
    ("!=", operator.ne),
16
    # `>` and `<` must come last since these strings are shorter!
17
    (">", operator.gt),
18
    ("<", operator.lt),
19
)
20

21

22
class ConstraintParseError(Exception):
1✔
23
    pass
1✔
24

25

26
class ConstraintSatisfied(Protocol):
1✔
27
    def is_satisified(self, version: Version) -> bool: ...
28

29

30
class Constraint(ConstraintSatisfied):
1✔
31
    """A single version constraint with operator."""
32

33
    def __init__(
1✔
34
        self, cmp_callback: Callable[[Version, Version], bool], cmp_version: Version
35
    ) -> None:
UNCOV
36
        self.cmp_callback: Callable[[Version, Version], bool] = cmp_callback
×
UNCOV
37
        self.cmp_version: Version = cmp_version
×
38

39
    def is_satisified(self, version: Version) -> bool:
1✔
UNCOV
40
        return self.cmp_callback(version, self.cmp_version)
×
41

42
    @classmethod
1✔
43
    def parse(cls, constraint: str) -> Constraint:
1✔
UNCOV
44
        constraint = constraint.strip()
×
45

UNCOV
46
        for op, callback in _OPERATORS:
×
UNCOV
47
            constraint_without_op = constraint.removeprefix(op)
×
UNCOV
48
            if constraint_without_op != constraint:
×
UNCOV
49
                cmp_callback = cast("Callable[[Version, Version], bool]", callback)
×
UNCOV
50
                cmp_version = Version(constraint_without_op.strip())
×
UNCOV
51
                return cls(cmp_callback, cmp_version)
×
52

53
        raise ConstraintParseError(
×
54
            f"A constraint must start with a comparison operator, i.e. {', '.join(x[0] for x in _OPERATORS)}, found {constraint!r}."
55
        )
56

57

58
class ConstraintsList(ConstraintSatisfied):
1✔
59
    """A list of constraints which must all match (i.e., they are AND'ed together)."""
60

61
    def __init__(self, constraints: Iterable[ConstraintSatisfied]) -> None:
1✔
UNCOV
62
        self.constraints: tuple[ConstraintSatisfied, ...] = tuple(constraints)
×
63

64
    def is_satisified(self, version: Version) -> bool:
1✔
UNCOV
65
        for constraint in self.constraints:
×
UNCOV
66
            if not constraint.is_satisified(version):
×
UNCOV
67
                return False
×
UNCOV
68
        return True
×
69

70
    @classmethod
1✔
71
    def parse(cls, constraints_str: str) -> ConstraintsList:
1✔
UNCOV
72
        parts = constraints_str.split(",")
×
UNCOV
73
        constraints = [Constraint.parse(part.strip()) for part in parts]
×
UNCOV
74
        return cls(constraints)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc