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

Fix issues with recent versions of click and django #12

Merged
merged 8 commits into from Jun 13, 2020
Merged

Fix issues with recent versions of click and django #12

merged 8 commits into from Jun 13, 2020

Conversation

simonpercivall
Copy link
Contributor

Fix multiple issues with recent versions of click and Django:

  • Django 3 removes Python 2 compatibility shims, like python_2_unicode_compatible; use the one from six instead
  • Django 3 handles ArgumentParser's mutually exclusive groups; add the attribute to ArgumentParserAdapt to make Django happy
  • Recent versions of click do not exit on ctx.exit() if standalone_mode = False, instead returning the exit code from Command.main(); use that exit code and exit "manually" instead, if it's non-zero
  • Different versions of click cases metavars differently; lowercase some output in tests to make checking equality more compatible with multiple click versions
  • Different versions of pytest stringifies ExceptionInfo differently; match against exception message in tests instead of checking against how pytest formats its wrapper
  • Fix help and usage output to show command names correctly; specifically, don't show the base command name twice, and show it (once) when showing usage for sub-commands (Fixes --help incorrectly repeats command name #8)
  • Style CommandError like Django, with red, bold text

Django 3.0 removed django.utils.encoding.python_2_unicode_compatible.
Use the one from six instead.
Instead of checking for the specific formatting of pytest's wrapper
around an exception, check the error message with `ExceptionInfo.match`.
This improves compatibility with different versions of pytest.
Improve compatibility with different versions of click (that format args
differently cased) by checking against the lower-cased output.
In Django 3.0, the parser is checked for _mutually_exclusive_groups. Add
an empty list to ArgumentParserAdapter (since click doesn't support
this feature) to make it compatible with Django 3.
…it()

Improve compatibility with recent versions of click, that changed how main
handles standalone_mode=False works. It now returns the exit_code rather than
letting an Exit() propagate.
Check that the exception caught does have ctx before accessing the attribute.

It's not likely that that code is ever reached, since ClickException is
explicitly caught in main, and not propagated unless standalone_mode=True.
Set prog_name explicitly when calling Command.main. This fixes two
issues:
* Base command names aren't duplicated in help output
* Both base command name and sub-commands are shown, instead of just the
  sub-command
@simonpercivall
Copy link
Contributor Author

The build error, btw, is an internal coverage error, and should be cleared by clearing the caches.

@FlipperPA FlipperPA merged commit 2a31bf4 into GaretJax:master Jun 13, 2020
@simonpercivall simonpercivall deleted the fix-issues-with-recent-versions-of-click-and-django branch June 13, 2020 11:24
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.

--help incorrectly repeats command name
2 participants