flake8-polyfill-1.0.2/0000775000175000017500000000000013221714277016124 5ustar icordascicordasc00000000000000flake8-polyfill-1.0.2/CHANGELOG.rst0000664000175000017500000000123613221714170020137 0ustar icordascicordasc000000000000001.0.2 (2017-12-29) ------------------ - Fix bug where user-supplied value for an option is ignored if the option is transformed with `comma_separated_list` or `normalize_paths` (!4) 1.0.1 (2016-07-19) ------------------ - Fix some packaging bugs 1.0.0 (2016-07-19) ------------------ - Release Initial Version of flake8-polyfill - Includes: * ``flake8_polyfill.options`` for Flake8 2.x/3.x compatibility handling * ``flake8_polyfill.stdin`` for Flake8 2.x stdin monkey patching that can also be used on Flake8 3.x * ``flake8_polyfill.version`` which can be used to retrieve a tuple to test Flake8's version information on all versions of Flake8 flake8-polyfill-1.0.2/LICENSE0000664000175000017500000000213113221714170017116 0ustar icordascicordasc00000000000000== Flake8 License (MIT) == Copyright (C) 2016 Ian Cordasco Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. flake8-polyfill-1.0.2/README.rst0000664000175000017500000000606713221714170017614 0ustar icordascicordasc00000000000000============================= Polyfill for Flake8 Plugins ============================= ``flake8-polyfill`` is a package that provides some compatibility helpers for Flake8 plugins that intend to support Flake8 2.x and 3.x simultaneously. Installation ============ .. code-block:: bash pip install flake8-polyfill Usage ===== Option Handling --------------- One problem area with compatibility with Flake8 2.x and 3.x is the registering options and receiving the parsed values. Flake8 3.0 added extra parameters to the ``add_option`` method which don't have the same effect on Flake8 2.x. To accomodate the change, this polyfill module allows you to do: .. code-block:: python from flake8_polyfill import options class MyFlake8Plugin(object): @classmethod def add_options(cls, parser): options.register(parser, '--my-long-option-name', parse_from_config=True, comma_separated_list=True, default='...', help='...') options.register(parser, '-m', '--my-other-long-option-name', parse_from_config=True, normalize_paths=True, default='...', help='...') @classmethod def parse_options(cls, values): cls.my_long_option_name = values.my_long_option_name cls.my_other_long_option_name = values.my_other_long_option_name And have the code work the same way on both versions. Retrieving Standard In ---------------------- Until Flake8 2.6, getting the code on standard in from a plugin has been simple: .. code-block:: python import pep8 stdin = pep8.get_stdin_value() In 2.6 you now have to know whether to use ``pep8`` or ``pycodestyle`` since Flake8 2.6 made a hard change to ``pycodestyle``. The reason you need to know which module to use is because standard in can be exhausted and Flake8 does some work to cache the value so that call always returns the desired data. In 3.0, Flake8 no longer monkey-patches those modules. To accommodate this, this package provides: .. code-block:: python from flake8_polyfill import stdin stdin.monkey_patch('all') stdin.monkey_patch('pep8') stdin.monkey_patch('pycodestyle') This allows you to have the polyfill module monkey-patch what you want so it is always monkey-patched. It will also do so in an intelligent way. Version Comparison ------------------ Flake8 2.x did not include an object that would allow for easy version comparison. Flake8 3.0, however, added a ``__version_info__`` attribute. For consistency, Flake8 Polyfill will turn 2.x's version string into a tuple suitable for comparison. .. code-block:: python from flake8_polyfill import version if (2, 4) <= version.version_info < (2, 6): # ... elif (2, 6) <= version.version_info < (3, 0): # ... elif (3, 0) <= version.version_info < (4, 0): # ... License ======= MIT Creator ======= Ian Cordasco flake8-polyfill-1.0.2/src/0000775000175000017500000000000013221714277016713 5ustar icordascicordasc00000000000000flake8-polyfill-1.0.2/src/flake8_polyfill/0000775000175000017500000000000013221714277021777 5ustar icordascicordasc00000000000000flake8-polyfill-1.0.2/src/flake8_polyfill/options.py0000664000175000017500000000666313221714170024047 0ustar icordascicordasc00000000000000"""Option handling polyfill for Flake8 2.x and 3.x.""" import optparse import os def register(parser, *args, **kwargs): r"""Register an option for the Option Parser provided by Flake8. :param parser: The option parser being used by Flake8 to handle command-line options. :param \*args: Positional arguments that you might otherwise pass to ``add_option``. :param \*\*kwargs: Keyword arguments you might otherwise pass to ``add_option``. """ try: # Flake8 3.x registration parser.add_option(*args, **kwargs) except (optparse.OptionError, TypeError): # Flake8 2.x registration # Pop Flake8 3 parameters out of the kwargs so they don't cause a # conflict. parse_from_config = kwargs.pop('parse_from_config', False) comma_separated_list = kwargs.pop('comma_separated_list', False) normalize_paths = kwargs.pop('normalize_paths', False) # In the unlikely event that the developer has specified their own # callback, let's pop that and deal with that as well. base_callback = kwargs.pop('callback', store_callback) callback = generate_callback_from(comma_separated_list, normalize_paths, base_callback) kwargs['callback'] = callback kwargs['action'] = 'callback' # We've updated our args and kwargs and can now rather confidently # call add_option. option = parser.add_option(*args, **kwargs) if parse_from_config: parser.config_options.append(option.get_opt_string().lstrip('-')) def parse_comma_separated_list(value): """Parse a comma-separated list. :param value: String or list of strings to be parsed and normalized. :returns: List of values with whitespace stripped. :rtype: list """ if not value: return [] if not isinstance(value, (list, tuple)): value = value.split(',') return [item.strip() for item in value] def normalize_path(path, parent=os.curdir): """Normalize a single-path. :returns: The normalized path. :rtype: str """ # NOTE(sigmavirus24): Using os.path.sep allows for Windows paths to # be specified and work appropriately. separator = os.path.sep if separator in path: path = os.path.abspath(os.path.join(parent, path)) return path.rstrip(separator) def parse_normalized_paths(value): """Normalize the path(s) value.""" if isinstance(value, list): normalized = [normalize_path(s) for s in value] else: normalized = normalize_path(value) return normalized def store_callback(option, opt_str, value, parser, *args, **kwargs): """Implement optparse's "store" action as a callback.""" setattr(parser.values, option.dest, value) def generate_callback_from(comma_separated_list, normalize_paths, base_callback): """Generate a callback from parameters provided for the option.""" def _callback(option, opt_str, value, parser, *args, **kwargs): """Wrap `base_callback` by transforming `value` for option params.""" if comma_separated_list: value = parse_comma_separated_list(value) if normalize_paths: value = parse_normalized_paths(value) base_callback(option, opt_str, value, parser, *args, **kwargs) return _callback flake8-polyfill-1.0.2/src/flake8_polyfill/version.py0000664000175000017500000000037113221714170024027 0ustar icordascicordasc00000000000000"""Version information for Flake8 2.x and 3.x.""" import flake8 version_info = getattr(flake8, '__version_info__', None) if version_info is None: version_info = tuple( int(i) for i in flake8.__version__.split('.') if i.isdigit() ) flake8-polyfill-1.0.2/src/flake8_polyfill/__init__.py0000664000175000017500000000022613221714170024100 0ustar icordascicordasc00000000000000"""The polyfill package for Flake8 plugins.""" __version__ = '1.0.2' __version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit()) flake8-polyfill-1.0.2/src/flake8_polyfill/stdin.py0000664000175000017500000000277013221714170023470 0ustar icordascicordasc00000000000000"""Monkey-patching for pep8 and pycodestyle.""" try: import pep8 except ImportError: pep8 = None try: import pycodestyle except ImportError: pycodestyle = None from flake8_polyfill import version __all__ = ('monkey_patch',) modules = { 'pep8': [pep8], 'pycodestyle': [pycodestyle], 'all': [pep8, pycodestyle], } def monkey_patch(which): """Monkey-patch the specified module with the appropriate stdin. On Flake8 2.5 and lower, Flake8 would would monkey-patch ``pep8.stdin_get_value`` for everyone. This avoided problems where stdin might be exhausted. On Flake8 2.6, Flake8 stopped patching ``pep8`` and started monkey-patching ``pycodestyle.stdin_get_value``. On Flake8 3.x, Flake8 has no need to monkey patch either ``pep8`` or ``pycodestyle``. This function accepts three parameters: - pep8 - pycodestyle - all "all" is a special value that will monkey-patch both "pep8" and "pycodestyle". :param str which: The name of the module to patch. :returns: Nothing. :rtype: NoneType """ if (2, 0) <= version.version_info < (3, 0): from flake8.engine import pep8 as _pep8 stdin_get_value = _pep8.stdin_get_value elif (3, 0) <= version.version_info < (4, 0): from flake8 import utils stdin_get_value = utils.stdin_get_value for module in modules[which]: if module is None: continue module.stdin_get_value = stdin_get_value flake8-polyfill-1.0.2/src/flake8_polyfill.egg-info/0000775000175000017500000000000013221714277023471 5ustar icordascicordasc00000000000000flake8-polyfill-1.0.2/src/flake8_polyfill.egg-info/dependency_links.txt0000664000175000017500000000000113221714277027537 0ustar icordascicordasc00000000000000 flake8-polyfill-1.0.2/src/flake8_polyfill.egg-info/SOURCES.txt0000664000175000017500000000072713221714277025363 0ustar icordascicordasc00000000000000AUTHORS.rst CHANGELOG.rst CONTRIBUTING.rst LICENSE MANIFEST.in README.rst setup.cfg setup.py src/flake8_polyfill/__init__.py src/flake8_polyfill/options.py src/flake8_polyfill/stdin.py src/flake8_polyfill/version.py src/flake8_polyfill.egg-info/PKG-INFO src/flake8_polyfill.egg-info/SOURCES.txt src/flake8_polyfill.egg-info/dependency_links.txt src/flake8_polyfill.egg-info/requires.txt src/flake8_polyfill.egg-info/top_level.txt tests/test_options.py tests/test_stdin.pyflake8-polyfill-1.0.2/src/flake8_polyfill.egg-info/requires.txt0000664000175000017500000000000713221714277026066 0ustar icordascicordasc00000000000000flake8 flake8-polyfill-1.0.2/src/flake8_polyfill.egg-info/PKG-INFO0000664000175000017500000001153313221714277024571 0ustar icordascicordasc00000000000000Metadata-Version: 1.1 Name: flake8-polyfill Version: 1.0.2 Summary: Polyfill package for Flake8 plugins Home-page: https://gitlab.com/pycqa/flake8-polyfill Author: Ian Cordasco Author-email: graffatcolmingov@gmail.com License: MIT Description-Content-Type: UNKNOWN Description: ============================= Polyfill for Flake8 Plugins ============================= ``flake8-polyfill`` is a package that provides some compatibility helpers for Flake8 plugins that intend to support Flake8 2.x and 3.x simultaneously. Installation ============ .. code-block:: bash pip install flake8-polyfill Usage ===== Option Handling --------------- One problem area with compatibility with Flake8 2.x and 3.x is the registering options and receiving the parsed values. Flake8 3.0 added extra parameters to the ``add_option`` method which don't have the same effect on Flake8 2.x. To accomodate the change, this polyfill module allows you to do: .. code-block:: python from flake8_polyfill import options class MyFlake8Plugin(object): @classmethod def add_options(cls, parser): options.register(parser, '--my-long-option-name', parse_from_config=True, comma_separated_list=True, default='...', help='...') options.register(parser, '-m', '--my-other-long-option-name', parse_from_config=True, normalize_paths=True, default='...', help='...') @classmethod def parse_options(cls, values): cls.my_long_option_name = values.my_long_option_name cls.my_other_long_option_name = values.my_other_long_option_name And have the code work the same way on both versions. Retrieving Standard In ---------------------- Until Flake8 2.6, getting the code on standard in from a plugin has been simple: .. code-block:: python import pep8 stdin = pep8.get_stdin_value() In 2.6 you now have to know whether to use ``pep8`` or ``pycodestyle`` since Flake8 2.6 made a hard change to ``pycodestyle``. The reason you need to know which module to use is because standard in can be exhausted and Flake8 does some work to cache the value so that call always returns the desired data. In 3.0, Flake8 no longer monkey-patches those modules. To accommodate this, this package provides: .. code-block:: python from flake8_polyfill import stdin stdin.monkey_patch('all') stdin.monkey_patch('pep8') stdin.monkey_patch('pycodestyle') This allows you to have the polyfill module monkey-patch what you want so it is always monkey-patched. It will also do so in an intelligent way. Version Comparison ------------------ Flake8 2.x did not include an object that would allow for easy version comparison. Flake8 3.0, however, added a ``__version_info__`` attribute. For consistency, Flake8 Polyfill will turn 2.x's version string into a tuple suitable for comparison. .. code-block:: python from flake8_polyfill import version if (2, 4) <= version.version_info < (2, 6): # ... elif (2, 6) <= version.version_info < (3, 0): # ... elif (3, 0) <= version.version_info < (4, 0): # ... License ======= MIT Creator ======= Ian Cordasco Platform: UNKNOWN Classifier: Environment :: Console Classifier: Framework :: Flake8 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Quality Assurance flake8-polyfill-1.0.2/src/flake8_polyfill.egg-info/top_level.txt0000664000175000017500000000002013221714277026213 0ustar icordascicordasc00000000000000flake8_polyfill flake8-polyfill-1.0.2/tests/0000775000175000017500000000000013221714277017266 5ustar icordascicordasc00000000000000flake8-polyfill-1.0.2/tests/test_stdin.py0000664000175000017500000000474013221714170022015 0ustar icordascicordasc00000000000000"""Tests for polyfill's stdin monkey patching.""" import pep8 import pycodestyle import pytest from flake8_polyfill import stdin from flake8_polyfill import version def test_modules_dict(): """Verify that it works the way we expect.""" assert len(stdin.modules['pep8']) == 1 assert stdin.modules['pep8'] == [pep8] assert len(stdin.modules['pycodestyle']) == 1 assert stdin.modules['pycodestyle'] == [pycodestyle] assert len(stdin.modules['all']) == 2 assert stdin.modules['all'] == [pep8, pycodestyle] @pytest.fixture def pep8_mod(request): """Fixture to replace pep8's default stdin_get_value.""" original_stdin_get_value = pep8.stdin_get_value def replace(): pep8.stdin_get_value = original_stdin_get_value request.addfinalizer(replace) return pep8 @pytest.fixture def pycodestyle_mod(request): """Fixture to replace pycodestyle's default stdin_get_value.""" original_stdin_get_value = pycodestyle.stdin_get_value def replace(): pycodestyle.stdin_get_value = original_stdin_get_value request.addfinalizer(replace) return pycodestyle # NOTE(sigmavirus24): These are weak tests but *shrug* I'm not sure of a # better way to test these. def test_monkey_patch_all(pep8_mod, pycodestyle_mod): """Verify we monkey patch everything.""" stdin.monkey_patch('all') assert pep8_mod.stdin_get_value is pycodestyle_mod.stdin_get_value @pytest.mark.skipif( (2, 5) < version.version_info < (2, 7), reason='They are the same on everything less than 2.6.' ) def test_monkey_patch_pep8(pep8_mod): """Verify we monkey patch pep8 only.""" stdin.monkey_patch('pep8') assert pep8_mod.stdin_get_value is not pycodestyle.stdin_get_value @pytest.mark.skipif( version.version_info < (2, 6), reason='They are the same on everything less than 2.6.' ) def test_monkey_patch_pycodestyle(pycodestyle_mod): """Verify we monkey patch pycodestyle only.""" stdin.monkey_patch('pycodestyle') assert pep8.stdin_get_value is not pycodestyle_mod.stdin_get_value @pytest.mark.skipif( version.version_info < (3, 0) or version.version_info > (4, 0), reason='Requires Flake8 3.x' ) def test_uses_flake8_util_stdin(pep8_mod, pycodestyle_mod): """Verify we monkey-patch using internal flake8 functions.""" import flake8.utils stdin.monkey_patch('all') assert pep8_mod.stdin_get_value is flake8.utils.stdin_get_value assert pycodestyle_mod.stdin_get_value is flake8.utils.stdin_get_value flake8-polyfill-1.0.2/tests/test_options.py0000664000175000017500000001144313221714170022365 0ustar icordascicordasc00000000000000"""Tests for our options submodule.""" import optparse import os import mock import pytest from flake8_polyfill import options @pytest.mark.parametrize('value,expected', [ ('E123,\n\tW234,\n E206', ['E123', 'W234', 'E206']), ('E123,W234,E206', ['E123', 'W234', 'E206']), (['E123', 'W234', 'E206'], ['E123', 'W234', 'E206']), (['E123', '\n\tW234', '\n E206'], ['E123', 'W234', 'E206']), ]) def test_parse_comma_separated_list(value, expected): """Verify that similar inputs produce identical outputs.""" assert options.parse_comma_separated_list(value) == expected @pytest.mark.parametrize('value,expected', [ ('flake8', 'flake8'), ('../flake8', os.path.abspath('../flake8')), ('flake8/', os.path.abspath('flake8')), ]) def test_normalize_path(value, expected): """Verify that we normalize paths provided to the tool.""" assert options.normalize_path(value) == expected @pytest.mark.parametrize('value,expected', [ ('file.py', 'file.py'), ('path/file.py', os.path.abspath('path/file.py')), (['file.py', 'path/file.py'], ['file.py', os.path.abspath('path/file.py')]), ]) def test_parse_normalized_paths(value, expected): """Verify that we handle strings and lists when normalizing paths.""" assert options.parse_normalized_paths(value) == expected @pytest.mark.parametrize( # NOTE: `defaults` has NO impact, since the callback being called implies # that a `value` was specified. 'comma_separated_list, normalize_paths, defaults, value, expected_value', [ (True, True, {}, 'val', 'N(C(val))'), (True, True, {'foo': 'defaultval'}, 'val', 'N(C(val))'), (True, False, {}, 'val', 'C(val)'), (True, False, {'foo': 'defaultval'}, 'val', 'C(val)'), (False, False, {}, 'val', 'val'), (False, False, {'foo': 'defaultval'}, 'val', 'val'), ] ) def test_generate_callback_from_composition( comma_separated_list, normalize_paths, defaults, value, expected_value, ): """Verify our generate_callback_from composition. We mock out parse_comma_separated_list and parse_normalized_paths with simple string transformations for better readability. """ dest = 'foo' opt_str = '--foo' option = optparse.Option(opt_str, dest=dest) parser = mock.Mock(values=optparse.Values(defaults)) base_callback = mock.Mock() callback = options.generate_callback_from( comma_separated_list=comma_separated_list, normalize_paths=normalize_paths, base_callback=base_callback, ) with mock.patch('flake8_polyfill.options.parse_comma_separated_list') as \ parse_comma_separated_list, \ mock.patch('flake8_polyfill.options.parse_normalized_paths') as \ parse_normalized_paths: parse_comma_separated_list.side_effect = lambda v: 'C({})'.format(v) parse_normalized_paths.side_effect = lambda v: 'N({})'.format(v) callback(option, opt_str, value, parser) base_callback.assert_called_with(option, opt_str, expected_value, parser) def test_store_callback(): """Verify the default callback behaves like option with action='store'.""" dest = 'foo' opt_str = '--foo' option = optparse.Option(opt_str, dest=dest) parser = mock.Mock(values=optparse.Values({'foo': 'defaultval'})) options.store_callback(option, opt_str, 'val', parser) assert parser.values.foo == 'val' @pytest.fixture def parser(): """Provide a pycodestyle-esque OptionParser instance.""" parser = optparse.OptionParser('flake8') parser.config_options = [] return parser def test_register_with_store_callback(parser): """Verify we handle typical no-custom-callback case (integration test).""" options.register(parser, '--foo', default=['path/file.py'], type='string', comma_separated_list=True, normalize_paths=True) values, _ = parser.parse_args([]) assert values.foo == ['path/file.py'] # default is used in its entirety values, _ = parser.parse_args(['--foo=file.py,path/file.py']) assert values.foo == ['file.py', os.path.abspath('path/file.py')] def test_register_with_custom_callback(parser): """Verify we handle custom callback (integration test).""" def custom_callback(option, opt_str, value, parser, *args, **kwargs): parser.values.count = len(value) options.register(parser, '--foo', type='string', callback=custom_callback, comma_separated_list=True, normalize_paths=True) values, _ = parser.parse_args(['--foo=file.py,path/file.py']) assert values.count == 2 def test_register_parse_from_config(parser): """Verify we append to config_options on registration.""" options.register(parser, '--select', default='E123,W504', parse_from_config=True) assert 'select' in parser.config_options flake8-polyfill-1.0.2/setup.py0000664000175000017500000000300713221714170017626 0ustar icordascicordasc00000000000000# -*- coding: utf-8 -*- """Packaging logic for Flake8's polyfill.""" import io import os import sys import setuptools sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) import flake8_polyfill # noqa requires = ['flake8'] def get_long_description(): """Generate a long description from the README file.""" descr = [] for fname in ('README.rst',): with io.open(fname, encoding='utf-8') as f: descr.append(f.read()) return '\n\n'.join(descr) setuptools.setup( name='flake8-polyfill', license='MIT', version=flake8_polyfill.__version__, description='Polyfill package for Flake8 plugins', long_description=get_long_description(), author='Ian Cordasco', author_email='graffatcolmingov@gmail.com', url='https://gitlab.com/pycqa/flake8-polyfill', package_dir={'': 'src'}, packages=[ 'flake8_polyfill', ], install_requires=requires, classifiers=[ "Environment :: Console", "Framework :: Flake8", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Quality Assurance", ], ) flake8-polyfill-1.0.2/CONTRIBUTING.rst0000664000175000017500000000000013221714170020543 0ustar icordascicordasc00000000000000flake8-polyfill-1.0.2/PKG-INFO0000664000175000017500000001153313221714277017224 0ustar icordascicordasc00000000000000Metadata-Version: 1.1 Name: flake8-polyfill Version: 1.0.2 Summary: Polyfill package for Flake8 plugins Home-page: https://gitlab.com/pycqa/flake8-polyfill Author: Ian Cordasco Author-email: graffatcolmingov@gmail.com License: MIT Description-Content-Type: UNKNOWN Description: ============================= Polyfill for Flake8 Plugins ============================= ``flake8-polyfill`` is a package that provides some compatibility helpers for Flake8 plugins that intend to support Flake8 2.x and 3.x simultaneously. Installation ============ .. code-block:: bash pip install flake8-polyfill Usage ===== Option Handling --------------- One problem area with compatibility with Flake8 2.x and 3.x is the registering options and receiving the parsed values. Flake8 3.0 added extra parameters to the ``add_option`` method which don't have the same effect on Flake8 2.x. To accomodate the change, this polyfill module allows you to do: .. code-block:: python from flake8_polyfill import options class MyFlake8Plugin(object): @classmethod def add_options(cls, parser): options.register(parser, '--my-long-option-name', parse_from_config=True, comma_separated_list=True, default='...', help='...') options.register(parser, '-m', '--my-other-long-option-name', parse_from_config=True, normalize_paths=True, default='...', help='...') @classmethod def parse_options(cls, values): cls.my_long_option_name = values.my_long_option_name cls.my_other_long_option_name = values.my_other_long_option_name And have the code work the same way on both versions. Retrieving Standard In ---------------------- Until Flake8 2.6, getting the code on standard in from a plugin has been simple: .. code-block:: python import pep8 stdin = pep8.get_stdin_value() In 2.6 you now have to know whether to use ``pep8`` or ``pycodestyle`` since Flake8 2.6 made a hard change to ``pycodestyle``. The reason you need to know which module to use is because standard in can be exhausted and Flake8 does some work to cache the value so that call always returns the desired data. In 3.0, Flake8 no longer monkey-patches those modules. To accommodate this, this package provides: .. code-block:: python from flake8_polyfill import stdin stdin.monkey_patch('all') stdin.monkey_patch('pep8') stdin.monkey_patch('pycodestyle') This allows you to have the polyfill module monkey-patch what you want so it is always monkey-patched. It will also do so in an intelligent way. Version Comparison ------------------ Flake8 2.x did not include an object that would allow for easy version comparison. Flake8 3.0, however, added a ``__version_info__`` attribute. For consistency, Flake8 Polyfill will turn 2.x's version string into a tuple suitable for comparison. .. code-block:: python from flake8_polyfill import version if (2, 4) <= version.version_info < (2, 6): # ... elif (2, 6) <= version.version_info < (3, 0): # ... elif (3, 0) <= version.version_info < (4, 0): # ... License ======= MIT Creator ======= Ian Cordasco Platform: UNKNOWN Classifier: Environment :: Console Classifier: Framework :: Flake8 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Quality Assurance flake8-polyfill-1.0.2/AUTHORS.rst0000664000175000017500000000013413221714170017771 0ustar icordascicordasc00000000000000Creator ======= * Ian Cordasco Contributors ============ * Fabian Neundorf * Saif Hakim flake8-polyfill-1.0.2/MANIFEST.in0000664000175000017500000000031313221714170017647 0ustar icordascicordasc00000000000000include *.rst include CONTRIBUTORS.txt include LICENSE global-exclude *.pyc recursive-include docs *.rst *.py recursive-include tests *.py *.ini *.rst *_diff recursive-include src *.py prune docs/build/ flake8-polyfill-1.0.2/setup.cfg0000664000175000017500000000021613221714277017744 0ustar icordascicordasc00000000000000[bdist_wheel] universal = 1 [pytest] norecursedirs = .git .* *.egg* old docs dist build addopts = -rw [egg_info] tag_build = tag_date = 0