• 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

97.56
/src/python/pants/option/scope.py
1
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from dataclasses import dataclass
11✔
5
from typing import Any, cast
11✔
6

7
from pants.option.option_value_container import OptionValueContainer
11✔
8

9
GLOBAL_SCOPE = ""
11✔
10
GLOBAL_SCOPE_CONFIG_SECTION = "GLOBAL"
11✔
11

12

13
def normalize_scope(scope: str):
11✔
14
    return scope.lower().replace("-", "_")
11✔
15

16

17
@dataclass(frozen=True)
11✔
18
class Scope:
11✔
19
    """An options scope."""
20

21
    scope: str
11✔
22

23

24
@dataclass(frozen=True, order=True)
11✔
25
class ScopeInfo:
11✔
26
    """Information about a scope."""
27

28
    scope: str
11✔
29
    subsystem_cls: type[Any] | None = None
11✔
30
    # A ScopeInfo may have a deprecated_scope (from its associated subsystem_cls), which represents
31
    # a previous/deprecated name for a current/non-deprecated ScopeInfo. It may also be directly
32
    # deprecated via this `removal_version`, which allows for the deprecation of an entire scope.
33
    removal_version: str | None = None
11✔
34
    removal_hint: str | None = None
11✔
35

36
    # Command line goal scope flag.
37
    is_goal: bool = False
11✔
38

39
    # Builtin goals, such as `help` and `version` etc.
40
    is_builtin: bool = False
11✔
41

42
    # Auxiliary goals, such as the `experimental-bsp` goal.
43
    is_auxiliary: bool = False
11✔
44

45
    @property
11✔
46
    def description(self) -> str:
11✔
47
        return cast(str, self._subsystem_cls_attr("help"))
2✔
48

49
    @property
11✔
50
    def deprecated_scope(self) -> str | None:
11✔
51
        return cast(str | None, self._subsystem_cls_attr("deprecated_options_scope"))
11✔
52

53
    @property
11✔
54
    def deprecated_scope_removal_version(self) -> str | None:
11✔
UNCOV
55
        return cast(
×
56
            str | None,
57
            self._subsystem_cls_attr("deprecated_options_scope_removal_version"),
58
        )
59

60
    @property
11✔
61
    def scope_aliases(self) -> tuple[str, ...]:
11✔
62
        """BuiltinGoal subsystems may define aliases."""
63
        return cast(tuple[str, ...], self._subsystem_cls_attr("aliases", ()))
11✔
64

65
    def _subsystem_cls_attr(self, name: str, default=None):
11✔
66
        return getattr(self.subsystem_cls, name, default) if self.subsystem_cls else default
11✔
67

68

69
@dataclass(frozen=True)
11✔
70
class OptionsParsingSettings:
11✔
71
    """Information derived from options bootstrapping used to parse full options."""
72

73
    known_scope_infos: tuple[ScopeInfo, ...]
11✔
74
    allow_unknown_options: bool
11✔
75

76

77
@dataclass(frozen=True)
11✔
78
class ScopedOptions:
11✔
79
    """A wrapper around options selected for a particular Scope."""
80

81
    scope: Scope
11✔
82
    options: OptionValueContainer
11✔
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