Skip to content
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

Deprecate --option-name-check-distance #10611

Merged
merged 3 commits into from Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/python/pants/help/help_formatter_test.py
Expand Up @@ -64,7 +64,7 @@ def _format_for_global_scope(show_advanced, show_deprecated, args, kwargs):
)
parser.register(*args, **kwargs)
# Force a parse to generate the derivation history.
parser.parse_args(Parser.ParseArgsRequest((), OptionValueContainer(), lambda: [], 0, []))
parser.parse_args(Parser.ParseArgsRequest((), OptionValueContainer(), lambda: [], []))
oshi = HelpInfoExtracter("").get_option_scope_help_info("", parser, False)
return HelpFormatter(
show_advanced=show_advanced, show_deprecated=show_deprecated, color=False
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/option/global_options.py
Expand Up @@ -223,8 +223,15 @@ def register_bootstrap_options(cls, register):
advanced=True,
type=int,
default=2,
help="The maximum Levenshtein distance to use when offering suggestions for invalid "
"option names.",
help=(
"The maximum Levenshtein distance to use when offering suggestions for invalid "
"option names."
),
removal_version="2.1.0.dev0",
removal_hint=(
"The option `--option-name-check-distance` no longer does anything, as Pants now "
"always uses the default of 2."
),
)

register(
Expand Down
7 changes: 0 additions & 7 deletions src/python/pants/option/options.py
Expand Up @@ -415,17 +415,10 @@ def _make_parse_args_request(
namespace: OptionValueContainer,
include_passive_options: bool = False,
) -> Parser.ParseArgsRequest:
levenshtein_max_distance = (
self._bootstrap_option_values.option_name_check_distance
if self._bootstrap_option_values
else 0
)

return Parser.ParseArgsRequest(
flags_in_scope=flags_in_scope,
namespace=namespace,
get_all_scoped_flag_names=lambda: self._all_scoped_flag_names_for_fuzzy_matching,
levenshtein_max_distance=levenshtein_max_distance,
passthrough_args=self._passthru,
include_passive_options=include_passive_options,
)
Expand Down
9 changes: 1 addition & 8 deletions src/python/pants/option/parser.py
Expand Up @@ -225,7 +225,6 @@ def __call__(self) -> Iterable[ScopedFlagNameForFuzzyMatching]:
flag_value_map: Dict[str, List[Any]]
namespace: OptionValueContainer
get_all_scoped_flag_names: FlagNameProvider
levenshtein_max_distance: int
passthrough_args: List[str]
# A passive option is one that doesn't affect functionality, or appear in help messages, but
# can be provided without failing validation. This allows us to conditionally register options
Expand All @@ -239,7 +238,6 @@ def __init__(
flags_in_scope: Iterable[str],
namespace: OptionValueContainer,
get_all_scoped_flag_names: FlagNameProvider,
levenshtein_max_distance: int,
passthrough_args: List[str],
include_passive_options: bool = False,
) -> None:
Expand All @@ -250,14 +248,10 @@ def __init__(
all registered option names in all their scopes. This
is used to create an error message with suggestions
when raising a `ParseError`.
:param levenshtein_max_distance: The maximum Levenshtein edit distance between option names
to determine similarly named options when an option name
hasn't been registered.
"""
self.flag_value_map = self._create_flag_value_map(flags_in_scope)
self.namespace = namespace
self.get_all_scoped_flag_names = get_all_scoped_flag_names
self.levenshtein_max_distance = levenshtein_max_distance
self.passthrough_args = passthrough_args
self.include_passive_options = include_passive_options

Expand Down Expand Up @@ -294,7 +288,6 @@ def parse_args(self, parse_args_request: ParseArgsRequest) -> OptionValueContain
flag_value_map = parse_args_request.flag_value_map
namespace = parse_args_request.namespace
get_all_scoped_flag_names = parse_args_request.get_all_scoped_flag_names
levenshtein_max_distance = parse_args_request.levenshtein_max_distance

mutex_map: DefaultDict[str, List[str]] = defaultdict(list)
for args, kwargs in self._unnormalized_option_registrations_iter():
Expand Down Expand Up @@ -383,7 +376,7 @@ def add_flag_val(v: Optional[Union[int, float, bool, str]]) -> None:
self._raise_error_for_invalid_flag_names(
tuple(flag_value_map.keys()),
all_scoped_flag_names=get_all_scoped_flag_names(),
max_edit_distance=levenshtein_max_distance,
max_edit_distance=2,
)

return namespace
Expand Down