• 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/nfpm/fields/apk.py
1
# Copyright 2023 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
from typing import ClassVar
×
7

UNCOV
8
from pants.backend.nfpm.fields._relationships import NfpmPackageRelationshipsField
×
UNCOV
9
from pants.backend.nfpm.fields.all import NfpmDependencies
×
UNCOV
10
from pants.backend.nfpm.fields.scripts import NfpmPackageScriptsField
×
UNCOV
11
from pants.engine.target import StringField
×
UNCOV
12
from pants.util.frozendict import FrozenDict
×
UNCOV
13
from pants.util.strutil import help_text
×
14

15
# These fields are used by the `nfpm_apk_package` target
16
# Some fields will be duplicated by other package types which
17
# allows the help string to be packager-specific.
18

19

UNCOV
20
class NfpmApkMaintainerField(StringField):
×
UNCOV
21
    nfpm_alias = "maintainer"
×
UNCOV
22
    alias: ClassVar[str] = nfpm_alias
×
UNCOV
23
    help = help_text(
×
24
        # based in part on the docs at:
25
        # https://nfpm.goreleaser.com/configuration/#reference
26
        lambda: f"""
27
        The name and email address of the packager or packager organization.
28

29
        The '{NfpmApkMaintainerField.alias}' is used to identify who actually
30
        packaged the software, as opposed to the author of the software.
31

32
        The name is first, then the email address inside angle brackets `<>`
33
        (in RFC5322 format). For example: "Foo Bar <maintainer@example.com>"
34

35
        See: https://wiki.alpinelinux.org/wiki/Apk_spec#PKGINFO_Format
36
        """
37
    )
38
    # During signing nFPM parses with mail.ParseAddress() which uses RFC5322
39
    # (RFC 5322 supersedes RFC 2822 which supersedes RFC 822).
40
    # Otherwise, nFPM embeds this string as-is in the apk package.
41

42

UNCOV
43
class NfpmApkReplacesField(NfpmPackageRelationshipsField):
×
UNCOV
44
    nfpm_alias = "replaces"
×
UNCOV
45
    alias: ClassVar[str] = nfpm_alias
×
UNCOV
46
    help = help_text(
×
47
        lambda: f"""
48
        A list of packages whose files this package can take ownership of.
49

50
        WARNING: This field does NOT have the same semantics as "replaces" in
51
        other packaging systems. This field deals with allowing packages that
52
        want to provide the same file to be installed at the same time.
53

54
        If another package '{NfpmApkProvidesField.alias}' the same file, and that
55
        package is in the '{NfpmApkReplacesField.alias}' list, then the apk
56
        installer will allow both packages to be installed and record that this
57
        package owns the conflicting files.
58

59
        This field takes a simple list of package names, like this:
60

61
          - "bash"
62
          - "git"
63
          - "pkgconfig"
64

65
        See:
66
        https://wiki.alpinelinux.org/wiki/Apk_spec#PKGINFO_Format
67
        https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#replaces
68
        """
69
    )
70

71

UNCOV
72
class NfpmApkProvidesField(NfpmPackageRelationshipsField):
×
UNCOV
73
    nfpm_alias = "provides"
×
UNCOV
74
    alias: ClassVar[str] = nfpm_alias
×
UNCOV
75
    help = help_text(
×
76
        lambda: f"""
77
        A list of (virtual) packages or other things that this package provides.
78

79
        The '{NfpmApkProvidesField.alias}' field takes a variety of different formats.
80
        You can provide package alternatives, virtual packages, or various packaged
81
        components (commands, shared objects, pkg-config, etc). A "provides" entry
82
        with a version specifier defines an alternative name for this package that
83
        will conflict with any other package that has or provides that name.
84
        A "provides" entry without a version specifier defines a virtual package
85
        that does not create conflicts; multiple packages with the same virtual
86
        package (no version specifier) can be installed at the same time.
87

88
        Sadly, the format of this field is not very well documented, so you may
89
        have to open other packages to find examples of how to use it. The format
90
        seems to be very similar to the '{NfpmApkDependsField.alias}' field.
91

92
        Here are some examples extracted a variety of random packages:
93

94
          - "cmd:bash=5.2.15-r0"
95
          - "cmd:git=2.38.5-r0"
96
          - "cmd:gio=2.74.6-r0"
97
          - "so:libgio-2.0.so.0=0.7400.6"
98
          - "so:libglib-2.0.so.0=0.7400.6"
99
          - "py3.10:pkgconfig=1.5.5-r1"
100
          - "pc:libpkgconf=1.9.4"
101
          - "pkgconfig=1"
102

103
        See:
104
        https://wiki.alpinelinux.org/wiki/Apk_spec#PKGINFO_Format
105
        https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#provides
106
        """
107
    )
