help_formatter.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
  4. from __future__ import annotations
  5. import argparse
  6. from pylint.config.callback_actions import _CallbackAction
  7. from pylint.constants import DEFAULT_PYLINT_HOME, OLD_DEFAULT_PYLINT_HOME
  8. class _HelpFormatter(argparse.RawDescriptionHelpFormatter):
  9. """Formatter for the help message emitted by argparse."""
  10. def _get_help_string(self, action: argparse.Action) -> str | None:
  11. """Copied from argparse.ArgumentDefaultsHelpFormatter."""
  12. assert action.help
  13. help_string = action.help
  14. # CallbackActions don't have a default
  15. if isinstance(action, _CallbackAction):
  16. return help_string
  17. if "%(default)" not in help_string:
  18. if action.default is not argparse.SUPPRESS:
  19. defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
  20. if action.option_strings or action.nargs in defaulting_nargs:
  21. help_string += " (default: %(default)s)"
  22. return help_string
  23. @staticmethod
  24. def get_long_description() -> str:
  25. return f"""
  26. Environment variables:
  27. The following environment variables are used:
  28. * PYLINTHOME Path to the directory where persistent data for the run will
  29. be stored. If not found, it defaults to '{DEFAULT_PYLINT_HOME}'
  30. or '{OLD_DEFAULT_PYLINT_HOME}' (in the current working directory).
  31. * PYLINTRC Path to the configuration file. See the documentation for the method used
  32. to search for configuration file.
  33. Output:
  34. Using the default text output, the message format is :
  35. MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
  36. There are 5 kind of message types :
  37. * (I) info, for informational messages
  38. * (C) convention, for programming standard violation
  39. * (R) refactor, for bad code smell
  40. * (W) warning, for python specific problems
  41. * (E) error, for probable bugs in the code
  42. * (F) fatal, if an error occurred which prevented pylint from doing further processing.
  43. Output status code:
  44. Pylint should leave with following bitwise status codes:
  45. * 0 if everything went fine
  46. * 1 if a fatal message was issued
  47. * 2 if an error message was issued
  48. * 4 if a warning message was issued
  49. * 8 if a refactor message was issued
  50. * 16 if a convention message was issued
  51. * 32 on usage error
  52. """