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

pantsbuild / pants / 18812500213

26 Oct 2025 03:42AM UTC coverage: 80.284% (+0.005%) from 80.279%
18812500213

Pull #22804

github

web-flow
Merge 2a56fdb46 into 4834308dc
Pull Request #22804: test_shell_command: use correct default cache scope for a test's environment

29 of 31 new or added lines in 2 files covered. (93.55%)

1314 existing lines in 64 files now uncovered.

77900 of 97030 relevant lines covered (80.28%)

3.35 hits per line

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

98.48
/src/python/pants/backend/nfpm/fields/all.py
1
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
8✔
5

6
from enum import Enum
8✔
7
from typing import ClassVar
8✔
8

9
from pants.backend.nfpm.subsystem import MTIME_DEFAULT
8✔
10
from pants.core.goals.package import OutputPathField
8✔
11
from pants.engine.target import Dependencies, StringField
8✔
12
from pants.util.docutil import bin_name
8✔
13
from pants.util.strutil import help_text
8✔
14

15

16
class NfpmPackageNameField(StringField):
8✔
17
    nfpm_alias = "name"
8✔
18
    alias: ClassVar[str] = "package_name"
8✔
19
    required = True
8✔
20
    value: str
8✔
21
    help = help_text(
8✔
22
        """
23
        The package name.
24
        """
25
    )
26

27

28
class NfpmPackageMtimeField(StringField):
8✔
29
    nfpm_alias = ""  # field handled separately to call normalized_value
8✔
30
    alias: ClassVar[str] = "mtime"
8✔
31
    default = MTIME_DEFAULT
8✔
32
    help = help_text(
8✔
33
        f"""
34
        The file modification time as an RFC 3339 formatted string.
35

36
        For example: 2008-01-02T15:04:05Z
37

38
        The format is defined in RFC 3339: https://rfc-editor.org/rfc/rfc3339.html
39

40
        NOTE: This field does NOT set the mtime for package contents. It sets the
41
        build time in package metadata (for package types that have that metadata),
42
        as well as the file modification time for files that nFPM generates in the
43
        package. To set the mtime for package contents, use the `file_mtime` field
44
        on the relevant `nfpm_content_*` targets.
45

46
        The default value is {repr(MTIME_DEFAULT)}. You may also override
47
        the default value by setting `[nfpm].default_mtime` in `pants.toml`,
48
        or by setting the `SOURCE_DATE_EPOCH` environment variable.
49

50
        See also: https://reproducible-builds.org/docs/timestamps/
51
        """
52
    )
53

54
    def normalized_value(self, default_mtime: str | None):
8✔
55
        # This protects against an empty SOURCE_DATE_EPOCH var as mtime must not be empty.
UNCOV
56
        if self.value == self.default and default_mtime and self.value != default_mtime:
1✔
57
            return default_mtime
×
UNCOV
58
        return self.value
1✔
59

60

61
class NfpmDependencies(Dependencies):
8✔
62
    nfpm_alias = ""  # doesn't map directly to a nfpm.yaml field
8✔
63

64

65
class NfpmArch(Enum):
8✔
66
    # nFPM uses arch = GOARCH + GOARM. See: https://nfpm.goreleaser.com/goarch-to-pkg/
67
    # GOARCH possible values come from `okgoarch` var at:
68
    # https://github.com/golang/go/blob/go1.20.3/src/cmd/dist/build.go#L62-L79
69
    # GOARM possible values come from `goarm()` func at:
70
    # https://github.com/golang/go/blob/go1.20.3/src/internal/buildcfg/cfg.go#L77-L84
71
    _386 = "386"
8✔
72
    all = "all"  # not in `okgoarch`, but a conventionally accepted GOARCH value.
8✔
73
    amd64 = "amd64"
8✔
74
    arm5 = "arm5"  # GOARCH=arm GOARM=5
8✔
75
    arm6 = "arm6"  # GOARCH=arm GOARM=6
8✔
76
    arm7 = "arm7"  # GOARCH=arm GOARM=7
8✔
77
    arm64 = "arm64"  # GOARCH=arm64
8✔
78
    loong64 = "loong64"
8✔
79
    mips = "mips"
8✔
80
    mipsle = "mipsle"
8✔
81
    mips64 = "mips64"
8✔
82
    mips64le = "mips64le"
8✔
83
    ppc64 = "ppc64"
8✔
84
    ppc64le = "ppc64le"
8✔
85
    riscv64 = "riscv64"
8✔
86
    s390 = "s390"  # not in `okgoarch`; nFPM translates it to "s390x".
8✔
87
    s390x = "s390x"
8✔
88
    sparc64 = "sparc64"
8✔
89
    wasm = "wasm"
