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

pantsbuild / pants / 19250292619

11 Nov 2025 12:09AM UTC coverage: 77.865% (-2.4%) from 80.298%
19250292619

push

github

web-flow
flag non-runnable targets used with `code_quality_tool` (#22875)

2 of 5 new or added lines in 2 files covered. (40.0%)

1487 existing lines in 72 files now uncovered.

71448 of 91759 relevant lines covered (77.86%)

3.22 hits per line

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

98.63
/src/python/pants/backend/nfpm/target_types.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
7✔
5

6
from pants.backend.nfpm.fields.all import (
7✔
7
    NfpmArchField,
8
    NfpmDependencies,
9
    NfpmHomepageField,
10
    NfpmLicenseField,
11
    NfpmOutputPathField,
12
    NfpmPackageMtimeField,
13
    NfpmPackageNameField,
14
    NfpmPlatformField,
15
)
16
from pants.backend.nfpm.fields.apk import (
7✔
17
    NfpmApkDependsField,
18
    NfpmApkMaintainerField,
19
    NfpmApkProvidesField,
20
    NfpmApkReplacesField,
21
    NfpmApkScriptsField,
22
)
23
from pants.backend.nfpm.fields.archlinux import (
7✔
24
    NfpmArchlinuxConflictsField,
25
    NfpmArchlinuxDependsField,
26
    NfpmArchlinuxPackagerField,
27
    NfpmArchlinuxPkgbaseField,
28
    NfpmArchlinuxProvidesField,
29
    NfpmArchlinuxReplacesField,
30
    NfpmArchlinuxScriptsField,
31
)
32
from pants.backend.nfpm.fields.contents import (
7✔
33
    NfpmContentDirDstField,
34
    NfpmContentDirsField,
35
    NfpmContentDirsOverridesField,
36
    NfpmContentDstField,
37
    NfpmContentFileGroupField,
38
    NfpmContentFileModeField,
39
    NfpmContentFileMtimeField,
40
    NfpmContentFileOwnerField,
41
    NfpmContentFilesField,
42
    NfpmContentFileSourceField,
43
    NfpmContentFilesOverridesField,
44
    NfpmContentSrcField,
45
    NfpmContentSymlinkDstField,
46
    NfpmContentSymlinksField,
47
    NfpmContentSymlinksOverridesField,
48
    NfpmContentSymlinkSrcField,
49
    NfpmContentTypeField,
50
)
51
from pants.backend.nfpm.fields.deb import (
7✔
52
    NfpmDebBreaksField,
53
    NfpmDebCompressionField,
54
    NfpmDebConflictsField,
55
    NfpmDebDependsField,
56
    NfpmDebFieldsField,
57
    NfpmDebMaintainerField,
58
    NfpmDebPreDependsField,
59
    NfpmDebPriorityField,
60
    NfpmDebProvidesField,
61
    NfpmDebRecommendsField,
62
    NfpmDebReplacesField,
63
    NfpmDebScriptsField,
64
    NfpmDebSectionField,
65
    NfpmDebSuggestsField,
66
    NfpmDebTriggersField,
67
)
68
from pants.backend.nfpm.fields.rpm import (
7✔
69
    NfpmRpmCompressionField,
70
    NfpmRpmConflictsField,
71
    NfpmRpmDependsField,
72
    NfpmRpmGhostContents,
73
    NfpmRpmGroupField,
74
    NfpmRpmPackagerField,
75
    NfpmRpmPrefixesField,
76
    NfpmRpmProvidesField,
77
    NfpmRpmRecommendsField,
78
    NfpmRpmReplacesField,
79
    NfpmRpmScriptsField,
80
    NfpmRpmSuggestsField,
81
    NfpmRpmSummaryField,
82
    NfpmRpmVendorField,
83
)
84
from pants.backend.nfpm.fields.version import (
7✔
85
    NfpmVersionEpochField,
86
    NfpmVersionField,
87
    NfpmVersionMetadataField,
88
    NfpmVersionPrereleaseField,
89
    NfpmVersionReleaseField,
90
    NfpmVersionSchemaField,
91
)
92
from pants.engine.target import (
7✔
93
    COMMON_TARGET_FIELDS,
94
    InvalidTargetException,
95
    Target,
96
    TargetGenerator,
97
)
98
from pants.util.docutil import doc_url
7✔
99
from pants.util.strutil import help_text
7✔
100

101
# Fields required to satisfy NfpmPackageFieldSet on all NfpmPackageTarget subclasses.
102
COMMON_NFPM_PACKAGE_FIELDS = (
7✔
103
    *COMMON_TARGET_FIELDS,  # tags, description
104
    NfpmOutputPathField,
105
    NfpmPackageMtimeField,
106
    NfpmDependencies,
107
    # NfpmPackageNameField is in the packager-specific lists of fields so that it ends up
108
    # in field_set.required_fields even though it is also required by NfpmPackageFieldSet.
109
)
110

111

112
class NfpmPackageTarget(Target):
7✔
113
    pass
7✔
114

115

116
# NB: The <packager>_FIELDS constants are used as Nfpm<packager>PackageFieldSet.required_fields,
117
# which is used when generating the nfpm config file. The field_set.nfpm_config method loops
118
# over required_fields, using the nfpm_alias class var on each field to construct the config.
119

120

121
APK_FIELDS = (
7✔
122
    NfpmPackageNameField,
123
    NfpmArchField,
124
    # version fields (apk does NOT get: version_metadata or epoch)
125
    NfpmVersionField,
126
    NfpmVersionSchemaField,
127
    NfpmVersionPrereleaseField,
128
    NfpmVersionReleaseField,
129
    # other package metadata fields
130
    NfpmHomepageField,
131
    NfpmLicenseField,
132
    NfpmApkMaintainerField,
133
    # package relationships
134
    NfpmApkReplacesField,
135
    NfpmApkProvidesField,
136
    NfpmApkDependsField,
137
    # content-related fields
138
    NfpmApkScriptsField,
139
)
140

141

142
class NfpmApkPackage(NfpmPackageTarget):
7✔
143
    alias = "nfpm_apk_package"
7✔
144
    core_fields = (
7✔
145
        *COMMON_NFPM_PACKAGE_FIELDS,
146
        *APK_FIELDS,
147
    )
148
    help = help_text(
7✔
149
        f"""
150
        An APK system package (Alpine Package Keeper) built by nFPM.
151

152
        This will not install the package, only create an .apk file
153
        that you can then distribute and install, e.g. via pkg.
154

155
        See {doc_url("nfpm-apk-package")}.
156
        """
157
    )
158

159

160
ARCHLINUX_FIELDS = (
7✔
161
    NfpmPackageNameField,
162
    NfpmArchField,
163
    # version fields (archlinux does NOT get: version_metadata)
164
    NfpmVersionField,
165
    NfpmVersionSchemaField,
166
    NfpmVersionPrereleaseField,
167
    NfpmVersionReleaseField,
168
    NfpmVersionEpochField,
169
    # other package metadata fields
170
    NfpmHomepageField,
171
    NfpmLicenseField,
172
    NfpmArchlinuxPackagerField,
173
    NfpmArchlinuxPkgbaseField,
174
    # package relationships
175
    NfpmArchlinuxReplacesField,
176
    NfpmArchlinuxProvidesField,
177
    NfpmArchlinuxDependsField,
178
    NfpmArchlinuxConflictsField,
179
    # content-related fields
180
    NfpmArchlinuxScriptsField,
181
)
182

183

184
class NfpmArchlinuxPackage(NfpmPackageTarget):
7✔
185
    alias = "nfpm_archlinux_package"
7✔
186
    core_fields = (
7✔
187
        *COMMON_NFPM_PACKAGE_FIELDS,
188
        *ARCHLINUX_FIELDS,
189
    )
190
    help = help_text(
7✔
191
        f"""
192
        An Archlinux system package built by nFPM.
193

194
        This will not install the package, only create an .tar.zst file
195
        that you can then distribute and install, e.g. via pkg.
196

197
        See {doc_url("nfpm-archlinux-package")}.
198
        """
199
    )
200

201

202
DEB_FIELDS = (
7✔
203
    NfpmPackageNameField,
204
    NfpmArchField,
205
    NfpmPlatformField,
206
    # version fields
207
    NfpmVersionField,
208
    NfpmVersionSchemaField,
209
    NfpmVersionPrereleaseField,
210
    NfpmVersionMetadataField,
211
    NfpmVersionReleaseField,
212
    NfpmVersionEpochField,
213
    # other package metadata fields
214
    NfpmHomepageField,
215
    NfpmLicenseField,  # not used by nFPM yet.
216
    NfpmDebMaintainerField,
217
    NfpmDebSectionField,
218
    NfpmDebPriorityField,
219
    # control files metadata
220
    NfpmDebFieldsField,
221
    NfpmDebTriggersField,
222
    # package relationships
223
    NfpmDebReplacesField,
224
    NfpmDebProvidesField,
225
    NfpmDebDependsField,
226
    NfpmDebPreDependsField,
227
    NfpmDebRecommendsField,
228
    NfpmDebSuggestsField,
229
    NfpmDebConflictsField,
230
    NfpmDebBreaksField,
231
    # how to build the package
232
    NfpmDebCompressionField,
233
    # content-related fields
234
    NfpmDebScriptsField,
235
)
236

237

238
class NfpmDebPackage(NfpmPackageTarget):
7✔
239
    alias = "nfpm_deb_package"
7✔
240
    core_fields = (
7✔
241
        *COMMON_NFPM_PACKAGE_FIELDS,
242
        *DEB_FIELDS,
243
    )
244
    help = help_text(
7✔
245
        f"""
246
        A Debian system package built by nFPM.
247

248
        This will not install the package, only create a .deb file
249
        that you can then distribute and install, e.g. via pkg.
250

251
        See {doc_url("nfpm-deb-package")}.
252
        """
253
    )
254

255

256
RPM_FIELDS = (
7✔
257
    NfpmPackageNameField,
258
    NfpmArchField,
259
    NfpmPlatformField,
260
    # version fields
261
    NfpmVersionField,
262
    NfpmVersionSchemaField,
263
    NfpmVersionPrereleaseField,
264
    NfpmVersionMetadataField,
265
    NfpmVersionReleaseField,
266
    NfpmVersionEpochField,
267
    # other package metadata fields
268
    NfpmHomepageField,
269
    NfpmLicenseField,
270
    NfpmRpmPackagerField,
271
    NfpmRpmVendorField,
272
    NfpmRpmGroupField,
273
    NfpmRpmSummaryField,
274
    NfpmRpmPrefixesField,
275
    # package relationships
276
    NfpmRpmReplacesField,
277
    NfpmRpmProvidesField,
278
    NfpmRpmDependsField,
279
    NfpmRpmRecommendsField,
280
    NfpmRpmSuggestsField,
281
    NfpmRpmConflictsField,
282
    # how to build the package
283
    NfpmRpmCompressionField,
284
    # content-related fields
285
    NfpmRpmScriptsField,
286
    NfpmRpmGhostContents,
287
)
288

289

290
class NfpmRpmPackage(NfpmPackageTarget):
7✔
291
    alias = "nfpm_rpm_package"
7✔
292
    core_fields = (
7✔
293
        *COMMON_NFPM_PACKAGE_FIELDS,
294
        *RPM_FIELDS,
295
    )
296
    help = help_text(
7✔
297
        f"""
298
        An RPM system package built by nFPM.
299

300
        This will not install the package, only create an .rpm file
301
        that you can then distribute and install, e.g. via pkg.
302

303
        See {doc_url("nfpm-rpm-package")}.
304
        """
305
    )
306

307

308
CONTENT_FILE_INFO_FIELDS = (
7✔
309
    NfpmContentFileOwnerField,
310
    NfpmContentFileGroupField,
311
    NfpmContentFileModeField,
312
    NfpmContentFileMtimeField,
313
)
314

315

316
class NfpmContentFile(Target):
7✔
317
    alias = "nfpm_content_file"
7✔
318
    core_fields = (
7✔
319
        *COMMON_TARGET_FIELDS,
320
        NfpmContentFileSourceField,
321
        NfpmDependencies,
322
        NfpmContentSrcField,
323
        NfpmContentDstField,
324
        NfpmContentTypeField,
325
        *CONTENT_FILE_INFO_FIELDS,
326
    )
327
    help = help_text(
7✔
328
        lambda: f"""
329
        A file (of any type) that should be copied into an nFPM package.
330

331
        The file comes from either the '{NfpmContentFileSourceField.alias}' field
332
        or from any of the targets listed in the '{NfpmDependencies.alias}' field.
333
        The file may be a workspace file, a generated file, or even a package.
334

335
        The '{NfpmContentSrcField}' field tells nFPM where the file is in the sandbox.
336
        The '{NfpmContentDstField}' field tells nFPM where the file should be installed
337
        by the nFPM-generated package.
338
        """
339
    )
340

341
    def validate(self) -> None:
7✔
342
        if self[NfpmContentFileSourceField].value is None and not (
1✔
343
            self[NfpmContentSrcField].value and self[NfpmDependencies].value
344
        ):
UNCOV
345
            raise InvalidTargetException(
×
346
                help_text(
347
                    f"""
348
                    The '{self.alias}' target {self.address} must either
349
                    define a source file in the '{NfpmContentFileSourceField.alias}' field
350
                    or specify a path in '{NfpmContentSrcField.alias}' that is provided
351
                    by one of the targets in the '{NfpmDependencies.alias}' field.
352
                    """
353
                )
354
            )
355

356

357
class NfpmContentFiles(TargetGenerator):
7✔
358
    alias = "nfpm_content_files"
7✔
359
    generated_target_cls = NfpmContentFile
7✔
360
    core_fields = (
7✔
361
        *COMMON_TARGET_FIELDS,
362
        NfpmContentFilesField,  # TODO: if given a "sources" field, what does this look like?
363
        NfpmContentFilesOverridesField,
364
    )
365
    copied_fields = COMMON_TARGET_FIELDS
7✔
366
    moved_fields = (
7✔
367
        NfpmDependencies,
368
        NfpmContentTypeField,
369
        *CONTENT_FILE_INFO_FIELDS,
370
    )
371
    help = help_text(
7✔
372
        f"""
373
        Multiple files that should be copied into an nFPM package.
374

375
        Pass the list of ('{NfpmContentSrcField.alias}', '{NfpmContentDstField.alias}')
376
        file tuples in the '{NfpmContentFilesField.alias}' field.
377
        The '{NfpmContentSrcField.alias}' files must be provided by or generated by
378
        the targets in '{NfpmDependencies.alias}'.
379
        """
380
    )
381

382

383
class NfpmContentSymlink(Target):
7✔
384
    alias = "nfpm_content_symlink"
7✔
385
    core_fields = (
7✔
386
        *COMMON_TARGET_FIELDS,
387
        # Modeled w/o dependencies for now (feel free to add later).
388
        NfpmContentSymlinkSrcField,  # path on package install target
389
        NfpmContentSymlinkDstField,  # path on package install target
390
        *CONTENT_FILE_INFO_FIELDS,
391
    )
392
    help = help_text(
7✔
393
        """
394
        A symlink in an nFPM package (created on package install).
395
        """
396
    )
397

398

399
class NfpmContentSymlinks(TargetGenerator):
7✔
400
    alias = "nfpm_content_symlinks"
7✔
401
    generated_target_cls = NfpmContentSymlink
7✔
402
    core_fields = (
7✔
403
        *COMMON_TARGET_FIELDS,
404
        # Modeled w/o dependencies for now (feel free to add later).
405
        NfpmContentSymlinksField,
406
        NfpmContentSymlinksOverridesField,
407
    )
408
    copied_fields = COMMON_TARGET_FIELDS
7✔
409
    moved_fields = CONTENT_FILE_INFO_FIELDS
7✔
410
    help = help_text(
7✔
411
        f"""
412
        Multiple symlinks in an nFPM package (created on package install).
413

414
        Pass the list of ('{NfpmContentSymlinkSrcField.alias}', '{NfpmContentSymlinkDstField.alias}')
415
        symlink tuples in the '{NfpmContentSymlinksField.alias}' field.
416

417
        Note that '{NfpmContentSymlinkSrcField.alias}' is commonly known as the
418
        symlink "target" and '{NfpmContentSymlinkDstField.alias}' is the path
419
        to the symlink itself, also known as the symlink "name".
420
        """
421
    )
422

423

424
class NfpmContentDir(Target):
7✔
425
    alias = "nfpm_content_dir"
7✔
426
    core_fields = (
7✔
427
        *COMMON_TARGET_FIELDS,
428
        # Modeled w/o dependencies for now (feel free to add later).
429
        NfpmContentDirDstField,  # path on package install target
430
        # nFPM also supports passing a real dir in "src", from which it
431
        # pulls the mode and mtime. But, pants creates the sandbox for nFPM,
432
        # so pants would have to explicitly set mode/mtime on sandboxed dirs.
433
        # So, the pants UX simplifies and only supports BUILD-defined values.
434
        *CONTENT_FILE_INFO_FIELDS,
435
    )
436
    help = help_text(
7✔
437
        """
438
        A directory in an nFPM package (created on package install).
439
        """
440
    )
441

442

443
class NfpmContentDirs(TargetGenerator):
7✔
444
    alias = "nfpm_content_dirs"
7✔
445
    generated_target_cls = NfpmContentDir
7✔
446
    core_fields = (
7✔
447
        *COMMON_TARGET_FIELDS,
448
        # Modeled w/o dependencies for now (feel free to add later).
449
        NfpmContentDirsField,
450
        NfpmContentDirsOverridesField,
451
    )
452
    copied_fields = COMMON_TARGET_FIELDS
7✔
453
    moved_fields = CONTENT_FILE_INFO_FIELDS
7✔
454
    help = help_text(
7✔
455
        """
456
        Multiple directories in an nFPM package (created on package install).
457
        """
458
    )
459

460

461
def target_types():
7✔
462
    return [
6✔
463
        NfpmApkPackage,
464
        NfpmArchlinuxPackage,
465
        NfpmDebPackage,
466
        NfpmRpmPackage,
467
        NfpmContentFile,
468
        NfpmContentFiles,
469
        NfpmContentSymlink,
470
        NfpmContentSymlinks,
471
        NfpmContentDir,
472
        NfpmContentDirs,
473
    ]
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