• 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/tools/trufflehog/rules.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
"""Generates trufflehog rules."""
4

UNCOV
5
from __future__ import annotations
×
6

UNCOV
7
from collections.abc import Iterable
×
8

UNCOV
9
from pants.backend.tools.trufflehog.subsystem import Trufflehog
×
UNCOV
10
from pants.core.goals.lint import LintFilesRequest, LintResult
×
UNCOV
11
from pants.core.util_rules.config_files import find_config_file
×
UNCOV
12
from pants.core.util_rules.external_tool import download_external_tool
×
UNCOV
13
from pants.core.util_rules.partitions import Partitions
×
UNCOV
14
from pants.engine.fs import CreateDigest, FileEntry, MergeDigests, PathGlobs
×
UNCOV
15
from pants.engine.intrinsics import (
×
16
    create_digest,
17
    digest_to_snapshot,
18
    execute_process,
19
    get_digest_entries,
20
    merge_digests,
21
)
UNCOV
22
from pants.engine.platform import Platform
×
UNCOV
23
from pants.engine.process import Process
×
UNCOV
24
from pants.engine.rules import Rule, collect_rules, concurrently, implicitly, rule
×
UNCOV
25
from pants.source.filespec import FilespecMatcher
×
UNCOV
26
from pants.util.logging import LogLevel
×
UNCOV
27
from pants.util.strutil import pluralize
×
28

29

UNCOV
30
class TrufflehogRequest(LintFilesRequest):
×
UNCOV
31
    tool_subsystem = Trufflehog  # type: ignore[assignment]
×
32

33

UNCOV
34
@rule
×
UNCOV
35
async def partition_inputs(
×
36
    request: TrufflehogRequest.PartitionRequest, trufflehog: Trufflehog
37
) -> Partitions:
38
    """Configure the partitions scheme."""
39
    if trufflehog.skip or not request.files:
×
40
        return Partitions()
×
41

42
    matched_filepaths = FilespecMatcher(
×
43
        includes=["**"],
44
        excludes=trufflehog.exclude,
45
    ).matches(tuple(request.files))
46
    return Partitions.single_partition(sorted(matched_filepaths))
×
47

48

UNCOV
49
@rule(desc="Run Trufflehog Scan", level=LogLevel.DEBUG)
×
UNCOV
50
async def run_trufflehog(
×
51
    request: TrufflehogRequest.Batch,
52
    trufflehog: Trufflehog,
53
    platform: Platform,
54
) -> LintResult:
55
    """Runs the trufflehog executable against the targeted files."""
56

57
    download_trufflehog_get = download_external_tool(trufflehog.get_request(platform))
×
58
    config_files_get = find_config_file(trufflehog.config_request())
×
59
    downloaded_trufflehog, config_digest = await concurrently(
×
60
        download_trufflehog_get, config_files_get
61
    )
62

63
    # The downloaded files are going to contain the `exe`, readme and license. We only want the `exe`
64
    entry = next(
×
65
        e
66
        for e in await get_digest_entries(downloaded_trufflehog.digest)
67
        if isinstance(e, FileEntry) and e.path == "trufflehog" and e.is_executable
68
    )
69

70
    trufflehog_digest = await create_digest(CreateDigest([entry]))
×
71
    snapshot = await digest_to_snapshot(**implicitly(PathGlobs(request.elements)))
×
72
    input_digest = await merge_digests(
×
73
        MergeDigests(
74
            (
75
                snapshot.digest,
76
                trufflehog_digest,
77
                config_digest.snapshot.digest,
78
            )
79
        )
80
    )
81

82
    process_result = await execute_process(
×
83
        Process(
84
            argv=(
85
                downloaded_trufflehog.exe,
86
                "filesystem",
87
                *snapshot.files,
88
                "--fail",
89
                "--no-update",
90
                *(
91
                    ("--config", *config_digest.snapshot.files)
92
                    if config_digest.snapshot.files
93
                    else ()
94
                ),
95
                *trufflehog.args,
96
            ),
97
            input_digest=input_digest,
98
            description=f"Run Trufflehog on {pluralize(len(snapshot.files), 'file')}.",
99
            level=LogLevel.DEBUG,
100
        ),
101
        **implicitly(),
102
    )
103
    return LintResult.create(request, process_result)
×
104

105

UNCOV
106
def rules() -> Iterable[Rule]:
×
UNCOV
107
    return (
×
108
        *collect_rules(),
109
        *TrufflehogRequest.rules(),
110
    )
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