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

pantsbuild / pants / 24103663753

07 Apr 2026 08:47PM UTC coverage: 92.906% (-0.003%) from 92.909%
24103663753

Pull #23228

github

web-flow
Merge 12bedb3c2 into b05152cd9
Pull Request #23228: Add persistent dependency inference cache for incremental --changed-dependents

299 of 316 new or added lines in 3 files covered. (94.62%)

10 existing lines in 4 files now uncovered.

91827 of 98839 relevant lines covered (92.91%)

4.04 hits per line

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

97.06
/src/python/pants/backend/python/mixed_interpreter_constraints/py_constraints_test.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
from textwrap import dedent
1✔
7

8
import pytest
1✔
9

10
from pants.backend.python import target_types_rules
1✔
11
from pants.backend.python.mixed_interpreter_constraints.py_constraints import PyConstraintsGoal
1✔
12
from pants.backend.python.mixed_interpreter_constraints.py_constraints import (
1✔
13
    rules as py_constraints_rules,
14
)
15
from pants.backend.python.target_types import (
1✔
16
    PythonSourcesGeneratorTarget,
17
    PythonSourceTarget,
18
    PythonTestsGeneratorTarget,
19
    PythonTestTarget,
20
)
21
from pants.core.target_types import FileTarget
1✔
22
from pants.testutil.rule_runner import GoalRuleResult, RuleRunner
1✔
23
from pants.util.strutil import softwrap
1✔
24

25

26
@pytest.fixture
1✔
27
def rule_runner() -> RuleRunner:
1✔
28
    return RuleRunner(
1✔
29
        rules=(*py_constraints_rules(), *target_types_rules.rules()),
30
        target_types=[
31
            FileTarget,
32
            PythonSourcesGeneratorTarget,
33
            PythonTestsGeneratorTarget,
34
            PythonSourceTarget,
35
            PythonTestTarget,
36
        ],
37
    )
38

39

40
def write_files(rule_runner: RuleRunner) -> None:
1✔
41
    rule_runner.write_files(
1✔
42
        {
43
            "lib1/f.py": "",
44
            "lib1/BUILD": "python_sources(interpreter_constraints=['==2.7.*', '>=3.5'])",
45
            # We leave off `interpreter_constraints`, which results in using
46
            # `[python].interpreter_constraints` instead.
47
            "lib2/f.py": "",
48
            "lib2/BUILD": "python_sources()",
49
            "app/f.py": "",
50
            "app/BUILD": dedent(
51
                """\
52
                python_sources(
53
                    dependencies=['lib1', 'lib2/f.py'],
54
                    interpreter_constraints=['==3.7.*'],
55
                )
56
                """
57
            ),
58
        }
59
    )
60

61

62
def run_goal(rule_runner: RuleRunner, args: list[str]) -> GoalRuleResult:
1✔
63
    return rule_runner.run_goal_rule(
1✔
64
        PyConstraintsGoal,
65
        env={"PANTS_PYTHON_INTERPRETER_CONSTRAINTS": "['>=3.6']"},
66
        args=args,
67
        global_args=["--no-python-infer-imports"],
68
    )
69

70

71
def test_no_matches(rule_runner: RuleRunner, caplog) -> None:
1✔
72
    rule_runner.write_files({"f.txt": "", "BUILD": "file(name='tgt', source='f.txt')"})
1✔
73
    result = run_goal(rule_runner, ["f.txt"])
1✔
74
    assert result.exit_code == 0
1✔
75
    print(caplog.records)
1✔
76
    assert len(caplog.records) == 1
1✔
77
    assert (
1✔
78
        softwrap(
79
            """
80
            No Python files/targets matched for the `py-constraints` goal. All target types with
81
            Python interpreter constraints: python_source, python_test
82
            """
83
        )
84
        in caplog.text
85
    )
86

87

88
def test_render_constraints(rule_runner: RuleRunner) -> None:
1✔
89
    write_files(rule_runner)
1✔
90
    result = run_goal(rule_runner, ["app:app"])
1✔
91
    assert result.stdout == dedent(
1✔
92
        """\
93
        Final merged constraints: CPython==2.7.*,==3.7.*,>=3.6 OR CPython==3.7.*,>=3.5,>=3.6
94

95
        CPython==3.7.*
96
          app/f.py
97

98
        CPython>=3.6
99
          lib2/f.py
100

101
        CPython==2.7.* OR CPython>=3.5
102
          lib1/f.py
103
        """
104
    )
105

106
    # If we run on >1 input, we include a warning about what the "final merged constraints" mean.
107
    result = run_goal(rule_runner, ["app:app", "lib1:lib1"])
1✔
108
    assert "Consider using a more precise query" in result.stdout
1✔
109

110

111
def test_constraints_summary(rule_runner: RuleRunner) -> None:
1✔
112
    write_files(rule_runner)
1✔
113
    result = run_goal(rule_runner, ["--summary"])
1✔
UNCOV
114
    assert result.stdout == dedent(
×
115
        """\
116
        Target,Constraints,Transitive Constraints,# Dependencies,# Dependents\r
117
        app/f.py,CPython==3.7.*,"CPython==2.7.*,==3.7.*,>=3.6 OR CPython==3.7.*,>=3.5,>=3.6",2,1\r
118
        lib1/f.py,CPython==2.7.* OR CPython>=3.5,CPython==2.7.* OR CPython>=3.5,0,3\r
119
        lib2/f.py,CPython>=3.6,CPython>=3.6,0,3\r
120
        """
121
    )
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