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

pantsbuild / pants / 18791134616

24 Oct 2025 08:18PM UTC coverage: 75.519% (-4.8%) from 80.282%
18791134616

Pull #22794

github

web-flow
Merge 098c595a0 into 7971a20bf
Pull Request #22794: Use self-hosted MacOS Intel runner

65803 of 87134 relevant lines covered (75.52%)

3.07 hits per line

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

74.19
/src/python/pants/engine/addresses.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
10✔
5

6
from collections.abc import Iterable, Sequence
10✔
7
from dataclasses import dataclass
10✔
8

9
from pants.build_graph.address import Address as Address
10✔
10
from pants.build_graph.address import AddressInput as AddressInput  # noqa: F401: rexport.
10✔
11
from pants.build_graph.address import BuildFileAddress as BuildFileAddress  # noqa: F401: rexport.
10✔
12
from pants.build_graph.address import (  # noqa: F401: rexport.
10✔
13
    BuildFileAddressRequest as BuildFileAddressRequest,
14
)
15
from pants.build_graph.address import MaybeAddress as MaybeAddress  # noqa: F401: rexport.
10✔
16
from pants.build_graph.address import ResolveError
10✔
17
from pants.engine.collection import Collection
10✔
18
from pants.util.strutil import bullet_list
10✔
19

20

21
def assert_single_address(addresses: Sequence[Address]) -> None:
10✔
22
    """Assert that exactly one address must be contained in the collection."""
23
    if len(addresses) == 0:
6✔
24
        raise ResolveError("No targets were matched.")
×
25
    if len(addresses) > 1:
6✔
26
        raise ResolveError(
×
27
            "Expected a single target, but was given multiple targets.\n\n"
28
            f"Did you mean one of these?\n\n{bullet_list(address.spec for address in addresses)}"
29
        )
30

31

32
class Addresses(Collection[Address]):
10✔
33
    def expect_single(self) -> Address:
10✔
34
        assert_single_address(self)
×
35
        return self[0]
×
36

37

38
@dataclass(frozen=True)
10✔
39
class UnparsedAddressInputs:
10✔
40
    """Raw addresses that have not been parsed yet.
41

42
    You can convert these into fully normalized `Addresses` and `Targets` like this:
43

44
        await resolve_unparsed_address_inputs(UnparsedAddressInputs(["//:tgt1", "//:tgt2"], owning_address=None), **implicitly())
45
        await resolve_targets(**implicitly(UnparsedAddressInputs([...], owning_address=Address("original")))
46

47
    This is intended for contexts where the user specifies addresses outside of the `dependencies`
48
    field, such as through an option or a special field on a target that is not normal
49
    `dependencies`. You should not use this to resolve the `dependencies` field; use
50
    `await resolve_dependencies(DependenciesRequest(..), **implicitly())` for that.
51

52
    If the addresses are coming from a target's fields, set `owning_address` so that relative
53
    references like `:sibling` work properly.
54

55
    Unlike the `dependencies` field, this type does not work with `!` and `!!` ignores.
56

57
    Set `description_of_origin` to a value like "CLI arguments" or "the `dependencies` field
58
    from {tgt.address}". It is used for better error messages.
59
    """
60

61
    values: tuple[str, ...]
10✔
62
    relative_to: str | None
10✔
63
    description_of_origin: str
10✔
64
    skip_invalid_addresses: bool
10✔
65

66
    def __init__(
10✔
67
        self,
68
        values: Iterable[str],
69
        *,
70
        owning_address: Address | None,
71
        description_of_origin: str,
72
        skip_invalid_addresses: bool = False,
73
    ) -> None:
74
        object.__setattr__(self, "values", tuple(values))
×
75
        object.__setattr__(
×
76
            self, "relative_to", owning_address.spec_path if owning_address else None
77
        )
78
        object.__setattr__(self, "description_of_origin", description_of_origin)
×
79
        object.__setattr__(self, "skip_invalid_addresses", skip_invalid_addresses)
×
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