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

pantsbuild / pants / 19381742489

15 Nov 2025 12:52AM UTC coverage: 49.706% (-30.6%) from 80.29%
19381742489

Pull #22890

github

web-flow
Merge d961abf79 into 42e1ebd41
Pull Request #22890: Updated all python subsystem constraints to 3.14

4 of 5 new or added lines in 5 files covered. (80.0%)

14659 existing lines in 485 files now uncovered.

31583 of 63540 relevant lines covered (49.71%)

0.79 hits per line

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

95.65
/src/python/pants/backend/openapi/target_types.py
1
# Copyright 2022 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 pants.engine.rules import collect_rules, rule
1✔
7
from pants.engine.target import (
1✔
8
    COMMON_TARGET_FIELDS,
9
    AllTargets,
10
    Dependencies,
11
    MultipleSourcesField,
12
    OptionalSingleSourceField,
13
    SingleSourceField,
14
    StringField,
15
    Target,
16
    TargetFilesGenerator,
17
    Targets,
18
    generate_multiple_sources_field_help_message,
19
)
20
from pants.util.logging import LogLevel
1✔
21
from pants.util.strutil import help_text
1✔
22

23
OPENAPI_FILE_EXTENSIONS = (".json", ".yaml", ".yml")
1✔
24

25

26
class OpenApiField(SingleSourceField):
1✔
27
    expected_file_extensions = OPENAPI_FILE_EXTENSIONS
1✔
28

29

30
class OpenApiGeneratorField(MultipleSourcesField):
1✔
31
    expected_file_extensions = OPENAPI_FILE_EXTENSIONS
1✔
32

33

34
# -----------------------------------------------------------------------------------------------
35
# `openapi_document` and `openapi_documents` targets
36
# -----------------------------------------------------------------------------------------------
37

38

39
class OpenApiDocumentField(OpenApiField):
1✔
40
    pass
1✔
41

42

43
class OpenApiDocumentDependenciesField(Dependencies):
1✔
44
    pass
1✔
45

46

47
class OpenApiDocumentTarget(Target):
1✔
48
    alias = "openapi_document"
1✔
49
    core_fields = (
1✔
50
        *COMMON_TARGET_FIELDS,
51
        OpenApiDocumentDependenciesField,
52
        OpenApiDocumentField,
53
    )
54
    help = "A single OpenAPI document file."
1✔
55

56

57
class OpenApiDocumentGeneratorField(OpenApiGeneratorField):
1✔
58
    default = tuple(f"openapi{ext}" for ext in OPENAPI_FILE_EXTENSIONS)
1✔
59
    help = generate_multiple_sources_field_help_message("Example: `sources=['openapi.json']`")
1✔
60

61

62
class OpenApiDocumentGeneratorTarget(TargetFilesGenerator):
1✔
63
    alias = "openapi_documents"
1✔
64
    core_fields = (
1✔
65
        *COMMON_TARGET_FIELDS,
66
        OpenApiDocumentGeneratorField,
67
    )
68
    generated_target_cls = OpenApiDocumentTarget
1✔
69
    copied_fields = COMMON_TARGET_FIELDS
1✔
70
    moved_fields = (OpenApiDocumentDependenciesField,)
1✔
71
    help = (
1✔
72
        f"Generate an `{OpenApiDocumentTarget.alias}` target for each file in the `sources` field."
73
    )
74

75

76
class AllOpenApiDocumentTargets(Targets):
1✔
77
    pass
1✔
78

79

80
@rule(desc="Find all OpenAPI Document targets in project", level=LogLevel.DEBUG)
1✔
81
async def find_all_openapi_document_targets(all_targets: AllTargets) -> AllOpenApiDocumentTargets:
1✔
82
    return AllOpenApiDocumentTargets(
×
83
        tgt for tgt in all_targets if tgt.has_field(OpenApiDocumentField)
84
    )
85

86

87
# -----------------------------------------------------------------------------------------------
88
# `openapi_source` and `openapi_sources` targets
89
# -----------------------------------------------------------------------------------------------
90

91

92
class OpenApiSourceField(OpenApiField):
1✔
93
    pass
1✔
94

95

96
class OpenApiSourceDependenciesField(Dependencies):
1✔
97
    pass
1✔
98

99

100
class OpenApiSourceTarget(Target):
1✔
101
    alias = "openapi_source"
1✔
102
    core_fields = (
1✔
103
        *COMMON_TARGET_FIELDS,
104
        OpenApiSourceDependenciesField,
105
        OpenApiSourceField,
106
    )
107
    help = "A single OpenAPI source file."
1✔
108

109

110
class OpenApiSourceGeneratorField(OpenApiGeneratorField):
1✔
111
    default = tuple(f"*{ext}" for ext in OPENAPI_FILE_EXTENSIONS)
1✔
112
    help = generate_multiple_sources_field_help_message("Example: `sources=['*.json']`")
1✔
113

114

115
class OpenApiSourceGeneratorTarget(TargetFilesGenerator):
1✔
116
    alias = "openapi_sources"
1✔
117
    core_fields = (
1✔
118
        *COMMON_TARGET_FIELDS,
119
        OpenApiSourceGeneratorField,
120
    )
121
    generated_target_cls = OpenApiSourceTarget
1✔
122
    copied_fields = COMMON_TARGET_FIELDS
1✔
123
    moved_fields = (OpenApiSourceDependenciesField,)
1✔
124
    help = f"Generate an `{OpenApiSourceTarget.alias}` target for each file in the `sources` field."
1✔
125

126

127
class AllOpenApiSourceTargets(Targets):
1✔
128
    pass
1✔
129

130

131
@rule(desc="Find all OpenAPI source targets in project", level=LogLevel.DEBUG)
1✔
132
async def find_all_openapi_source_targets(all_targets: AllTargets) -> AllOpenApiSourceTargets:
1✔
133
    return AllOpenApiSourceTargets(tgt for tgt in all_targets if tgt.has_field(OpenApiSourceField))
×
134

135

136
# -----------------------------------------------------------------------------------------------
137
# `openapi_bundle` target
138
# -----------------------------------------------------------------------------------------------
139

140

141
class OpenApiBundleSourceRootField(StringField):
1✔
142
    alias = "bundle_source_root"
1✔
143
    help = help_text(
1✔
144
        f"""
145
        The source root to bundle OpenAPI documents under.
146

147
        If unspecified, the source root the `{OpenApiDocumentGeneratorTarget.alias}` is under will be used.
148
        """
149
    )
150

151

152
class OpenApiBundleDependenciesField(Dependencies):
1✔
153
    pass
1✔
154

155

156
class OpenApiBundleDummySourceField(OptionalSingleSourceField):
1✔
157
    alias = "_source"
1✔
158

159

160
class OpenApiBundleTarget(Target):
1✔
161
    alias = "openapi_bundle"
1✔
162
    core_fields = (
1✔
163
        *COMMON_TARGET_FIELDS,
164
        OpenApiBundleDummySourceField,
165
        OpenApiBundleDependenciesField,
166
        OpenApiBundleSourceRootField,
167
    )
168
    help = help_text("An OpenAPI document bundled as a single source.")
1✔
169

170

171
def rules():
1✔
UNCOV
172
    return collect_rules()
×
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