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

pantsbuild / pants / 23415513592

22 Mar 2026 11:51PM UTC coverage: 92.92% (-0.004%) from 92.924%
23415513592

Pull #23192

github

web-flow
Merge 1456ad98b into 30dee98e2
Pull Request #23192: strip common prefixes off ExternalTool archive paths

12 of 17 new or added lines in 2 files covered. (70.59%)

8 existing lines in 2 files now uncovered.

91521 of 98494 relevant lines covered (92.92%)

4.05 hits per line

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

78.95
/src/python/pants/ng/external_binary.py
1
# Copyright 2026 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
import json
1✔
5

6
from pants.core.util_rules.external_tool import ExternalToolRequest
1✔
7
from pants.engine.fs import DownloadFile
1✔
8
from pants.engine.internals.native_engine import FileDigest
1✔
9
from pants.engine.platform import Platform
1✔
10
from pants.ng.subsystem import ContextualSubsystem, option
1✔
11
from pants.util.resources import read_resource
1✔
12
from pants.util.strutil import softwrap
1✔
13

14

15
class ExternalBinary(ContextualSubsystem):
1✔
16
    @option(help="Version of the binary to use", default=lambda cls: cls.version_default)
17
    def version(self) -> str: ...
18

19
    exe_help = softwrap(
1✔
20
        """
21
        The executable to invoke: the downloaded file itself, or if the download is an archive,
22
        the relative path of the executable file within that archive."
23
        """
24
    )
25

26
    @classmethod
1✔
27
    def exe_default(cls) -> str:
1✔
28
        raise NotImplementedError("Subclasses must implement to provide the default executable")
×
29

30

31
    @option(help=exe_help, default=lambda cls: cls.exe_default)
32
    def exe(self) -> str: ...
33

34
    known_versions_help = softwrap(
1✔
35
        """
36
        A JSON string containing metadata of all known versions of the binary:
37

38
        {
39
            "version1": {
40
                "platform1": {
41
                    "url": ...
42
                    "sha256": ...
43
                    "size": ...
44
                },
45
                "platform2": {
46
                    "url": ...
47
                    "sha256": ...
48
                    "size": ...
49
                },
50
            }
51
            "version2": ...
52
        }
53

54
        Where each platform is one of `linux_x86_64`, `linux_arm64` or `macos_arm64`.
55

56
        Can be a string of the form `@dotted.pkg:filename.json` to load the value from
57
        that file in that package.
58
        """
59
    )
60

61
    @option(help=known_versions_help, default=lambda cls: cls.known_versions_default)
62
    def known_versions(self) -> str: ...
63

64
    def get_download_request(self) -> ExternalToolRequest:
1✔
65
        known_versions = self.known_versions
1✔
66
        if known_versions.startswith("@"):
1✔
67
            pkg, _, filename = known_versions[1:].partition(":")
×
UNCOV
68
            known_versions = read_resource(pkg, filename)
×
69
        metadata = json.loads(known_versions.strip())
1✔
70
        version = self.version
1✔
71
        version_metadata = metadata.get(version)
1✔
72
        if not version_metadata:
1✔
UNCOV
73
            raise ValueError(
×
74
                f"No metadata for version {version} in known_versions for tool {self.options_scope}."
75
            )
76
        platform = Platform.create_for_localhost().name
1✔
77
        platform_metadata = version_metadata.get(platform)
1✔
78
        if not platform_metadata:
1✔
UNCOV
79
            raise ValueError(
×
80
                f"No metadata for version {version} on platform {platform} in known_versions for tool {self.options_scope}."
81
            )
82
        url = platform_metadata.get("url")
1✔
83
        if not url:
1✔
UNCOV
84
            raise ValueError(
×
85
                f"No url for version {version} on platform {platform} in known_versions for tool {self.options_scope}."
86
            )
87
        sha256 = platform_metadata.get("sha256")
1✔
88
        if not sha256:
1✔
UNCOV
89
            raise ValueError(
×
90
                f"No sha256 for version {version} on platform {platform} in known_versions for tool {self.options_scope}."
91
            )
92
        size = platform_metadata.get("size")
1✔
93
        if not size:
1✔
UNCOV
94
            raise ValueError(
×
95
                f"No size for version {version} on platform {platform} in known_versions for tool {self.options_scope}."
96
            )
97
        return ExternalToolRequest(
1✔
98
            download_file_request=DownloadFile(url=url, expected_digest=FileDigest(sha256, size)),
99
            exe=self.exe,
100
            strip_common_path_prefix=True,
101
        )
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