8✔
90

91

92
class NfpmArchField(StringField):
8✔
93
    nfpm_alias = "arch"
8✔
94
    alias: ClassVar[str] = nfpm_alias
8✔
95
    # valid_choices = NfpmArch  # no valid_choices to support pass-through values.
96
    default = NfpmArch.amd64.value  # based on nFPM default
8✔
97
    help = help_text(
8✔
98
        f"""
99
        The package architecture.
100

101
        This should be a valid GOARCH value (or GOARCH+GOARM) that nFPM can
102
        convert into the package-specific equivalent. Otherwise, pants tells
103
        nFPM to use this value as-is.
104

105
        nFPM conversion from GOARCH to package-specific value is documented here:
106
        https://nfpm.goreleaser.com/goarch-to-pkg/
107

108
        Use one of these values unless you need nFPM to use your value as-is:
109
        `{" | ".join(repr(arch.value) for arch in NfpmArch.__members__.values())}`
110
        """
111
    )
112

113

114
class NfpmPlatformField(StringField):
8✔
115
    nfpm_alias = "platform"
8✔
116
    alias: ClassVar[str] = nfpm_alias
8✔
117
    # no valid_choices to support pass-through values.
118
    default = "linux"  # based on nFPM default
8✔
119
    help = help_text(
8✔
120
        """
121
        The package platform or OS.
122

123
        You probably do not need to change the package's OS. nFPM is designed
124
        with the assumption that this is a GOOS value (since nFPM is part of the
125
        "goreleaser" project). But, nFPM does not do much with it.
126

127
        For archlinux and apk, the only valid value is 'linux'.
128
        For deb, this can be used as part of the 'Architecture' entry.
129
        For rpm, this populates the "OS" tag.
130
        """
131
    )
132

133

134
class NfpmHomepageField(StringField):
8✔
135
    nfpm_alias = "homepage"
8✔
136
    alias: ClassVar[str] = nfpm_alias
8✔
137
    help = help_text(
8✔
138
        lambda: f"""
139
        The URL of this package's homepage like "https://example.com".
140

141
        This field is named "{NfpmHomepageField.alias}" instead of "url" because
142
        that is the term used by nFPM, which adopted the term from deb packaging.
143
        The term "url" is used by apk, archlinux, and rpm packaging.
144
        """
145
    )
146

147

148
class NfpmLicenseField(StringField):
8✔
149
    nfpm_alias = "license"
8✔
150
    alias: ClassVar[str] = nfpm_alias
8✔
151
    help = help_text(
8✔
152
        """
153
        The license of this package.
154

155
        Where possible, please try to use the SPDX license identifiers (for
156
        example "Apache-2.0", "BSD-3-Clause", "GPL-3.0-or-later", or "MIT"):
157
        https://spdx.org/licenses/
158

159
        For more complex cases, where the package includes software with multiple
160
        licenses, consider using an SPDX license expression:
161
        https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/
162

163
        See also these rpm-specific descriptions of how to set this field (this
164
        is helpful info even if you are not using rpm):
165
        https://docs.fedoraproject.org/en-US/legal/license-field/
166

167
        nFPM does not yet generate the debian/copyright file, so this field is
168
        technically unused for now. Even for deb, we recommend using this field
169
        to document the software license for this package. See also these pages
170
        about specifying a license for deb packaging:
171
        https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/#license-specification
172
        https://wiki.debian.org/Proposals/CopyrightFormat#Differences_between_DEP5_and_SPDX
173
        """
174
    )
175

176

177
class NfpmOutputPathField(OutputPathField):
8✔
178
    nfpm_alias = ""
8✔
179
    help = help_text(
8✔
180
        f"""
181
        Where the built directory tree should be located.
182

183
        If undefined, this will use the path to the BUILD file, followed by the target name.
184
        For example, `src/project/packaging:rpm` would be `src.project.packaging/rpm/`.
185

186
        Regardless of whether you use the default or set this field, the package's file name
187
        will have the packaging system's conventional filename (as understood by nFPM).
188
        So, an rpm using the default for this field, the target `src/project/packaging:rpm`
189
        might have a final path like `src.project.packaging/rpm/projectname-1.2.3-1.x86_64.rpm`.
190
        Similarly, for deb, the target `src/project/packaging:deb` might have a final path like
191
        `src.project.packaging/deb/projectname_1.2.3+git-1_x86_64.deb`. The other packagers
192
        have their own formats as well.
193

194
        When running `{bin_name()} package`, this path will be prefixed by `--distdir` (e.g. `dist/`).
195

196
        Warning: setting this value risks naming collisions with other package targets you may have.
197
        """
198
    )
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

© 2025 Coveralls, Inc