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

pantsbuild / pants / 25441711719

06 May 2026 02:31PM UTC coverage: 92.915%. Remained the same
25441711719

push

github

web-flow
use sha pin (with comment) format for generated actions (#23312)

Per the GitHub Action best practices we recently enabled at #23249, we
should pin each action to a SHA so that the reference is actually
immutable.

This will -- I hope -- knock out a large chunk of the 421 alerts we
currently get from zizmor. The next followup would then be upgrades and
harmonizing the generated and none-generated pins.

Notice: This idea was suggested by Claude while going over pinact output
and I was surprised to see that post processing the yaml wasn't too
gross.

92206 of 99237 relevant lines covered (92.91%)

4.04 hits per line

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

96.08
/src/python/pants/build_graph/build_file_aliases.py
1
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
12✔
5

6
from collections.abc import Callable, Mapping
12✔
7
from dataclasses import dataclass
12✔
8
from typing import Any
12✔
9

10
from pants.base.parse_context import ParseContext
12✔
11
from pants.util.frozendict import FrozenDict
12✔
12

13
ContextAwareObjectFactory = Callable[[ParseContext], Callable[..., None]]
12✔
14

15

16
@dataclass(frozen=True)
12✔
17
class BuildFileAliases:
12✔
18
    """A structure containing sets of symbols to be exposed in BUILD files.
19

20
    There are three types of symbols that can be directly exposed:
21

22
    :API: public
23

24
    - targets: These are Target subclasses or TargetMacro.Factory instances.
25
    - objects: These are any python object, from constants to types.
26
    - context_aware_object_factories: These are object factories that are passed a ParseContext and
27
      produce one or more objects that use data from the context to enable some feature or utility;
28
      you might call them a BUILD file "macro" since they expand parameters to some final, "real"
29
      BUILD file object.  Common uses include creating objects that must be aware of the current
30
      BUILD file path or functions that need to be able to create targets or objects from within the
31
      BUILD file parse.
32
    """
33

34
    _objects: FrozenDict[str, Any]
12✔
35
    _context_aware_object_factories: FrozenDict[str, ContextAwareObjectFactory]
12✔
36

37
    @classmethod
12✔
38
    def _validate_alias(cls, category: str, alias: str, obj: Any) -> None:
12✔
39
        if not isinstance(alias, str):
12✔
40
            raise TypeError(
×
41
                f"Aliases must be strings, given {category} entry {alias!r} of type {type(alias).__name__} as "
42
                f"the alias of {obj}"
43
            )
44

45
    @classmethod
12✔
46
    def _validate_objects(cls, objects: dict[str, Any] | None) -> FrozenDict[str, Any]:
12✔
47
        if not objects:
12✔
48
            return FrozenDict()
12✔
49

50
        for alias, obj in objects.items():
12✔
51
            cls._validate_alias("objects", alias, obj)
12✔
52
        return FrozenDict(objects)
12✔
53

54
    @classmethod
12✔
55
    def _validate_context_aware_object_factories(
12✔
56
        cls, context_aware_object_factories: dict[str, ContextAwareObjectFactory] | None
57
    ) -> FrozenDict[str, ContextAwareObjectFactory]:
58
        if not context_aware_object_factories:
12✔
59
            return FrozenDict()
12✔
60

61
        for alias, obj in context_aware_object_factories.items():
3✔
62
            cls._validate_alias("context_aware_object_factories", alias, obj)
3✔
63
            if not callable(obj):
3✔
64
                raise TypeError(
1✔
65
                    f"The given context aware object factory {alias!r} must be a callable."
66
                )
67

68
        return FrozenDict(context_aware_object_factories)
3✔
69

70
    def __init__(
12✔
71
        self,
72
        objects: dict[str, Any] | None = None,
73
        context_aware_object_factories: dict[str, ContextAwareObjectFactory] | None = None,
74
    ) -> None:
75
        """
76
        :API: public
77
        """
78
        object.__setattr__(self, "_objects", self._validate_objects(objects))
12✔
79
        object.__setattr__(
12✔
80
            self,
81
            "_context_aware_object_factories",
82
            self._validate_context_aware_object_factories(context_aware_object_factories),
83
        )
84

85
    @property
12✔
86
    def objects(self) -> FrozenDict[str, Any]:
12✔
87
        """
88
        :API: public
89
        """
90
        return self._objects
12✔
91

92
    @property
12✔
93
    def context_aware_object_factories(self) -> FrozenDict[str, ContextAwareObjectFactory]:
12✔
94
        """
95
        :API: public
96
        """
97
        return self._context_aware_object_factories
12✔
98

99
    def merge(self, other: BuildFileAliases) -> BuildFileAliases:
12✔
100
        """Merges a set of build file aliases and returns a new set of aliases containing both.
101

102
        Any duplicate aliases from `other` will trump.
103

104
        :API: public
105
        """
106
        if not isinstance(other, BuildFileAliases):
1✔
107
            raise TypeError(f"Can only merge other BuildFileAliases, given {other}")
×
108

109
        def _merge(item1: Mapping[str, Any], item2: Mapping[str, Any]) -> dict[str, Any]:
1✔
110
            merged: dict[str, Any] = {}
1✔
111
            merged.update(item1)
1✔
112
            merged.update(item2)
1✔
113
            return merged
1✔
114

115
        objects = _merge(self.objects, other.objects)
1✔
116
        context_aware_object_factories = _merge(
1✔
117
            self.context_aware_object_factories, other.context_aware_object_factories
118
        )
119
        return BuildFileAliases(
1✔
120
            objects=objects,
121
            context_aware_object_factories=context_aware_object_factories,
122
        )
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