• 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

92.11
/src/python/pants/engine/internals/engine_testutil.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
import re
1✔
7
from collections.abc import Callable
1✔
8
from dataclasses import dataclass, field
1✔
9

10
from pants.engine.streaming_workunit_handler import WorkunitsCallback
1✔
11

12

13
def assert_equal_with_printing(
1✔
14
    expected, actual, uniform_formatter: Callable[[str], str] | None = None
15
):
16
    """Asserts equality, but also prints the values so they can be compared on failure."""
17
    str_actual = str(actual)
1✔
18
    print("Expected:")
1✔
19
    print(expected)
1✔
20
    print("Actual:")
1✔
21
    print(str_actual)
1✔
22

23
    if uniform_formatter is not None:
1✔
UNCOV
24
        expected = uniform_formatter(expected)
×
UNCOV
25
        str_actual = uniform_formatter(str_actual)
×
26
    assert expected == str_actual
1✔
27

28

29
def remove_locations_from_traceback(trace: str) -> str:
1✔
30
    location_pattern = re.compile(r'"/.*", line \d+')
1✔
31
    address_pattern = re.compile(r"0x[0-9a-f]+")
1✔
32
    new_trace = location_pattern.sub("LOCATION-INFO", trace)
1✔
33
    new_trace = address_pattern.sub("0xEEEEEEEEE", new_trace)
1✔
34
    return new_trace
1✔
35

36

37
@dataclass
1✔
38
class WorkunitTracker(WorkunitsCallback):
1✔
39
    """This class records every non-empty batch of started and completed workunits received from the
40
    engine."""
41

42
    finished_workunit_chunks: list[list[dict]] = field(default_factory=list)
1✔
43
    started_workunit_chunks: list[list[dict]] = field(default_factory=list)
1✔
44
    finished: bool = False
1✔
45

46
    @property
1✔
47
    def can_finish_async(self) -> bool:
1✔
48
        return False
×
49

50
    def __call__(self, **kwargs) -> None:
1✔
51
        if kwargs["finished"] is True:
1✔
52
            self.finished = True
1✔
53

54
        started_workunits = kwargs.get("started_workunits")
1✔
55
        if started_workunits:
1✔
56
            self.started_workunit_chunks.append(started_workunits)
1✔
57

58
        completed_workunits = kwargs.get("completed_workunits")
1✔
59
        if completed_workunits:
1✔
60
            self.finished_workunit_chunks.append(completed_workunits)
1✔
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