Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed May 7, 2024
1 parent 480e266 commit d5862b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
22 changes: 12 additions & 10 deletions src/rich_click/rich_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions src/rich_click/rich_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d5862b7

Please sign in to comment.