• 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/codegen/export_codegen_goal.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
import logging
×
5

UNCOV
6
from pants.core.util_rules.distdir import DistDir
×
UNCOV
7
from pants.engine.fs import MergeDigests, Workspace
×
UNCOV
8
from pants.engine.goal import Goal, GoalSubsystem
×
UNCOV
9
from pants.engine.internals.graph import hydrate_sources
×
UNCOV
10
from pants.engine.intrinsics import merge_digests
×
UNCOV
11
from pants.engine.rules import collect_rules, concurrently, goal_rule, implicitly
×
UNCOV
12
from pants.engine.target import (
×
13
    FilteredTargets,
14
    GenerateSourcesRequest,
15
    HydrateSourcesRequest,
16
    RegisteredTargetTypes,
17
    SourcesField,
18
)
UNCOV
19
from pants.engine.unions import UnionMembership
×
UNCOV
20
from pants.util.strutil import softwrap
×
21

UNCOV
22
logger = logging.getLogger(__name__)
×
23

24

UNCOV
25
class ExportCodegenSubsystem(GoalSubsystem):
×
UNCOV
26
    name = "export-codegen"
×
UNCOV
27
    help = "Write generated files to `dist/codegen` for use outside of Pants."
×
28

UNCOV
29
    @classmethod
×
UNCOV
30
    def activated(cls, union_membership: UnionMembership) -> bool:
×
31
        return GenerateSourcesRequest in union_membership
×
32

33

UNCOV
34
class ExportCodegen(Goal):
×
UNCOV
35
    subsystem_cls = ExportCodegenSubsystem
×
UNCOV
36
    environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY  # TODO(#17129) — Migrate this.
×
37

38

UNCOV
39
@goal_rule
×
UNCOV
40
async def export_codegen(
×
41
    targets: FilteredTargets,
42
    union_membership: UnionMembership,
43
    workspace: Workspace,
44
    dist_dir: DistDir,
45
    registered_target_types: RegisteredTargetTypes,
46
) -> ExportCodegen:
47
    # We run all possible code generators. Running codegen requires specifying the expected
48
    # output_type, so we must inspect what is possible to generate.
49
    all_generate_request_types = union_membership.get(GenerateSourcesRequest)
×
50
    inputs_to_outputs = [
×
51
        (req.input, req.output) for req in all_generate_request_types if req.exportable
52
    ]
53
    codegen_sources_fields_with_output = []
×
54
    for tgt in targets:
×
55
        if not tgt.has_field(SourcesField):
×
56
            continue
×
57
        sources = tgt[SourcesField]
×
58
        for input_type, output_type in inputs_to_outputs:
×
59
            if isinstance(sources, input_type):
×
60
                codegen_sources_fields_with_output.append((sources, output_type))
×
61

62
    if not codegen_sources_fields_with_output:
×
63
        codegen_targets = sorted(
×
64
            {
65
                tgt_type.alias
66
                for tgt_type in registered_target_types.types
67
                for input_source in {input_source for input_source, _ in inputs_to_outputs}
68
                if tgt_type.class_has_field(input_source, union_membership=union_membership)
69
            }
70
        )
71
        logger.warning(
×
72
            softwrap(
73
                f"""
74
                No codegen files/targets matched. All codegen target types:
75
                {", ".join(codegen_targets)}
76
                """
77
            )
78
        )
79
        return ExportCodegen(exit_code=0)
×
80

81
    all_hydrated_sources = await concurrently(
×
82
        hydrate_sources(
83
            HydrateSourcesRequest(
84
                sources,
85
                for_sources_types=(output_type,),
86
                enable_codegen=True,
87
            ),
88
            **implicitly(),
89
        )
90
        for sources, output_type in codegen_sources_fields_with_output
91
    )
92

93
    merged_digest = await merge_digests(
×
94
        MergeDigests(hydrated_sources.snapshot.digest for hydrated_sources in all_hydrated_sources)
95
    )
96

97
    dest = str(dist_dir.relpath / "codegen")
×
98
    logger.info(f"Writing generated files to {dest}")
×
99
    workspace.write_digest(merged_digest, path_prefix=dest)
×
100
    return ExportCodegen(exit_code=0)
×
101

102

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