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

pantsbuild / pants / 20332790708

18 Dec 2025 09:48AM UTC coverage: 64.992% (-15.3%) from 80.295%
20332790708

Pull #22949

github

web-flow
Merge f730a56cd into 407284c67
Pull Request #22949: Add experimental uv resolver for Python lockfiles

54 of 97 new or added lines in 5 files covered. (55.67%)

8270 existing lines in 295 files now uncovered.

48990 of 75379 relevant lines covered (64.99%)

1.81 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
2✔
4

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

9
from packaging.version import Version
2✔
10

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

25

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

29

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

33
    def __init__(
2✔
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:
2✔
UNCOV
40
        return self.cmp_callback(version, self.cmp_version)
×
41

42
    @classmethod
2✔
43
    def parse(cls, constraint: str) -> Constraint:
2✔
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):
2✔
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:
2✔
UNCOV
62
        self.constraints: tuple[ConstraintSatisfied, ...] = tuple(constraints)
×
63

64
    def is_satisified(self, version: Version) -> bool:
2✔
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
2✔
71
    def parse(cls, constraints_str: str) -> ConstraintsList:
2✔
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

© 2025 Coveralls, Inc