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

pantsbuild / pants / 22740642519

05 Mar 2026 11:00PM UTC coverage: 52.677% (-40.3%) from 92.931%
22740642519

Pull #23157

github

web-flow
Merge 2aa18e6d4 into f0030f5e7
Pull Request #23157: [pants ng] Partition source files by config.

31678 of 60136 relevant lines covered (52.68%)

0.53 hits per line

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

85.29
/src/python/pants/backend/python/lint/first_party_plugins.py
1
# Copyright 2025 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from dataclasses import dataclass
1✔
4
from typing import ClassVar, TypeVar
1✔
5

6
from pants.backend.python.target_types import (
1✔
7
    InterpreterConstraintsField,
8
    PythonRequirementsField,
9
    PythonResolveField,
10
)
11
from pants.backend.python.util_rules.pex_requirements import PexRequirements
1✔
12
from pants.backend.python.util_rules.python_sources import (
1✔
13
    PythonSourceFilesRequest,
14
    strip_python_sources,
15
)
16
from pants.engine.addresses import UnparsedAddressInputs
1✔
17
from pants.engine.fs import EMPTY_DIGEST, AddPrefix, Digest
1✔
18
from pants.engine.internals.graph import resolve_unparsed_address_inputs
1✔
19
from pants.engine.internals.graph import transitive_targets as transitive_targets_get
1✔
20
from pants.engine.intrinsics import add_prefix
1✔
21
from pants.engine.rules import implicitly
1✔
22
from pants.engine.target import TransitiveTargetsRequest
1✔
23
from pants.util.ordered_set import FrozenOrderedSet, OrderedSet
1✔
24

25

26
@dataclass(frozen=True)
1✔
27
class BaseFirstPartyPlugins:
1✔
28
    requirement_strings: FrozenOrderedSet[str]
29
    interpreter_constraints_and_resolve_fields: FrozenOrderedSet[
30
        tuple[InterpreterConstraintsField, PythonResolveField]
31
    ]
32
    sources_digest: Digest
33

34
    PREFIX: ClassVar[str] = "__plugins"
1✔
35

36
    def __bool__(self) -> bool:
1✔
37
        return self.sources_digest != EMPTY_DIGEST
1✔
38

39

40
FPP = TypeVar("FPP", bound=BaseFirstPartyPlugins)
1✔
41

42

43
async def resolve_first_party_plugins(
1✔
44
    source_plugins: UnparsedAddressInputs, fpp_type: type[FPP]
45
) -> FPP:
46
    if not source_plugins:
1✔
47
        return fpp_type(FrozenOrderedSet(), FrozenOrderedSet(), EMPTY_DIGEST)
×
48

49
    plugin_target_addresses = await resolve_unparsed_address_inputs(source_plugins, **implicitly())
1✔
50
    transitive_targets = await transitive_targets_get(
1✔
51
        TransitiveTargetsRequest(plugin_target_addresses), **implicitly()
52
    )
53

54
    requirements_fields: OrderedSet[PythonRequirementsField] = OrderedSet()
1✔
55
    interpreter_constraints_and_resolve_fields: OrderedSet[
1✔
56
        tuple[InterpreterConstraintsField, PythonResolveField]
57
    ] = OrderedSet()
58
    for tgt in transitive_targets.closure:
1✔
59
        if tgt.has_field(PythonRequirementsField):
×
60
            requirements_fields.add(tgt[PythonRequirementsField])
×
61
        if tgt.has_field(InterpreterConstraintsField):
×
62
            interpreter_constraints_and_resolve_fields.add(
×
63
                (tgt[InterpreterConstraintsField], tgt[PythonResolveField])
64
            )
65

66
    # NB: Flake8 and Pylint source plugins must be explicitly loaded via PYTHONPATH (i.e. PEX_EXTRA_SYS_PATH).
67
    # The value must point to the plugin's directory, rather than to a parent's directory, because
68
    # `flake8:local-plugins` values take a module name rather than a path to the module;
69
    # i.e. `plugin`, but not `path/to/plugin`.
70
    # (This means users must have specified the parent directory as a source root.)
71
    stripped_sources = await strip_python_sources(
1✔
72
        **implicitly(PythonSourceFilesRequest(transitive_targets.closure))
73
    )
74
    prefixed_sources = await add_prefix(
1✔
75
        AddPrefix(stripped_sources.stripped_source_files.snapshot.digest, fpp_type.PREFIX)
76
    )
77

78
    return fpp_type(
1✔
79
        requirement_strings=PexRequirements.req_strings_from_requirement_fields(
80
            requirements_fields,
81
        ),
82
        interpreter_constraints_and_resolve_fields=FrozenOrderedSet(
83
            interpreter_constraints_and_resolve_fields
84
        ),
85
        sources_digest=prefixed_sources,
86
    )
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