ewels / rich-click

Format click help output nicely with rich.
https://ewels.github.io/rich-click/
MIT License
604 stars 34 forks source link

OptionHighlighter is deprecated and will be removed in a future version. #194

Closed henryiii closed 5 months ago

henryiii commented 5 months ago

On rich-click 1.8.0, rich-click is triggering it's own warning:

# /// script
# dependencies = ["rick-click"]
# ///

import rich_click as click
from click.testing import CliRunner

@click.command()
def main() -> None:
    pass

runner = CliRunner()
result = runner.invoke(main, [], catch_exceptions=False)
assert result.exit_code == 0
$ python -Werror example.py
Traceback (most recent call last):
  File "/Users/henryschreiner/git/scikit-hep/repo-review/example.py", line 13, in <module>
    result = runner.invoke(main, [], catch_exceptions=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/click/testing.py", line 408, in invoke
    return_value = cli.main(args=args or (), prog_name=prog_name, **extra)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/rich_click/rich_command.py", line 151, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/rich_click/rich_command.py", line 254, in make_context
    return super().make_context(info_name, args, parent, **extra)  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/click/core.py", line 938, in make_context
    ctx = self.context_class(
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/rich_click/rich_context.py", line 54, in __init__
    self.help_config = RichHelpConfiguration.load_from_globals()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/rich_click/rich_help_configuration.py", line 208, in load_from_globals
    elif k == "highlighter" and hasattr(module, k):
                                ^^^^^^^^^^^^^^^^^^
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/rich_click/rich_click.py", line 121, in __getattr__
    from rich_click.rich_help_configuration import OptionHighlighter
  File "/Users/henryschreiner/git/scikit-hep/repo-review/.venv/lib/python3.12/site-packages/rich_click/rich_help_configuration.py", line 241, in __getattr__
    warnings.warn(
DeprecationWarning: OptionHighlighter is deprecated and will be removed in a future version.

This is breaking test suites that turn on deprecation warnings, but are not using any deprecated functionality. Deprecation warnings should only be emitted by third party code (and test suites should always enable all warnings as errors; [tool.pytest.ini_options] filterwarnings = ["error"] in pyproject.toml for pytest, for example).

Ignoring this one then hits another: DeprecationWarning: `highlighter` config option is deprecated. Please do one of the following instead: either set...

PS: see https://docs.python.org/3.13/library/warnings.html#warnings.deprecated if you don't mind adding a Python 3.13 backport (it's in typing_extensions for older Pythons). A nice feature of this is it is or will be supported by type checkers too.

dwreeves commented 5 months ago

🤦 Thanks for catching this!

dwreeves commented 5 months ago

Thanks for flagging. We are in the middle of overhauling our test suites, which have become hard to maintain (it's the next thing on the road map!), and yes, we have not fully addressed warnings as you can tell. Apologies for you having run into this issue. This will be fixed tonight when I am home from work.

dwreeves commented 5 months ago

Issue should be fixed for 1.8.1.

henryiii commented 5 months ago

Thanks!

jamescooke commented 4 months ago

Re @henryiii 's comment:

Ignoring this one then hits another: DeprecationWarning: highlighter config option is deprecated. Please do one of the following instead: either set...

I believe that's what I've run into in #197 and have opened that issue as a new one - hope I've got that right.

dwreeves commented 4 months ago

🫠 I dropped the ball on this lol. Gimme a day.