-
-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify OptionsBootstrapper #21784
base: main
Are you sure you want to change the base?
Simplify OptionsBootstrapper #21784
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
from pants.base.build_environment import get_buildroot | ||
from pants.base.deprecated import warn_or_error | ||
from pants.option.arg_splitter import ArgSplitter | ||
from pants.option.config import Config | ||
from pants.option.config import ConfigSource | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer parse config in Python, so we only traffic in ConfigSource, which gets passed to Rust. A followup change will delete the Python Config class and its tests, but this change was already gnarly enough without adding that in. |
||
from pants.option.errors import ( | ||
ConfigValidationError, | ||
MutuallyExclusiveOptionError, | ||
|
@@ -116,26 +116,26 @@ def complete_scopes(cls, scope_infos: Iterable[ScopeInfo]) -> FrozenOrderedSet[S | |
@classmethod | ||
def create( | ||
cls, | ||
env: Mapping[str, str], | ||
config: Config, | ||
known_scope_infos: Iterable[ScopeInfo], | ||
*, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To force callsites to be readable... |
||
args: Sequence[str], | ||
bootstrap_option_values: OptionValueContainer | None = None, | ||
env: Mapping[str, str], | ||
config_sources: Sequence[ConfigSource] | None, | ||
known_scope_infos: Sequence[ScopeInfo], | ||
extra_specs: Sequence[str] = tuple(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the Options class knowing about bootstrap options and finding the extra specs there (via the |
||
allow_unknown_options: bool = False, | ||
native_options_config_discovery: bool = True, | ||
allow_pantsrc: bool = True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously we were not plumbing OTOH we no longer need to set |
||
include_derivation: bool = False, | ||
) -> Options: | ||
"""Create an Options instance. | ||
|
||
:param args: a list of cmd-line args; defaults to `sys.argv` if None is supplied. | ||
:param env: a dict of environment variables. | ||
:param config: data from a config file. | ||
:param config_sources: sources of config data. | ||
:param known_scope_infos: ScopeInfos for all scopes that may be encountered. | ||
:param args: a list of cmd-line args; defaults to `sys.argv` if None is supplied. | ||
:param bootstrap_option_values: An optional namespace containing the values of bootstrap | ||
options. We can use these values when registering other options. | ||
:param extra_specs: Extra specs to add to those specified in the args (e.g., from --spec-files). | ||
:param allow_unknown_options: Whether to ignore or error on unknown cmd-line flags. | ||
:param native_options_config_discovery: Whether to discover config files in the native | ||
parser or use the ones supplied. | ||
:param allow_pantsrc: Whether to read config from local .rc files. Typically | ||
disabled in tests, for hermeticity. | ||
:param include_derivation: Whether to gather option value derivation information. | ||
""" | ||
# We need registrars for all the intermediate scopes, so inherited option values | ||
|
@@ -150,19 +150,19 @@ def create( | |
scope: registrar.known_scoped_args for scope, registrar in registrar_by_scope.items() | ||
} | ||
|
||
config_to_pass = None if native_options_config_discovery else config.sources() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
native_parser = NativeOptionParser( | ||
args[1:], # The native parser expects args without the sys.argv[0] binary name. | ||
env, | ||
config_sources=config_to_pass, | ||
allow_pantsrc=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was where we failed to plumb this setting to the top, now remedied. |
||
config_sources=config_sources, | ||
allow_pantsrc=allow_pantsrc, | ||
include_derivation=include_derivation, | ||
known_scopes_to_flags=known_scope_to_flags, | ||
) | ||
|
||
splitter = ArgSplitter(complete_known_scope_infos, get_buildroot()) | ||
# We take the cli alias-expanded args[1:] from the native parser. | ||
split_args = splitter.split_args([args[0], *native_parser.get_args()]) | ||
split_args.specs.extend(extra_specs) | ||
|
||
if split_args.passthru and len(split_args.goals) > 1: | ||
raise cls.AmbiguousPassthroughError( | ||
|
@@ -177,15 +177,6 @@ def create( | |
) | ||
) | ||
|
||
if bootstrap_option_values: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned, this logic is now in the OptionsBootstrapper |
||
spec_files = bootstrap_option_values.spec_files | ||
if spec_files: | ||
for spec_file in spec_files: | ||
with open(spec_file) as f: | ||
split_args.specs.extend( | ||
[line for line in [line.strip() for line in f] if line] | ||
) | ||
|
||
return cls( | ||
builtin_or_auxiliary_goal=split_args.builtin_or_auxiliary_goal, | ||
goals=split_args.goals, | ||
|
@@ -278,7 +269,7 @@ def known_scope_to_scoped_args(self) -> dict[str, frozenset[str]]: | |
def scope_to_flags(self) -> dict[str, list[str]]: | ||
return self._scope_to_flags | ||
|
||
def verify_configs(self, global_config: Config) -> None: | ||
def verify_configs(self) -> None: | ||
"""Verify all loaded configs have correct scopes and options.""" | ||
|
||
section_to_valid_options = {} | ||
|
@@ -300,7 +291,6 @@ def verify_configs(self, global_config: Config) -> None: | |
""" | ||
) | ||
) | ||
global_config.verify(section_to_valid_options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was an oversight - config verification has been done in Rust for a while now, but I hadn't removed the python side call... |
||
|
||
def get_args(self) -> tuple[str, ...]: | ||
return self._native_parser.get_args() | ||
|
@@ -459,14 +449,11 @@ def for_scope( | |
) | ||
) | ||
setattr(builder, dest, RankedValue(rank, val)) | ||
native_values = builder.build() | ||
|
||
# Check for any deprecation conditions, which are evaluated using `self._flag_matchers`. | ||
if check_deprecations: | ||
native_values_builder = native_values.to_builder() | ||
self._check_and_apply_deprecations(scope, native_values_builder) | ||
native_values = native_values_builder.build() | ||
return native_values | ||
self._check_and_apply_deprecations(scope, builder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just some local streamlining that could have been done sooner. We don't need to build an OptionsValueContainer and then call |
||
return builder.build() | ||
|
||
def get_fingerprintable_for_scope( | ||
self, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of fields was changed to be consistently "args then env", as it is elsewhere. Note that the type of
env
was changed be a mapping instead of the less obvious list of pairs.