108

109

UNCOV
110
class NfpmApkDependsField(NfpmPackageRelationshipsField):
×
UNCOV
111
    nfpm_alias = "depends"
×
UNCOV
112
    alias: ClassVar[str] = nfpm_alias
×
UNCOV
113
    help = help_text(
×
114
        lambda: f"""
115
        List of package dependencies or conflicts (for package installers).
116

117
        To specify a conflicting dependency (a package that cannot be installed
118
        at the same time), prefix the entry with a `!`.
119

120
        This field is named "{NfpmApkDependsField.alias}" because that is the
121
        term used by nFPM. Alpine linux uses both "depends" and "depend", which
122
        are used in APKBUILD and PKGINFO files respectively. The `abuild` tool
123
        uses the APKBUILD "depends" var--and other build-time introspection--to
124
        generate the PKGINFO "depend" var that ends up in the final apk package.
125

126
        The Alpine documentation says not to include shared-object dependencies
127
        in the APKBUILD "depends" var, but that warning does not apply to this
128
        field. Even though this field is named "{NfpmApkDependsField.alias}",
129
        nFPM uses it to build the PKGINFO "depend" var, so you SHOULD include any
130
        shared-object dependencies in this list.
131

132
        The '{NfpmApkDependsField.alias}' field takes a variety of different formats.
133
        You can depend on packages, absolute paths, shared objects, pkg-configs,
134
        and possibly other things. Sadly, that format is not very well documented,
135
        so you may have to open other packages to find examples of how to use
136
        pkg-config deps (which have a `pc:` prefix), and any other less common
137
        syntax. Here are some examples extracted a variety of random packages:
138

139
        Example package dependencies (which do not have a prefix):
140

141
          - "git"
142
          - "git=2.40.1-r0"
143

144
        Example absolute path dependencies (which start with `/`):
145

146
          - "/bin/sh"
147

148
        Example shared object dependencies (which have a `so:` prefix):
149

150
          - "so:libc.musl-x86_64.so.1"
151
          - "so:libcurl.so.4"
152
          - "so:libpcre2-8.so.0"
153
          - "so:libz.so.1"
154

155
        WARNING: This is NOT the same as the 'dependencies' field!
156
        It does not accept pants-style dependencies like target addresses.
157

158
        See: https://wiki.alpinelinux.org/wiki/Apk_spec#PKGINFO_Format
159

160
        See also the related (but different!) "depends" var in APKBUILD:
161
        https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#depends
162
        https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package#depends_&_makedepends
163
        """
164
        # apkbuild uses the 'scanelf' binary, and the 'scan_shared_objects',
165
        # 'find_scanelf_paths', and 'trace_apk_deps' functions in abuild.in
166
        # to autodetect deps when generating the PKGINFO file.
167
        # https://git.alpinelinux.org/abuild/tree/abuild.in
168
        # nFPM does not do that.
169
        # TODO: maybe analyze the pants-built artifacts to generate this like abuild does
170
    )
171

172

UNCOV
173
class NfpmApkScriptsField(NfpmPackageScriptsField):
×
UNCOV
174
    nfpm_aliases: ClassVar[FrozenDict[str, str]] = FrozenDict(
×
175
        {
176
            **NfpmPackageScriptsField.nfpm_aliases,
177
            "preupgrade": "apk.scripts.preupgrade",
178
            "postupgrade": "apk.scripts.postupgrade",
179
        }
180
    )
UNCOV
181
    help = help_text(
×
182
        f"""
183
        Map of install script source files for the APK package.
184

185
        This maps the script type (key) to the script source file (value).
186
        Each of the script source file(s) must be provided via '{NfpmDependencies.alias}'.
187
        The script types are the terms used by nFPM. For reference, Alpine Linux
188
        uses the following terms in the APKBUILD file instead:
189

190
        | nFPM term   | APKBUILD term  |
191
        +-------------+----------------+
192
        | preinstall  | pre-install    |
193
        | postinstall | post-install   |
194
        | preupgrade  | pre-upgrade    |
195
        | postupgrade | post-upgrade   |
196
        | preremove   | pre-deinstall  |
197
        | postremove  | post-deinstall |
198

199
        Please consult the Alpine Linux docs to understand when `apk` will run
200
        each of these scripts, how it handles a failure, and what failure means
201
        for the lifecycle of the package `apk` is working on.
202

203
        See:
204
        https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#install
205
        https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package#install
206
        https://wiki.alpinelinux.org/wiki/Apk_spec#Binary_Format
207
        """
208
    )
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