Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add context_settings support #115

Merged
merged 9 commits into from
Oct 2, 2023

Conversation

dwreeves
Copy link
Collaborator

Overview

The issue suggests there may be more issues with context_settings options not being passed into Rich-Click properly, but as far as I can tell, the only outstanding issue with context_settings was the show_default option.

Behaviors of each Click version

When it comes to handling defaults using context_settings={"show_default": True}, each supported minor version of click, 7, 8.0, and 8.1, behaves differently.

In the below sub-sections, I catalog each behavior of each version of Click and show that my changes to Rich-Click adhere to the behaviors of the base Click versions.

Click 7.x

Original Click behavior

>>> pip install -U "click<8" >/dev/null 2>&1 && python tests/fixtures/context_settings.py --help
Usage: context_settings.py [OPTIONS]

  Test cases for context_settings.

  Note that in click < 8.1, '[default: False]' shows for "--help".

Options:
  --a TEXT  This works in all supported click versions.  [default: show me
            always]

  --b TEXT  This works in all supported click versions.  [default: show me
            always]

  --c TEXT  Hide default only in click>=8.1  [default: show me in old
            versions]

  --d TEXT  Show 'default: (show me in c8+)' in click>=8.0. In click 7, no
            default is shown.

  --help    Show this message and exit.  [default: False]

Rich-Click behavior

>>> pip install -U "click<8" >/dev/null 2>&1 && python tests/fixtures/context_settings.py --help
                                                                                                                                                                             
 Usage: context_settings.py [OPTIONS]                                                                                                                                        
                                                                                                                                                                             
 Test cases for context_settings.                                                                                                                                            
 Note that in click < 8.1, '[default: False]' shows for "--help".                                                                                                            
                                                                                                                                                                             
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --a       TEXT  This works in all supported click versions. [default: show me always]                                                                                     │
│ --b       TEXT  This works in all supported click versions. [default: show me always]                                                                                     │
│ --c       TEXT  Hide default only in click>=8.1 [default: show me in old versions]                                                                                        │
│ --d       TEXT  Show 'default: (show me in c8+)' in click>=8.0. In click 7, no default is shown.                                                                          │
│ --help          Show this message and exit. [default: False]                                                                                                              │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Click 8.0

Original Click behavior

>>> pip install -U "click==8.0.*" >/dev/null 2>&1 && python tests/fixtures/context_settings.py --help
Usage: context_settings.py [OPTIONS]

  Test cases for context_settings.

  Note that in click < 8.1, '[default: False]' shows for "--help".

Options:
  --a TEXT  This works in all supported click versions.  [default: show me
            always]
  --b TEXT  This works in all supported click versions.  [default: show me
            always]
  --c TEXT  Hide default only in click>=8.1  [default: show me in old
            versions]
  --d TEXT  Show 'default: (show me in c8+)' in click>=8.0. In click 7, no
            default is shown.  [default: (show me in c8+)]
  --help    Show this message and exit.  [default: False]

Rich-Click behavior

>>> pip install -U "click==8.0.*" >/dev/null 2>&1 && python tests/fixtures/context_settings.py --help

Usage: context_settings.py [OPTIONS]                                                                                                                                        
                                                                                                                                                                            
Test cases for context_settings.                                                                                                                                            
Note that in click < 8.1, '[default: False]' shows for "--help".                                                                                                            
                                                                                                                                                                            
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --a       TEXT  This works in all supported click versions. [default: show me always]                                                                                     │
│ --b       TEXT  This works in all supported click versions. [default: show me always]                                                                                     │
│ --c       TEXT  Hide default only in click>=8.1 [default: show me in old versions]                                                                                        │
│ --d       TEXT  Show 'default: (show me in c8+)' in click>=8.0. In click 7, no default is shown. [default: (show me in c8+)]                                              │
│ --help          Show this message and exit. [default: False]                                                                                                              │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Click 8.1

Original Click behavior

>>> pip install -U "click==8.1.*" >/dev/null 2>&1 && python tests/fixtures/context_settings.py --help
Usage: context_settings.py [OPTIONS]

  Test cases for context_settings.

  Note that in click < 8.1, '[default: False]' shows for "--help".

Options:
  --a TEXT  This works in all supported click versions.  [default: show me
            always]
  --b TEXT  This works in all supported click versions.  [default: show me
            always]
  --c TEXT  Hide default only in click>=8.1
  --d TEXT  Show 'default: (show me in c8+)' in click>=8.0. In click 7, no
            default is shown.  [default: (show me in c8+)]
  --help    Show this message and exit.

Rich-Click behavior

>>> pip install -U "click==8.1.*" >/dev/null 2>&1 && python tests/fixtures/context_settings.py --help

Usage: context_settings.py [OPTIONS]                                                                                                                                        
                                                                                                                                                                            
Test cases for context_settings.                                                                                                                                            
Note that in click < 8.1, '[default: False]' shows for "--help".                                                                                                            
                                                                                                                                                                            
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --a       TEXT  This works in all supported click versions. [default: show me always]                                                                                     │
│ --b       TEXT  This works in all supported click versions. [default: show me always]                                                                                     │
│ --c       TEXT  Hide default only in click>=8.1                                                                                                                           │
│ --d       TEXT  Show 'default: (show me in c8+)' in click>=8.0. In click 7, no default is shown. [default: (show me in c8+)]                                              │
│ --help          Show this message and exit.                                                                                                                               │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

@dwreeves dwreeves force-pushed the 18-options-from-context-settings branch from 7c6f01b to c61797b Compare July 16, 2023 23:11
@dwreeves
Copy link
Collaborator Author

OK, that took a few attempts to get the CI passing, but it's ready! 😄 @ewels

@dwreeves
Copy link
Collaborator Author

@ewels This is going to conflict a little bit with the other PR because this one is using the (deprecated!!!!) distutils package (which will be removed in Python 3.12!!!), and the other one is using the suggested packaging package. I'll get to this as soon as I can, probably not tonight but possibly tomorrow.

@ewels
Copy link
Owner

ewels commented Sep 24, 2023

Ah right, sorry! But yeah, I think as you say it's good to switch over anyway.

@dwreeves dwreeves force-pushed the 18-options-from-context-settings branch from 4047d5f to 616054d Compare October 2, 2023 19:10
@dwreeves
Copy link
Collaborator Author

dwreeves commented Oct 2, 2023

Some changes to the code between July and now:

  • Had some time to think about this: I'm longer using the packaging package because I want to reduce the scope of dependencies; just parsing the string should be fine!
  • click is deprecating click.__version__ in 9.1 and is saying to use importlib.metadata.version('click') instead, so I switched to that.

Of course, the main point of this PR is to address #18, which we do! It is just entwined in the version compatibility stuff due to how Click 7.x, 8.0, and 8.1+ all parse things differently than one another.

@dwreeves dwreeves merged commit c8797a7 into ewels:main Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

options inherited from context settings aren't applied
2 participants