• 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/go/util_rules/embedcfg.py
1
# Copyright 2021 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 json
×
UNCOV
7
from collections.abc import Iterable, Mapping
×
UNCOV
8
from dataclasses import dataclass
×
UNCOV
9
from typing import Any
×
10

UNCOV
11
from pants.util.frozendict import FrozenDict
×
UNCOV
12
from pants.util.strutil import strip_prefix
×
13

14

UNCOV
15
@dataclass(frozen=True)
×
UNCOV
16
class EmbedConfig:
×
UNCOV
17
    patterns: FrozenDict[str, tuple[str, ...]]
×
UNCOV
18
    files: FrozenDict[str, str]
×
19

UNCOV
20
    def __init__(self, patterns: Mapping[str, Iterable[str]], files: Mapping[str, str]) -> None:
×
21
        """Configuration passed to the Go compiler to configure file embedding.
22

23
        The compiler relies entirely on the caller to map embed patterns to actual filesystem
24
        paths. All embed patterns
25
        contained in the package must be mapped. Consult
26
        `FirstPartyPkgAnalysis.embed_patterns` for the embed patterns obtained from analysis.
27

28
        :param patterns: Maps each pattern provided via a //go:embed directive to a list of file
29
          paths relative to the package directory for files to embed for that pattern. When the
30
          embedded variable is an `embed.FS`, those relative file paths define the virtual
31
          directory hierarchy exposed by the embed.FS filesystem abstraction. The relative file
32
          paths are resolved to actual filesystem paths for their content by consulting the
33
          `files` dictionary.
34
        :param files: Maps each virtual, relative file path used as a value in the `patterns`
35
          dictionary to the actual filesystem path with that file's content.
36
        """
UNCOV
37
        object.__setattr__(self, "patterns", FrozenDict({k: tuple(v) for k, v in patterns.items()}))
×
UNCOV
38
        object.__setattr__(self, "files", FrozenDict(files))
×
39

UNCOV
40
    @classmethod
×
UNCOV
41
    def from_json_dict(
×
42
        cls, d: dict[str, Any], prefix_to_strip: str | None = None
43
    ) -> EmbedConfig | None:
44
        patterns = d.get("Patterns", {})
×
45
        files = d.get("Files", {})
×
46
        if prefix_to_strip:
×
47
            files = {key: strip_prefix(value, prefix_to_strip) for key, value in files.items()}
×
48
        result = cls(
×
49
            patterns=FrozenDict({key: tuple(value) for key, value in patterns.items()}),
50
            files=FrozenDict(files),
51
        )
52
        return result if result else None
×
53

UNCOV
54
    def to_embedcfg(self) -> bytes:
×
55
        data = {
×
56
            "Patterns": dict(self.patterns),
57
            "Files": dict(self.files),
58
        }
59
        return json.dumps(data).encode("utf-8")
×
60

UNCOV
61
    def __bool__(self) -> bool:
×
62
        return bool(self.patterns) or bool(self.files)
×
63

UNCOV
64
    def merge(self, other: EmbedConfig) -> EmbedConfig:
×
65
        """Merge two EmbedConfig's into one.
66

67
        Overlapping keys must have the same values.
68
        """
UNCOV
69
        overlapping_patterns_keys = set(self.patterns.keys()) & set(other.patterns.keys())
×
UNCOV
70
        for key in overlapping_patterns_keys:
×
UNCOV
71
            if self.patterns[key] != other.patterns[key]:
×
UNCOV
72
                raise AssertionError(
×
73
                    "Unable to merge conflicting golang file embed configurations. This should not have occurred. "
74
                    "Please open an issue at https://github.com/pantsbuild/pants/issues/new/choose "
75
                    "with the following information: "
76
                    f"Patterns Key: {key}; Left: {self.patterns[key]}; Right: {other.patterns[key]} "
77
                )
78

UNCOV
79
        overlapping_files_keys = set(self.files.keys()) & set(other.files.keys())
×
UNCOV
80
        for key in overlapping_files_keys:
×
UNCOV
81
            if self.files[key] != other.files[key]:
×
82
                raise AssertionError(
×
83
                    "Unable to merge conflicting golang file embed configurations. This should not have occurred. "
84
                    "Please open an issue at https://github.com/pantsbuild/pants/issues/new/choose "
85
                    "with the following information: "
86
                    f"Files Key: {key}; Left: {self.patterns[key]}; Right: {other.patterns[key]} "
87
                )
88

UNCOV
89
        return EmbedConfig(
×
90
            patterns={**self.patterns, **other.patterns},
91
            files={**self.files, **other.files},
92
        )
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