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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

64.29
/src/python/pants/testutil/option_util.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
3✔
5

6
from collections.abc import Iterable, Mapping
3✔
7
from typing import TypeVar
3✔
8

9
from pants.engine.env_vars import CompleteEnvironmentVars
3✔
10
from pants.engine.goal import GoalSubsystem
3✔
11
from pants.engine.unions import UnionMembership
3✔
12
from pants.init.options_initializer import OptionsInitializer
3✔
13
from pants.option.bootstrap_options import DynamicRemoteOptions
3✔
14
from pants.option.option_value_container import OptionValueContainer, OptionValueContainerBuilder
3✔
15
from pants.option.options_bootstrapper import OptionsBootstrapper
3✔
16
from pants.option.ranked_value import Rank, RankedValue, Value
3✔
17
from pants.option.subsystem import Subsystem
3✔
18

19

20
def create_options_bootstrapper(
3✔
21
    args: Iterable[str] | None = None, *, env: Mapping[str, str] | None = None
22
) -> OptionsBootstrapper:
23
    return OptionsBootstrapper.create(
3✔
24
        args=("pants", "--pants-config-files=[]", *(args or [])),
25
        env=env or {},
26
        allow_pantsrc=False,
27
    )
28

29

30
def create_dynamic_remote_options(
3✔
31
    *,
32
    initial_headers: dict[str, str] | None = None,
33
    address: str | None = "grpc://fake.url:10",
34
    token_path: str | None = None,
35
    plugin: str | None = None,
36
) -> DynamicRemoteOptions:
37
    from pants.testutil import rule_runner
×
38

39
    if initial_headers is None:
×
40
        initial_headers = {}
×
41
    args = [
×
42
        "--remote-cache-read",
43
        f"--remote-execution-address={address}",
44
        f"--remote-store-address={address}",
45
        f"--remote-store-headers={initial_headers}",
46
        f"--remote-execution-headers={initial_headers}",
47
        "--remote-instance-name=main",
48
    ]
49
    if token_path:
×
50
        args.append(f"--remote-oauth-bearer-token=@{token_path}")
×
51
    if plugin:
×
52
        args.append(f"--backend-packages={plugin}")
×
53
    ob = create_options_bootstrapper(args)
×
54
    env = CompleteEnvironmentVars({})
×
55
    oi = OptionsInitializer(ob, rule_runner.EXECUTOR)
×
56
    _build_config = oi.build_config(ob, env)
×
57
    options = oi.options(
×
58
        ob, env, _build_config, union_membership=UnionMembership.empty(), raise_=False
59
    )
60
    return DynamicRemoteOptions.from_options(
×
61
        options, env, remote_auth_plugin_func=_build_config.remote_auth_plugin_func
62
    )[0]
63

64

65
def create_option_value_container(
3✔
66
    default_rank: Rank = Rank.NONE, **options: RankedValue | Value
67
) -> OptionValueContainer:
68
    scoped_options = OptionValueContainerBuilder()
3✔
69
    for key, value in options.items():
3✔
70
        if not isinstance(value, RankedValue):
3✔
71
            value = RankedValue(default_rank, value)
3✔
72
        setattr(scoped_options, key, value)
3✔
73
    return scoped_options.build()
3✔
74

75

76
_GS = TypeVar("_GS", bound=GoalSubsystem)
3✔
77

78

79
def create_goal_subsystem(
3✔
80
    goal_subsystem_type: type[_GS],
81
    default_rank: Rank = Rank.NONE,
82
    **options: RankedValue | Value,
83
) -> _GS:
84
    """Creates a new goal subsystem instance populated with the given option values.
85

86
    :param goal_subsystem_type: The `GoalSubsystem` type to create.
87
    :param default_rank: The rank to assign any raw option values passed.
88
    :param options: The option values to populate the new goal subsystem instance with.
89
    """
90
    return goal_subsystem_type(
×
91
        options=create_option_value_container(default_rank, **options),
92
    )
93

94

95
_SS = TypeVar("_SS", bound=Subsystem)
3✔
96

97

98
def create_subsystem(
3✔
99
    subsystem_type: type[_SS], default_rank: Rank = Rank.NONE, **options: RankedValue | Value
100
) -> _SS:
101
    """Creates a new subsystem instance populated with the given option values.
102

103
    :param subsystem_type: The `Subsystem` type to create.
104
    :param default_rank: The rank to assign any raw option values passed.
105
    :param options: The option values to populate the new subsystem instance with.
106
    """
107
    return subsystem_type(
3✔
108
        options=create_option_value_container(default_rank, **options),
109
    )
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