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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 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

4
from __future__ import annotations
×
5

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

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

25

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

29

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

33

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

38

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

42

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

46

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

56

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

61

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

75

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

79

80
@rule(desc="Find all OpenAPI Document targets in project", level=LogLevel.DEBUG)
×
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

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

95

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

99

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

109

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

114

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

126

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

130

131
@rule(desc="Find all OpenAPI source targets in project", level=LogLevel.DEBUG)
×
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

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

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

155

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

159

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

170

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