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

pantsbuild / pants / 22285099215

22 Feb 2026 08:52PM UTC coverage: 75.854% (-17.1%) from 92.936%
22285099215

Pull #23121

github

web-flow
Merge c7299df9c into ba8359840
Pull Request #23121: fix issue with optional fields in dependency validator

28 of 29 new or added lines in 2 files covered. (96.55%)

11174 existing lines in 400 files now uncovered.

53694 of 70786 relevant lines covered (75.85%)

1.88 hits per line

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

0.0
/src/python/pants/backend/plugin_development/pants_requirements.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
from pants.backend.python.target_types import (
×
5
    PythonRequirementFindLinksField,
6
    PythonRequirementModulesField,
7
    PythonRequirementResolveField,
8
    PythonRequirementsField,
9
    PythonRequirementTarget,
10
)
UNCOV
11
from pants.engine.rules import collect_rules, rule
×
UNCOV
12
from pants.engine.target import (
×
13
    COMMON_TARGET_FIELDS,
14
    BoolField,
15
    GeneratedTargets,
16
    GenerateTargetsRequest,
17
    StringField,
18
    TargetGenerator,
19
)
UNCOV
20
from pants.engine.unions import UnionMembership, UnionRule
×
UNCOV
21
from pants.util.strutil import help_text
×
UNCOV
22
from pants.version import PANTS_SEMVER
×
23

24

UNCOV
25
class PantsRequirementsTestutilField(BoolField):
×
UNCOV
26
    alias = "testutil"
×
UNCOV
27
    default = True
×
UNCOV
28
    help = "If true, include `pantsbuild.pants.testutil` to write tests for your plugin."
×
29

30

UNCOV
31
class PantsRequirementsVersionSpecField(StringField):
×
UNCOV
32
    alias = "version_spec"
×
UNCOV
33
    default = f"== {PANTS_SEMVER.public}"
×
UNCOV
34
    help = help_text(
×
35
        """
36
        The PEP 440 version specifier version of Pants to target.
37
        E.g. `== 2.15.*`, or `>= 2.16.0, < 2.17.0`
38
        """
39
    )
40

41

UNCOV
42
class PantsRequirementsTargetGenerator(TargetGenerator):
×
UNCOV
43
    alias = "pants_requirements"
×
UNCOV
44
    help = help_text(
×
45
        """
46
        Generate `python_requirement` targets for Pants itself to use with Pants plugins.
47

48
        This is useful when writing plugins so that you can build and test your
49
        plugin using Pants.
50

51
        The generated targets will have the correct version based on the exact `version` in your
52
        `pants.toml`, and they will work with dependency inference. They're pulled directly from
53
        our GitHub releases, using the relevant platform markers.
54

55
        (If this versioning scheme does not work for you, you can directly create
56
        `python_requirement` targets for `pantsbuild.pants` and `pantsbuild.pants.testutil`. We
57
        also invite you to share your ideas at
58
        https://github.com/pantsbuild/pants/issues/new/choose)
59
        """
60
    )
UNCOV
61
    generated_target_cls = PythonRequirementTarget
×
UNCOV
62
    core_fields = (
×
63
        *COMMON_TARGET_FIELDS,
64
        PantsRequirementsVersionSpecField,
65
        PantsRequirementsTestutilField,
66
        PythonRequirementFindLinksField,
67
    )
UNCOV
68
    copied_fields = COMMON_TARGET_FIELDS
×
UNCOV
69
    moved_fields = (PythonRequirementResolveField,)
×
70

71

UNCOV
72
class GenerateFromPantsRequirementsRequest(GenerateTargetsRequest):
×
UNCOV
73
    generate_from = PantsRequirementsTargetGenerator
×
74

75

UNCOV
76
@rule
×
UNCOV
77
async def generate_from_pants_requirements(
×
78
    request: GenerateFromPantsRequirementsRequest, union_membership: UnionMembership
79
) -> GeneratedTargets:
UNCOV
80
    generator = request.generator
×
UNCOV
81
    version_spec = generator[PantsRequirementsVersionSpecField].value
×
82

UNCOV
83
    def create_tgt(dist: str, module: str) -> PythonRequirementTarget:
×
UNCOV
84
        return PythonRequirementTarget(
×
85
            {
86
                PythonRequirementsField.alias: (f"{dist} {version_spec}",),
87
                PythonRequirementFindLinksField.alias: ("https://wheels.pantsbuild.org/simple",),
88
                PythonRequirementModulesField.alias: (module,),
89
                **request.template,
90
            },
91
            request.template_address.create_generated(dist),
92
            union_membership,
93
        )
94

UNCOV
95
    result = [create_tgt("pantsbuild.pants", "pants")]
×
UNCOV
96
    if generator[PantsRequirementsTestutilField].value:
×
UNCOV
97
        result.append(create_tgt("pantsbuild.pants.testutil", "pants.testutil"))
×
UNCOV
98
    return GeneratedTargets(generator, result)
×
99

100

UNCOV
101
def rules():
×
UNCOV
102
    return (
×
103
        *collect_rules(),
104
        UnionRule(GenerateTargetsRequest, GenerateFromPantsRequirementsRequest),
105
    )
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