diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ad77b..d54d500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Version 1.8.1 (2023-05-07) + +- Fixed bad deprecation warning with `highlighter` +- Fixed incompatibility with Click 9. + ## Version 1.8.0 (2023-04-30) - Add `--rich-config` and `--output` options to the `rich-click` CLI. diff --git a/src/rich_click/__init__.py b/src/rich_click/__init__.py index 56d2109..8e0d246 100644 --- a/src/rich_click/__init__.py +++ b/src/rich_click/__init__.py @@ -6,7 +6,7 @@ customisation required. """ -__version__ = "1.8.0" +__version__ = "1.8.1" # Import the entire click API here. # We need to manually import these instead of `from click import *` to force diff --git a/src/rich_click/rich_click.py b/src/rich_click/rich_click.py index f9fe147..cba1c39 100644 --- a/src/rich_click/rich_click.py +++ b/src/rich_click/rich_click.py @@ -116,18 +116,20 @@ def __getattr__(name: str) -> Any: return RichHelpConfiguration.load_from_globals if name == "highlighter": - import warnings + # TODO: Fix deprecation warning. For now, exclude. - from rich_click.rich_help_configuration import OptionHighlighter + # import warnings - warnings.warn( - "`highlighter` config option is deprecated." - " Please do one of the following instead: either set HIGHLIGHTER_PATTERNS = [...] if you want" - " to use regex; or for more advanced use cases where you'd like to use a different type" - " of rich.highlighter.Highlighter, subclass the `RichHelpFormatter` and update its `highlighter`.", - DeprecationWarning, - stacklevel=2, - ) + # warnings.warn( + # "`highlighter` config option is deprecated." + # " Please do one of the following instead: either set HIGHLIGHTER_PATTERNS = [...] if you want" + # " to use regex; or for more advanced use cases where you'd like to use a different type" + # " of rich.highlighter.Highlighter, subclass the `RichHelpFormatter` and update its `highlighter`.", + # DeprecationWarning, + # stacklevel=2, + # ) + + from rich_click.rich_help_configuration import OptionHighlighter globals()["highlighter"] = highlighter = OptionHighlighter() return highlighter diff --git a/src/rich_click/rich_command.py b/src/rich_click/rich_command.py index 3129cc7..a3f9d3e 100644 --- a/src/rich_click/rich_command.py +++ b/src/rich_click/rich_command.py @@ -220,10 +220,16 @@ def format_help_text(self, ctx: RichContext, formatter: RichHelpFormatter) -> No get_rich_help_text(self, ctx, formatter) - def format_options(self, ctx: RichContext, formatter: RichHelpFormatter) -> None: # type: ignore[override] + # TODO: + # Switching from base click to rich click causes mypy problems. + # Either we: (a) swap MRO (incompatible with click 9, without handling 8 and 9 differently) + # or (b) we allow issues when users attempt multiple inheritance with a RichCommand + # or (c) we use incorrect types here. + # We are looking for a solution that fixes all 3. For now, we opt for (c). + def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: from rich_click.rich_help_rendering import get_rich_options - get_rich_options(self, ctx, formatter) + get_rich_options(self, ctx, formatter) # type: ignore[arg-type] def format_epilog(self, ctx: RichContext, formatter: RichHelpFormatter) -> None: # type: ignore[override] from rich_click.rich_help_rendering import get_rich_epilog @@ -264,7 +270,7 @@ def make_context( MultiCommand = Group # type: ignore[misc,assignment] -class RichMultiCommand(MultiCommand, RichCommand): +class RichMultiCommand(RichCommand, MultiCommand): """ Richly formatted click MultiCommand. @@ -282,11 +288,12 @@ def format_commands(self, ctx: RichContext, formatter: RichHelpFormatter) -> Non get_rich_commands(self, ctx, formatter) - def format_options(self, ctx: RichContext, formatter: RichHelpFormatter) -> None: # type: ignore[override] + def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: from rich_click.rich_help_rendering import get_rich_options - get_rich_options(self, ctx, formatter) - self.format_commands(ctx, formatter) + get_rich_options(self, ctx, formatter) # type: ignore[arg-type] + + self.format_commands(ctx, formatter) # type: ignore[arg-type] def format_help(self, ctx: RichContext, formatter: RichHelpFormatter) -> None: # type: ignore[override] if OVERRIDES_GUARD: @@ -298,7 +305,7 @@ def format_help(self, ctx: RichContext, formatter: RichHelpFormatter) -> None: self.format_epilog(ctx, formatter) -class RichGroup(Group, RichMultiCommand): +class RichGroup(RichMultiCommand, Group): """ Richly formatted click Group. @@ -360,7 +367,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any: return super().__call__(*args, **kwargs) -class RichCommandCollection(RichGroup, CommandCollection): +class RichCommandCollection(CommandCollection, RichGroup): """ Richly formatted click CommandCollection.