• 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

0.0
/src/python/pants/backend/helm/goals/tailor.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
import logging
×
UNCOV
7
import os
×
UNCOV
8
from dataclasses import dataclass
×
9

UNCOV
10
from pants.backend.helm.subsystems.helm import HelmSubsystem
×
UNCOV
11
from pants.backend.helm.target_types import (
×
12
    HelmChartTarget,
13
    HelmUnitTestGeneratingSourcesField,
14
    HelmUnitTestTestsGeneratorTarget,
15
)
UNCOV
16
from pants.backend.helm.util_rules.chart_metadata import HELM_CHART_METADATA_FILENAMES
×
UNCOV
17
from pants.core.goals.tailor import (
×
18
    AllOwnedSources,
19
    PutativeTarget,
20
    PutativeTargets,
21
    PutativeTargetsRequest,
22
)
UNCOV
23
from pants.core.target_types import ResourcesGeneratorTarget
×
UNCOV
24
from pants.engine.fs import PathGlobs
×
UNCOV
25
from pants.engine.intrinsics import path_globs_to_paths
×
UNCOV
26
from pants.engine.rules import collect_rules, rule
×
UNCOV
27
from pants.engine.unions import UnionRule
×
UNCOV
28
from pants.source.filespec import FilespecMatcher
×
UNCOV
29
from pants.util.dirutil import group_by_dir
×
UNCOV
30
from pants.util.logging import LogLevel
×
UNCOV
31
from pants.util.strutil import softwrap
×
32

UNCOV
33
logger = logging.getLogger(__name__)
×
34

35

UNCOV
36
@dataclass(frozen=True)
×
UNCOV
37
class PutativeHelmTargetsRequest(PutativeTargetsRequest):
×
UNCOV
38
    pass
×
39

40

UNCOV
41
_TESTS_FOLDER_NAME = "tests"
×
UNCOV
42
_SNAPSHOT_FOLDER_NAME = "__snapshot__"
×
UNCOV
43
_SNAPSHOT_FILE_GLOBS = ("*_test.yaml.snap", "*_test.yml.snap")
×
44

45

UNCOV
46
@rule(desc="Determine candidate Helm chart targets to create", level=LogLevel.DEBUG)
×
UNCOV
47
async def find_putative_helm_targets(
×
48
    request: PutativeHelmTargetsRequest,
49
    all_owned_sources: AllOwnedSources,
50
    helm_subsystem: HelmSubsystem,
51
) -> PutativeTargets:
52
    putative_targets = []
×
53

54
    if helm_subsystem.tailor_charts:
×
55
        all_chart_files = await path_globs_to_paths(
×
56
            request.path_globs(*HELM_CHART_METADATA_FILENAMES)
57
        )
58
        unowned_chart_files = set(all_chart_files.files) - set(all_owned_sources)
×
59

60
        for chart_file in sorted(unowned_chart_files):
×
61
            dirname, filename = os.path.split(chart_file)
×
62
            putative_targets.append(
×
63
                PutativeTarget.for_target_type(
64
                    HelmChartTarget,
65
                    name=os.path.basename(dirname),
66
                    path=dirname,
67
                    triggering_sources=[filename],
68
                )
69
            )
70

71
        if helm_subsystem.tailor_unittests:
×
72
            chart_folders = {os.path.dirname(path) for path in all_chart_files.files}
×
73
            # Helm charts have a rigid folder structure and we rely on it
74
            # to successfully identify unit tests without false positives.
75
            all_unittest_files = await path_globs_to_paths(
×
76
                PathGlobs(
77
                    [
78
                        os.path.join(chart_root, _TESTS_FOLDER_NAME, glob)
79
                        for glob in HelmUnitTestGeneratingSourcesField.default
80
                        for chart_root in chart_folders
81
                    ]
82
                )
83
            )
84
            unonwned_unittest_files = set(all_unittest_files.files) - set(all_owned_sources)
×
85
            unittest_filespec_matcher = FilespecMatcher(
×
86
                HelmUnitTestGeneratingSourcesField.default, ()
87
            )
88
            unittest_files = {
×
89
                path
90
                for path in unonwned_unittest_files
91
                if os.path.basename(path)
92
                in set(
93
                    unittest_filespec_matcher.matches(
94
                        [os.path.basename(path) for path in unonwned_unittest_files]
95
                    )
96
                )
97
            }
98
            grouped_unittest_files = group_by_dir(unittest_files)
×
99

100
            # To prevent false positives, we look for snapshot files relative to the unit test sources
101
            all_snapshot_files = await path_globs_to_paths(
×
102
                PathGlobs(
103
                    [
104
                        os.path.join(dirname, _SNAPSHOT_FOLDER_NAME, glob)
105
                        for glob in _SNAPSHOT_FILE_GLOBS
106
                        for dirname in grouped_unittest_files.keys()
107
                    ]
108
                )
109
            )
110
            unowned_snapshot_files = set(all_snapshot_files.files) - set(all_owned_sources)
×
111
            grouped_snapshot_files = group_by_dir(unowned_snapshot_files)
×
112
            snapshot_folders = list(grouped_snapshot_files.keys())
×
113

114
            def find_snapshot_files_for(unittest_dir: str) -> set[str]:
×
115
                key = [
×
116
                    folder for folder in snapshot_folders if os.path.dirname(folder) == unittest_dir
117
                ]
118
                if not key:
×
119
                    return set()
×
120
                return grouped_snapshot_files[key[0]]
×
121

122
            for dirname, filenames in grouped_unittest_files.items():
×
123
                putative_targets.append(
×
124
                    PutativeTarget.for_target_type(
125
                        HelmUnitTestTestsGeneratorTarget,
126
                        path=dirname,
127
                        name=None,
128
                        triggering_sources=sorted(filenames),
129
                    )
130
                )
131

132
                snapshot_files = find_snapshot_files_for(dirname)
×
133
                if snapshot_files:
×
134
                    putative_targets.append(
×
135
                        PutativeTarget.for_target_type(
136
                            ResourcesGeneratorTarget,
137
                            path=os.path.join(dirname, _SNAPSHOT_FOLDER_NAME),
138
                            name=None,
139
                            triggering_sources=sorted(snapshot_files),
140
                            kwargs={"sources": _SNAPSHOT_FILE_GLOBS},
141
                        )
142
                    )
143

144
    elif helm_subsystem.tailor_unittests:
×
145
        logging.warning(
×
146
            softwrap(
147
                """
148
                Pants can not identify Helm unit tests when `[helm].tailor_charts` has been set to `False`.
149

150
                If this is intentional, then set `[helm].tailor_unittests` to `False` to disable this warning.
151
                """
152
            )
153
        )
154

155
    return PutativeTargets(putative_targets)
×
156

157

UNCOV
158
def rules():
×
UNCOV
159
    return [*collect_rules(), UnionRule(PutativeTargetsRequest, PutativeHelmTargetsRequest)]
×
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