Skip to content

Commit

Permalink
Deprecate --option-name-check-distance (#10611)
Browse files Browse the repository at this point in the history
Generally, Pants suffers from options fatigue. It's sensible to always use a max edit distance of 2 for Levenshtein matching on bad option names - there isn't much utility to allowing users to configure something so granular.

This simplifies our code, reduces the # of options for users, and will allow us to change the algorithm if we ever want to.
 
[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Aug 15, 2020
1 parent 659ffd6 commit 0b2be0b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/help/help_formatter_test.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 0b2be0b

Please sign in to comment.