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

pantsbuild / pants / 24055979590

06 Apr 2026 11:17PM UTC coverage: 52.37% (-40.5%) from 92.908%
24055979590

Pull #23225

github

web-flow
Merge 67474653c into 542ca048d
Pull Request #23225: Add --test-show-all-batch-targets to expose all targets in batched pytest

6 of 17 new or added lines in 2 files covered. (35.29%)

23030 existing lines in 605 files now uncovered.

31643 of 60422 relevant lines covered (52.37%)

1.05 hits per line

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

0.0
/src/python/pants/backend/tools/preamble/subsystem.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
from __future__ import annotations
×
4

UNCOV
5
from collections.abc import Sequence
×
6

UNCOV
7
from pants.option.option_types import DictOption, SkipOption
×
UNCOV
8
from pants.option.subsystem import Subsystem
×
UNCOV
9
from pants.source.filespec import FilespecMatcher
×
UNCOV
10
from pants.util.strutil import help_text, softwrap
×
11

12

UNCOV
13
class PreambleSubsystem(Subsystem):
×
UNCOV
14
    options_scope = "preamble"
×
UNCOV
15
    name = "preamble"
×
UNCOV
16
    help = help_text(
×
17
        """
18
        Formats files with a preamble, with the preamble looked up based on path.
19

20
        This is useful for things such as copyright headers or shebang lines.
21

22
        Pants substitutes the following identifiers (following Python's `string.Template` substitutions):
23
        - $year: The current year (only used when actually writing the year to the file).
24
        """
25
    )
26

UNCOV
27
    skip = SkipOption("fmt")
×
28

UNCOV
29
    _template_by_globs = DictOption[str](
×
30
        help=softwrap(
31
            """
32
            Which preamble template to use based on the path globs (relative to the build root).
33

34
            Example:
35

36
                {
37
                    '*.rs': '// Copyright (c) $year\\n// Line 2\\n'
38
                    '*.py:!__init__.py': '# Copyright (c) $year\\n# Line 2\\n',
39
                }
40

41
            It might be helpful to load this config from a JSON or YAML file. To do that, set
42
            `[preamble].config = '@path/to/config.yaml'`, for example.
43
            """
44
        ),
45
        fromfile=True,
46
    )
47

UNCOV
48
    @property
×
UNCOV
49
    def template_by_globs(self) -> dict[tuple[str, ...], str]:
×
UNCOV
50
        return {tuple(key.split(":")): value for key, value in self._template_by_globs.items()}
×
51

UNCOV
52
    def get_template_by_path(self, filepaths: Sequence[str]) -> dict[str, str]:
×
53
        """Returns a mapping from path to (most-relevant) template."""
UNCOV
54
        filepaths_to_test = set(filepaths)
×
UNCOV
55
        template_by_path = {}
×
UNCOV
56
        for globs, template in self.template_by_globs.items():
×
UNCOV
57
            if not filepaths_to_test:
×
58
                break
×
59

UNCOV
60
            matched_filepaths = FilespecMatcher(
×
61
                includes=[
62
                    (glob[2:] if glob.startswith(r"\\!") else glob)
63
                    for glob in globs
64
                    if not glob.startswith("!")
65
                ],
66
                excludes=[glob[1:] for glob in globs if glob.startswith("!")],
67
            ).matches(tuple(filepaths_to_test))
UNCOV
68
            filepaths_to_test -= set(matched_filepaths)
×
UNCOV
69
            for filepath in matched_filepaths:
×
UNCOV
70
                template_by_path[filepath] = template
×
71

UNCOV
72
        return template_by_path
×
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