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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

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

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

0.0
/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

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
from pants.engine.rules import collect_rules, rule
×
UNCOV
7
from pants.engine.target import (
×
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
)
UNCOV
20
from pants.util.logging import LogLevel
×
UNCOV
21
from pants.util.strutil import help_text
×
22

UNCOV
23
OPENAPI_FILE_EXTENSIONS = (".json", ".yaml", ".yml")
×
24

25

UNCOV
26
class OpenApiField(SingleSourceField):
×
UNCOV
27
    expected_file_extensions = OPENAPI_FILE_EXTENSIONS
×
28

29

UNCOV
30
class OpenApiGeneratorField(MultipleSourcesField):
×
UNCOV
31
    expected_file_extensions = OPENAPI_FILE_EXTENSIONS
×
32

33

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

38

UNCOV
39
class OpenApiDocumentField(OpenApiField):
×
UNCOV
40
    pass
×
41

42

UNCOV
43
class OpenApiDocumentDependenciesField(Dependencies):
×
UNCOV
44
    pass
×
45

46

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

56

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

61

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

75

UNCOV
76
class AllOpenApiDocumentTargets(Targets):
×
UNCOV
77
    pass
×
78

79

UNCOV
80
@rule(desc="Find all OpenAPI Document targets in project", level=LogLevel.DEBUG)
×
UNCOV
81
async def find_all_openapi_document_targets(all_targets: AllTargets) -> AllOpenApiDocumentTargets:
×
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

UNCOV
92
class OpenApiSourceField(OpenApiField):
×
UNCOV
93
    pass
×
94

95

UNCOV
96
class OpenApiSourceDependenciesField(Dependencies):
×
UNCOV
97
    pass
×
98

99

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

109

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

114

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

126

UNCOV
127
class AllOpenApiSourceTargets(Targets):
×
UNCOV
128
    pass
×
129

130

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

135

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

140

UNCOV
141
class OpenApiBundleSourceRootField(StringField):
×
UNCOV
142
    alias = "bundle_source_root"
×
UNCOV
143
    help = help_text(
×
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

UNCOV
152
class OpenApiBundleDependenciesField(Dependencies):
×
UNCOV
153
    pass
×
154

155

UNCOV
156
class OpenApiBundleDummySourceField(OptionalSingleSourceField):
×
UNCOV
157
    alias = "_source"
×
158

159

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

170

UNCOV
171
def rules():
×
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