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

pantsbuild / pants / 21552830208

31 Jan 2026 11:40PM UTC coverage: 80.277% (-0.05%) from 80.324%
21552830208

Pull #23062

github

web-flow
Merge 808a9786c into 2c4dcf9cf
Pull Request #23062: Remove support for Get

18 of 25 new or added lines in 4 files covered. (72.0%)

17119 existing lines in 541 files now uncovered.

78278 of 97510 relevant lines covered (80.28%)

3.36 hits per line

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

97.37
/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
6✔
4

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

9
from packaging.version import Version
6✔
10

11
_OPERATORS = (
6✔
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):
6✔
23
    pass
6✔
24

25

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

29

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

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

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

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

UNCOV
46
        for op, callback in _OPERATORS:
2✔
UNCOV
47
            constraint_without_op = constraint.removeprefix(op)
2✔
UNCOV
48
            if constraint_without_op != constraint:
2✔
UNCOV
49
                cmp_callback = cast("Callable[[Version, Version], bool]", callback)
2✔
UNCOV
50
                cmp_version = Version(constraint_without_op.strip())
2✔
UNCOV
51
                return cls(cmp_callback, cmp_version)
2✔
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):
6✔
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:
6✔
UNCOV
62
        self.constraints: tuple[ConstraintSatisfied, ...] = tuple(constraints)
2✔
63

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

70
    @classmethod
6✔
71
    def parse(cls, constraints_str: str) -> ConstraintsList:
6✔
UNCOV
72
        parts = constraints_str.split(",")
2✔
UNCOV
73
        constraints = [Constraint.parse(part.strip()) for part in parts]
2✔
UNCOV
74
        return cls(constraints)
2✔
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