def get_option_help_info(self, args, kwargs): """Returns an OptionHelpInfo for the option registered with the given (args, kwargs).""" display_args = [] scoped_cmd_line_args = [] unscoped_cmd_line_args = [] for arg in args: is_short_arg = len(arg) == 2 unscoped_cmd_line_args.append(arg) if self._scope_prefix: scoped_arg = f"--{self._scope_prefix}-{arg.lstrip('-')}" else: scoped_arg = arg scoped_cmd_line_args.append(scoped_arg) if Parser.is_bool(kwargs): if is_short_arg: display_args.append(scoped_arg) else: unscoped_cmd_line_args.append(f"--no-{arg[2:]}") sa_2 = scoped_arg[2:] scoped_cmd_line_args.append(f"--no-{sa_2}") display_args.append(f"--[no-]{sa_2}") else: metavar = self.compute_metavar(kwargs) display_args.append(f"{scoped_arg}={metavar}") if kwargs.get("passthrough"): type_str = self.stringify_type(kwargs.get("member_type", str)) display_args.append(f"... -- [{type_str} [{type_str} [...]]]") typ = kwargs.get("type", str) default = self.compute_default(**kwargs) help_msg = kwargs.get("help", "No help available.") deprecation_start_version = kwargs.get("deprecation_start_version") removal_version = kwargs.get("removal_version") deprecation_active = removal_version is not None and deprecated.is_deprecation_active( deprecation_start_version ) deprecated_message = None if removal_version: deprecated_tense = deprecated.get_deprecated_tense(removal_version) message_start = ( "Deprecated" if deprecation_active else f"Upcoming deprecation in version: {deprecation_start_version}" ) deprecated_message = ( f"{message_start}, {deprecated_tense} removed in version: {removal_version}." ) removal_hint = kwargs.get("removal_hint") choices = self.compute_choices(kwargs) dest = Parser.parse_dest(*args, **kwargs) # Global options have three env var variants. The last one is the most human-friendly. env_var = Parser.get_env_var_names(self._scope, dest)[-1] ret = OptionHelpInfo( display_args=tuple(display_args), comma_separated_display_args=", ".join(display_args), scoped_cmd_line_args=tuple(scoped_cmd_line_args), unscoped_cmd_line_args=tuple(unscoped_cmd_line_args), env_var=env_var, config_key=dest, typ=typ, default=default, help=help_msg, deprecation_active=deprecation_active, deprecated_message=deprecated_message, removal_version=removal_version, removal_hint=removal_hint, choices=choices, comma_separated_choices=None if choices is None else ", ".join(choices), value_history=None, ) return ret
def test_is_deprecation_active() -> None: assert is_deprecation_active(start_version=None) assert is_deprecation_active(start_version="1.0.0") assert not is_deprecation_active(start_version=FUTURE_VERSION)