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

pantsbuild / pants / 20332790708

18 Dec 2025 09:48AM UTC coverage: 64.992% (-15.3%) from 80.295%
20332790708

Pull #22949

github

web-flow
Merge f730a56cd into 407284c67
Pull Request #22949: Add experimental uv resolver for Python lockfiles

54 of 97 new or added lines in 5 files covered. (55.67%)

8270 existing lines in 295 files now uncovered.

48990 of 75379 relevant lines covered (64.99%)

1.81 hits per line

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

50.0
/src/python/pants/backend/shell/goals/tailor.py
1
# Copyright 2021 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 os
1✔
7
from collections.abc import Iterable
1✔
8
from dataclasses import dataclass
1✔
9

10
from pants.backend.shell.subsystems.shell_setup import ShellSetup
1✔
11
from pants.backend.shell.target_types import (
1✔
12
    ShellSourcesGeneratorTarget,
13
    Shunit2TestsGeneratorSourcesField,
14
    Shunit2TestsGeneratorTarget,
15
)
16
from pants.core.goals.tailor import (
1✔
17
    AllOwnedSources,
18
    PutativeTarget,
19
    PutativeTargets,
20
    PutativeTargetsRequest,
21
)
22
from pants.engine.intrinsics import path_globs_to_paths
1✔
23
from pants.engine.rules import Rule, collect_rules, rule
1✔
24
from pants.engine.target import Target
1✔
25
from pants.engine.unions import UnionRule
1✔
26
from pants.source.filespec import FilespecMatcher
1✔
27
from pants.util.dirutil import group_by_dir
1✔
28
from pants.util.logging import LogLevel
1✔
29

30

31
@dataclass(frozen=True)
1✔
32
class PutativeShellTargetsRequest(PutativeTargetsRequest):
1✔
33
    pass
1✔
34

35

36
def classify_source_files(paths: Iterable[str]) -> dict[type[Target], set[str]]:
1✔
37
    """Returns a dict of target type -> files that belong to targets of that type."""
UNCOV
38
    tests_filespec_matcher = FilespecMatcher(Shunit2TestsGeneratorSourcesField.default, ())
×
UNCOV
39
    test_filenames = set(tests_filespec_matcher.matches([os.path.basename(path) for path in paths]))
×
UNCOV
40
    test_files = {path for path in paths if os.path.basename(path) in test_filenames}
×
UNCOV
41
    sources_files = set(paths) - test_files
×
UNCOV
42
    return {Shunit2TestsGeneratorTarget: test_files, ShellSourcesGeneratorTarget: sources_files}
×
43

44

45
@rule(level=LogLevel.DEBUG, desc="Determine candidate shell targets to create")
1✔
46
async def find_putative_targets(
1✔
47
    req: PutativeShellTargetsRequest, all_owned_sources: AllOwnedSources, shell_setup: ShellSetup
48
) -> PutativeTargets:
49
    if not (shell_setup.tailor_sources or shell_setup.tailor_shunit2_tests):
×
50
        return PutativeTargets()
×
51

52
    all_shell_files = await path_globs_to_paths(req.path_globs("*.sh"))
×
53
    unowned_shell_files = set(all_shell_files.files) - set(all_owned_sources)
×
54
    classified_unowned_shell_files = classify_source_files(unowned_shell_files)
×
55
    pts: list[PutativeTarget] = []
×
56
    for tgt_type, paths in classified_unowned_shell_files.items():
×
57
        for dirname, filenames in group_by_dir(paths).items():
×
58
            if tgt_type == Shunit2TestsGeneratorTarget:
×
59
                if not shell_setup.tailor_shunit2_tests:
×
60
                    continue
×
61
                name = "tests"
×
62
            else:
63
                if not shell_setup.tailor_sources:
×
64
                    continue
×
65
                name = None
×
66

67
            pts.append(
×
68
                PutativeTarget.for_target_type(
69
                    tgt_type, path=dirname, name=name, triggering_sources=sorted(filenames)
70
                )
71
            )
72
    return PutativeTargets(pts)
×
73

74

75
def rules() -> Iterable[Rule | UnionRule]:
1✔
76
    return (*collect_rules(), UnionRule(PutativeTargetsRequest, PutativeShellTargetsRequest))
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