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

pantsbuild / pants / 19529437518

20 Nov 2025 07:44AM UTC coverage: 78.884% (-1.4%) from 80.302%
19529437518

push

github

web-flow
nfpm.native_libs: Add RPM package depends from packaged pex_binaries (#22899)

## PR Series Overview

This is the second in a series of PRs that introduces a new backend:
`pants.backend.npm.native_libs`
Initially, the backend will be available as:
`pants.backend.experimental.nfpm.native_libs`

I proposed this new backend (originally named `bindeps`) in discussion
#22396.

This backend will inspect ELF bin/lib files (like `lib*.so`) in packaged
contents (for this PR series, only in `pex_binary` targets) to identify
package dependency metadata and inject that metadata on the relevant
`nfpm_deb_package` or `nfpm_rpm_package` targets. Effectively, it will
provide an approximation of these native packager features:
- `rpm`: `rpmdeps` + `elfdeps`
- `deb`: `dh_shlibdeps` + `dpkg-shlibdeps` (These substitute
`${shlibs:Depends}` in debian control files have)

### Goal: Host-agnostic package builds

This pants backend is designed to be host-agnostic, like
[nFPM](https://nfpm.goreleaser.com/).

Native packaging tools are often restricted to a single release of a
single distro. Unlike native package builders, this new pants backend
does not use any of those distro-specific or distro-release-specific
utilities or local package databases. This new backend should be able to
run (help with building deb and rpm packages) anywhere that pants can
run (MacOS, rpm linux distros, deb linux distros, other linux distros,
docker, ...).

### Previous PRs in series

- #22873

## PR Overview

This PR adds rules in `nfpm.native_libs` to add package dependency
metadata to `nfpm_rpm_package`. The 2 new rules are:

- `inject_native_libs_dependencies_in_package_fields`:

    - An implementation of the polymorphic rule `inject_nfpm_package_fields`.
      This rule is low priority (`priority = 2`) so that in-repo plugins can
      override/augment what it injects. (See #22864)

    - Rule logic overview:
        - find any pex_binaries that will be packaged in an `nfpm_rpm_package`
   ... (continued)

96 of 118 new or added lines in 3 files covered. (81.36%)

910 existing lines in 53 files now uncovered.

73897 of 93678 relevant lines covered (78.88%)

3.21 hits per line

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

77.78
/src/python/pants/backend/helm/goals/package.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
3✔
5

6
import logging
3✔
7
import os
3✔
8
from dataclasses import dataclass
3✔
9

10
from pants.backend.helm.target_types import HelmChartFieldSet, HelmChartOutputPathField
3✔
11
from pants.backend.helm.util_rules.chart import HelmChartRequest, get_helm_chart
3✔
12
from pants.backend.helm.util_rules.chart_metadata import HelmChartMetadata
3✔
13
from pants.backend.helm.util_rules.tool import HelmProcess
3✔
14
from pants.core.goals.package import BuiltPackage, BuiltPackageArtifact, PackageFieldSet
3✔
15
from pants.engine.fs import AddPrefix, CreateDigest, Directory, RemovePrefix
3✔
16
from pants.engine.intrinsics import create_digest, digest_to_snapshot, remove_prefix
3✔
17
from pants.engine.process import execute_process_or_raise
3✔
18
from pants.engine.rules import collect_rules, concurrently, implicitly, rule
3✔
19
from pants.engine.unions import UnionRule
3✔
20
from pants.util.logging import LogLevel
3✔
21

22
logger = logging.getLogger(__name__)
3✔
23

24

25
@dataclass(frozen=True)
3✔
26
class BuiltHelmArtifact(BuiltPackageArtifact):
3✔
27
    info: HelmChartMetadata | None = None
3✔
28

29
    @classmethod
3✔
30
    def create(cls, relpath: str, info: HelmChartMetadata) -> BuiltHelmArtifact:
3✔
UNCOV
31
        return cls(
×
32
            relpath=relpath,
33
            info=info,
34
            extra_log_lines=(f"Built Helm chart artifact: {relpath}",),
35
        )
36

37

38
@dataclass(frozen=True)
3✔
39
class HelmPackageFieldSet(HelmChartFieldSet, PackageFieldSet):
3✔
40
    output_path: HelmChartOutputPathField
3✔
41

42

43
@rule(desc="Package Helm chart", level=LogLevel.DEBUG)
3✔
44
async def run_helm_package(field_set: HelmPackageFieldSet) -> BuiltPackage:
3✔
45
    result_dir = "__out"
×
46

47
    chart, result_digest = await concurrently(
×
48
        get_helm_chart(HelmChartRequest(field_set), **implicitly()),
49
        create_digest(CreateDigest([Directory(result_dir)])),
50
    )
51

52
    process_output_file = os.path.join(result_dir, f"{chart.info.artifact_name}.tgz")
×
53

54
    process_result = await execute_process_or_raise(
×
55
        **implicitly(
56
            HelmProcess(
57
                argv=["package", chart.name, "-d", result_dir],
58
                input_digest=result_digest,
59
                extra_immutable_input_digests=chart.immutable_input_digests,
60
                output_files=(process_output_file,),
61
                description=f"Packaging Helm chart: {field_set.address}",
62
            )
63
        )
64
    )
65

66
    stripped_output_digest = await remove_prefix(
×
67
        RemovePrefix(process_result.output_digest, result_dir)
68
    )
69

70
    final_snapshot = await digest_to_snapshot(
×
71
        **implicitly(
72
            AddPrefix(
73
                stripped_output_digest, field_set.output_path.value_or_default(file_ending=None)
74
            )
75
        )
76
    )
77
    return BuiltPackage(
×
78
        final_snapshot.digest,
79
        artifacts=tuple(
80
            BuiltHelmArtifact.create(file, chart.info) for file in final_snapshot.files
81
        ),
82
    )
83

84

85
def rules():
3✔
86
    return [*collect_rules(), UnionRule(PackageFieldSet, HelmPackageFieldSet)]
3✔
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