Skip to content

Commit

Permalink
Merge pull request #196 from dwreeves/fix-issues
Browse files Browse the repository at this point in the history
fix issues
  • Loading branch information
dwreeves authored May 7, 2024
2 parents 480e266 + da6ea9f commit bcd77f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/rich_click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 bcd77f1

Please sign in to comment.