METADATA 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Metadata-Version: 2.0
  2. Name: flake8-polyfill
  3. Version: 1.0.2
  4. Summary: Polyfill package for Flake8 plugins
  5. Home-page: https://gitlab.com/pycqa/flake8-polyfill
  6. Author: Ian Cordasco
  7. Author-email: graffatcolmingov@gmail.com
  8. License: MIT
  9. Description-Content-Type: UNKNOWN
  10. Platform: UNKNOWN
  11. Classifier: Environment :: Console
  12. Classifier: Framework :: Flake8
  13. Classifier: Intended Audience :: Developers
  14. Classifier: License :: OSI Approved :: MIT License
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 2
  17. Classifier: Programming Language :: Python :: 2.7
  18. Classifier: Programming Language :: Python :: 3
  19. Classifier: Programming Language :: Python :: 3.4
  20. Classifier: Programming Language :: Python :: 3.5
  21. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  22. Classifier: Topic :: Software Development :: Quality Assurance
  23. Requires-Dist: flake8
  24. =============================
  25. Polyfill for Flake8 Plugins
  26. =============================
  27. ``flake8-polyfill`` is a package that provides some compatibility helpers for
  28. Flake8 plugins that intend to support Flake8 2.x and 3.x simultaneously.
  29. Installation
  30. ============
  31. .. code-block:: bash
  32. pip install flake8-polyfill
  33. Usage
  34. =====
  35. Option Handling
  36. ---------------
  37. One problem area with compatibility with Flake8 2.x and 3.x is the registering
  38. options and receiving the parsed values.
  39. Flake8 3.0 added extra parameters to the ``add_option`` method which don't
  40. have the same effect on Flake8 2.x. To accomodate the change, this polyfill
  41. module allows you to do:
  42. .. code-block:: python
  43. from flake8_polyfill import options
  44. class MyFlake8Plugin(object):
  45. @classmethod
  46. def add_options(cls, parser):
  47. options.register(parser, '--my-long-option-name',
  48. parse_from_config=True,
  49. comma_separated_list=True,
  50. default='...',
  51. help='...')
  52. options.register(parser, '-m', '--my-other-long-option-name',
  53. parse_from_config=True,
  54. normalize_paths=True,
  55. default='...',
  56. help='...')
  57. @classmethod
  58. def parse_options(cls, values):
  59. cls.my_long_option_name = values.my_long_option_name
  60. cls.my_other_long_option_name = values.my_other_long_option_name
  61. And have the code work the same way on both versions.
  62. Retrieving Standard In
  63. ----------------------
  64. Until Flake8 2.6, getting the code on standard in from a plugin has been
  65. simple:
  66. .. code-block:: python
  67. import pep8
  68. stdin = pep8.get_stdin_value()
  69. In 2.6 you now have to know whether to use ``pep8`` or ``pycodestyle`` since
  70. Flake8 2.6 made a hard change to ``pycodestyle``.
  71. The reason you need to know which module to use is because standard in can be
  72. exhausted and Flake8 does some work to cache the value so that call always
  73. returns the desired data.
  74. In 3.0, Flake8 no longer monkey-patches those modules.
  75. To accommodate this, this package provides:
  76. .. code-block:: python
  77. from flake8_polyfill import stdin
  78. stdin.monkey_patch('all')
  79. stdin.monkey_patch('pep8')
  80. stdin.monkey_patch('pycodestyle')
  81. This allows you to have the polyfill module monkey-patch what you want so it
  82. is always monkey-patched. It will also do so in an intelligent way.
  83. Version Comparison
  84. ------------------
  85. Flake8 2.x did not include an object that would allow for easy version
  86. comparison. Flake8 3.0, however, added a ``__version_info__`` attribute. For
  87. consistency, Flake8 Polyfill will turn 2.x's version string into a tuple
  88. suitable for comparison.
  89. .. code-block:: python
  90. from flake8_polyfill import version
  91. if (2, 4) <= version.version_info < (2, 6):
  92. # ...
  93. elif (2, 6) <= version.version_info < (3, 0):
  94. # ...
  95. elif (3, 0) <= version.version_info < (4, 0):
  96. # ...
  97. License
  98. =======
  99. MIT
  100. Creator
  101. =======
  102. Ian Cordasco