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

pantsbuild / pants / 18517631058

15 Oct 2025 04:18AM UTC coverage: 69.207% (-11.1%) from 80.267%
18517631058

Pull #22745

github

web-flow
Merge 642a76ca1 into 99919310e
Pull Request #22745: [windows] Add windows support in the stdio crate.

53815 of 77759 relevant lines covered (69.21%)

2.42 hits per line

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

95.24
/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
7✔
5

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

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

19

20
def create_options_bootstrapper(
7✔
21
    args: Iterable[str] | None = None, *, env: Mapping[str, str] | None = None
22
) -> OptionsBootstrapper:
23
    return OptionsBootstrapper.create(
7✔
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(
7✔
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
1✔
38

39
    if initial_headers is None:
1✔
40
        initial_headers = {}
1✔
41
    args = [
1✔
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:
1✔
50
        args.append(f"--remote-oauth-bearer-token=@{token_path}")
×
51
    if plugin:
1✔
52
        args.append(f"--backend-packages={plugin}")
×
53
    ob = create_options_bootstrapper(args)
1✔
54
    env = CompleteEnvironmentVars({})
1✔
55
    oi = OptionsInitializer(ob, rule_runner.EXECUTOR)
1✔
56
    _build_config = oi.build_config(ob, env)
1✔
57
    options = oi.options(
1✔
58
        ob, env, _build_config, union_membership=UnionMembership.empty(), raise_=False
59
    )
60
    return DynamicRemoteOptions.from_options(
1✔
61
        options, env, remote_auth_plugin_func=_build_config.remote_auth_plugin_func
62
    )[0]
63

64

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

75

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

78

79
def create_goal_subsystem(
7✔
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(
3✔
91
        options=create_option_value_container(default_rank, **options),
92
    )
93

94

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

97

98
def create_subsystem(
7✔
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(
6✔
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