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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 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
3✔
4

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

9
from packaging.version import Version
3✔
10

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

25

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

29

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

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

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

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

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

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

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

© 2025 Coveralls, Inc