• 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/target_types.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 pants.backend.nfpm.fields.all import (
×
7
    NfpmArchField,
8
    NfpmDependencies,
9
    NfpmHomepageField,
10
    NfpmLicenseField,
11
    NfpmOutputPathField,
12
    NfpmPackageMtimeField,
13
    NfpmPackageNameField,
14
    NfpmPlatformField,
15
)
UNCOV
16
from pants.backend.nfpm.fields.apk import (
×
17
    NfpmApkDependsField,
18
    NfpmApkMaintainerField,
19
    NfpmApkProvidesField,
20
    NfpmApkReplacesField,
21
    NfpmApkScriptsField,
22
)
UNCOV
23
from pants.backend.nfpm.fields.archlinux import (
×
24
    NfpmArchlinuxConflictsField,
25
    NfpmArchlinuxDependsField,
26
    NfpmArchlinuxPackagerField,
27
    NfpmArchlinuxPkgbaseField,
28
    NfpmArchlinuxProvidesField,
29
    NfpmArchlinuxReplacesField,
30
    NfpmArchlinuxScriptsField,
31
)
UNCOV
32
from pants.backend.nfpm.fields.contents import (
×
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
)
UNCOV
51
from pants.backend.nfpm.fields.deb import (
×
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
)
UNCOV
68
from pants.backend.nfpm.fields.rpm import (
×
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
)
UNCOV
84
from pants.backend.nfpm.fields.version import (
×
85
    NfpmVersionEpochField,
86
    NfpmVersionField,
87
    NfpmVersionMetadataField,
88
    NfpmVersionPrereleaseField,
89
    NfpmVersionReleaseField,
90
    NfpmVersionSchemaField,
91
)
UNCOV
92
from pants.engine.target import (
×
93
    COMMON_TARGET_FIELDS,
94
    InvalidTargetException,
95
    Target,
96
    TargetGenerator,
97
)
UNCOV
98
from pants.util.docutil import doc_url
×
UNCOV
99
from pants.util.strutil import help_text
×
100

101
# Fields required to satisfy NfpmPackageFieldSet on all NfpmPackageTarget subclasses.
UNCOV
102
COMMON_NFPM_PACKAGE_FIELDS = (
×
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

UNCOV
112
class NfpmPackageTarget(Target):
×
UNCOV
113
    pass
×
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

UNCOV
121
APK_FIELDS = (
×
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

UNCOV
142
class NfpmApkPackage(NfpmPackageTarget):
×
UNCOV
143
    alias = "nfpm_apk_package"
×
UNCOV
144
    core_fields = (
×
145
        *COMMON_NFPM_PACKAGE_FIELDS,
146
        *APK_FIELDS,
147
    )
UNCOV
148
    help = help_text(
×
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

UNCOV
160
ARCHLINUX_FIELDS = (
×
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

UNCOV
184
class NfpmArchlinuxPackage(NfpmPackageTarget):
×
UNCOV
185
    alias = "nfpm_archlinux_package"
×
UNCOV
186
    core_fields = (
×
187
        *COMMON_NFPM_PACKAGE_FIELDS,
188
        *ARCHLINUX_FIELDS,
189
    )
UNCOV
190
    help = help_text(
×
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

UNCOV
202
DEB_FIELDS = (
×
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

UNCOV
238
class NfpmDebPackage(NfpmPackageTarget):
×
UNCOV
239
    alias = "nfpm_deb_package"
×
UNCOV
240
    core_fields = (
×
241
        *COMMON_NFPM_PACKAGE_FIELDS,
242
        *DEB_FIELDS,
243
    )
UNCOV
244
    help = help_text(
×
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

UNCOV
256
RPM_FIELDS = (
×
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

UNCOV
290
class NfpmRpmPackage(NfpmPackageTarget):
×
UNCOV
291
    alias = "nfpm_rpm_package"
×
UNCOV
292
    core_fields = (
×
293
        *COMMON_NFPM_PACKAGE_FIELDS,
294
        *RPM_FIELDS,
295
    )
UNCOV
296
    help = help_text(
×
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

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

315

UNCOV
316
class NfpmContentFile(Target):
×
UNCOV
317
    alias = "nfpm_content_file"
×
UNCOV
318
    core_fields = (
×
319
        *COMMON_TARGET_FIELDS,
320
        NfpmContentFileSourceField,
321
        NfpmDependencies,
322
        NfpmContentSrcField,
323
        NfpmContentDstField,
324
        NfpmContentTypeField,
325
        *CONTENT_FILE_INFO_FIELDS,
326
    )
UNCOV
327
    help = help_text(
×
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

UNCOV
341
    def validate(self) -> None:
×
UNCOV
342
        if self[NfpmContentFileSourceField].value is None and not (
×
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

UNCOV
357
class NfpmContentFiles(TargetGenerator):
×
UNCOV
358
    alias = "nfpm_content_files"
×
UNCOV
359
    generated_target_cls = NfpmContentFile
×
UNCOV
360
    core_fields = (
×
361
        *COMMON_TARGET_FIELDS,
362
        NfpmContentFilesField,  # TODO: if given a "sources" field, what does this look like?
363
        NfpmContentFilesOverridesField,
364
    )
UNCOV
365
    copied_fields = COMMON_TARGET_FIELDS
×
UNCOV
366
    moved_fields = (
×
367
        NfpmDependencies,
368
        NfpmContentTypeField,
369
        *CONTENT_FILE_INFO_FIELDS,
370
    )
UNCOV
371
    help = help_text(
×
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

UNCOV
383
class NfpmContentSymlink(Target):
×
UNCOV
384
    alias = "nfpm_content_symlink"
×
UNCOV
385
    core_fields = (
×
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
    )
UNCOV
392
    help = help_text(
×
393
        """
394
        A symlink in an nFPM package (created on package install).
395
        """
396
    )
397

398

UNCOV
399
class NfpmContentSymlinks(TargetGenerator):
×
UNCOV
400
    alias = "nfpm_content_symlinks"
×
UNCOV
401
    generated_target_cls = NfpmContentSymlink
×
UNCOV
402
    core_fields = (
×
403
        *COMMON_TARGET_FIELDS,
404
        # Modeled w/o dependencies for now (feel free to add later).
405
        NfpmContentSymlinksField,
406
        NfpmContentSymlinksOverridesField,
407
    )
UNCOV
408
    copied_fields = COMMON_TARGET_FIELDS
×
UNCOV
409
    moved_fields = CONTENT_FILE_INFO_FIELDS
×
UNCOV
410
    help = help_text(
×
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

UNCOV
424
class NfpmContentDir(Target):
×
UNCOV
425
    alias = "nfpm_content_dir"
×
UNCOV
426
    core_fields = (
×
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
    )
UNCOV
436
    help = help_text(
×
437
        """
438
        A directory in an nFPM package (created on package install).
439
        """
440
    )
441

442

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

460

UNCOV
461
def target_types():
×
UNCOV
462
    return [
×
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