• 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/debian/rules.py
1
# Copyright 2022 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 collections.abc import Iterable
×
UNCOV
7
from dataclasses import dataclass
×
UNCOV
8
from pathlib import PurePath
×
9

UNCOV
10
from pants.backend.debian.target_types import (
×
11
    DebianInstallPrefix,
12
    DebianPackageDependencies,
13
    DebianSources,
14
)
UNCOV
15
from pants.core.goals.package import (
×
16
    BuiltPackage,
17
    BuiltPackageArtifact,
18
    OutputPathField,
19
    PackageFieldSet,
20
)
UNCOV
21
from pants.core.util_rules.system_binaries import BinaryPathRequest, TarBinary, find_binary
×
UNCOV
22
from pants.engine.fs import CreateDigest, FileEntry
×
UNCOV
23
from pants.engine.internals.graph import hydrate_sources
×
UNCOV
24
from pants.engine.intrinsics import create_digest, get_digest_entries
×
UNCOV
25
from pants.engine.process import Process, execute_process_or_raise
×
UNCOV
26
from pants.engine.rules import Rule, collect_rules, implicitly, rule
×
UNCOV
27
from pants.engine.target import HydrateSourcesRequest
×
UNCOV
28
from pants.engine.unions import UnionRule
×
UNCOV
29
from pants.util.logging import LogLevel
×
30

31

UNCOV
32
@dataclass(frozen=True)
×
UNCOV
33
class DebianPackageFieldSet(PackageFieldSet):
×
UNCOV
34
    required_fields = (DebianSources, DebianInstallPrefix, DebianPackageDependencies)
×
35

UNCOV
36
    sources_dir: DebianSources
×
UNCOV
37
    install_prefix: DebianInstallPrefix
×
UNCOV
38
    packages: DebianPackageDependencies
×
UNCOV
39
    output_path: OutputPathField
×
40

41

UNCOV
42
@rule(level=LogLevel.INFO)
×
UNCOV
43
async def package_debian_package(
×
44
    field_set: DebianPackageFieldSet, tar_binary_path: TarBinary
45
) -> BuiltPackage:
46
    dpkg_deb_path = await find_binary(
×
47
        BinaryPathRequest(
48
            binary_name="dpkg-deb",
49
            search_path=["/usr/bin"],
50
        ),
51
        **implicitly(),
52
    )
53
    if not dpkg_deb_path.first_path:
×
54
        raise OSError(f"Could not find the `{dpkg_deb_path.binary_name}` program in `/usr/bin`.")
×
55

56
    hydrated_sources = await hydrate_sources(
×
57
        HydrateSourcesRequest(field_set.sources_dir), **implicitly()
58
    )
59

60
    # Since all the sources are coming only from a single directory, it is
61
    # safe to pick an arbitrary file and get its root directory name.
62
    # Validation of the resolved files has been called on the target, so it is known that
63
    # snapshot.files isn't empty.
64
    sources_directory_name = PurePath(hydrated_sources.snapshot.files[0]).parts[0]
×
65

66
    result = await execute_process_or_raise(
×
67
        **implicitly(
68
            Process(
69
                argv=(
70
                    dpkg_deb_path.first_path.path,
71
                    "--build",
72
                    sources_directory_name,
73
                ),
74
                description="Create a Debian package from the produced packages.",
75
                input_digest=hydrated_sources.snapshot.digest,
76
                # dpkg-deb produces a file with the same name as the input directory
77
                output_files=(f"{sources_directory_name}.deb",),
78
                env={"PATH": str(PurePath(tar_binary_path.path).parent)},
79
            )
80
        )
81
    )
82
    # The output Debian package file needs to be renamed to match the output_path field.
83
    output_filename = field_set.output_path.value_or_default(
×
84
        file_ending="deb",
85
    )
86
    digest_entries = await get_digest_entries(result.output_digest)
×
87
    assert len(digest_entries) == 1
×
88
    result_file_entry = digest_entries[0]
×
89
    assert isinstance(result_file_entry, FileEntry)
×
90
    new_file = FileEntry(output_filename, result_file_entry.file_digest)
×
91

92
    final_result = await create_digest(CreateDigest([new_file]))
×
93
    return BuiltPackage(final_result, artifacts=(BuiltPackageArtifact(output_filename),))
×
94

95

UNCOV
96
def rules() -> Iterable[Rule | UnionRule]:
×
UNCOV
97
    return (
×
98
        *collect_rules(),
99
        UnionRule(PackageFieldSet, DebianPackageFieldSet),
100
    )
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