From 56e1864867d45d6da689d0fcf0316f9541600917 Mon Sep 17 00:00:00 2001 From: Robpol86 Date: Sat, 14 Nov 2015 17:24:31 -0800 Subject: [PATCH] Fixed compatibility with latest pep257. pep257 significantly changed configuration handling from 0.6.0 to 0.7.0. Looks like they support multiple config files that apply only to that directory and its subdirectories. But the change impacting flake8-pep257 was that pep257 no longer exposes 'ignore' config settings. Instead it reads the 'ignore' value in a private method and then subtracts it from all valid error codes and exposes that. Flake8 doesn't behave this way. This fix implements my own config file reader using a couple of public APIs, reading only the top-most (current working directory) config file (same behavior as pep257 0.6.0). Fixes https://github.com/Robpol86/flake8-pep257/issues/4 --- README.rst | 6 ++++++ flake8_pep257.py | 18 +++++++++++++----- setup.py | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index aa57d2b..1e843ce 100644 --- a/README.rst +++ b/README.rst @@ -62,6 +62,12 @@ Changelog This project adheres to `Semantic Versioning `_. +1.0.4 - 2015-11-14 +------------------ + +Fixed + * pep257 v0.7.0 compatibility. + 1.0.3 - 2015-05-31 ------------------ diff --git a/flake8_pep257.py b/flake8_pep257.py index 2884c53..089c5df 100644 --- a/flake8_pep257.py +++ b/flake8_pep257.py @@ -5,6 +5,7 @@ """ import codecs +import os import pep257 import pep8 @@ -78,11 +79,18 @@ def parse_options(cls, options): cls.options['ignore'] = options.ignore # Handle pep257 options. - opt_parser = pep257.get_option_parser() - setattr(opt_parser, '_get_args', lambda *_: list()) - native_options = vars(pep257.get_options(['.'], opt_parser)) - native_options.pop('match', None) - native_options.pop('match_dir', None) + config = pep257.RawConfigParser() + for file_name in pep257.ConfigurationParser.PROJECT_CONFIG_FILES: + if config.read(os.path.join(os.path.abspath('.'), file_name)): + break + if not config.has_section('pep257'): + return + native_options = dict() + for option in config.options('pep257'): + if option == 'ignore': + native_options['ignore'] = config.get('pep257', option) + if option in ('explain', 'source'): + native_options[option] = config.getboolean('pep257', option) native_options['show-source'] = native_options.pop('source', None) if native_options.get('ignore'): native_options['ignore'] = native_options['ignore'].split(',') diff --git a/setup.py b/setup.py index 6aab02c..7c07264 100755 --- a/setup.py +++ b/setup.py @@ -50,13 +50,13 @@ def safe_read(path): ], description='Flake8 plugin for the pep257 Python utility.', entry_points={'flake8.extension': 'D = flake8_pep257:Main'}, - install_requires=['flake8', 'pep257<0.7.0'], + install_requires=['flake8', 'pep257'], keywords='flake8 pep257 docstrings', license='MIT', long_description=safe_read('README.rst'), name='flake8-pep257', py_modules=['flake8_pep257'], url='https://github.com/Robpol86/flake8-pep257', - version='1.0.3', + version='1.0.4', zip_safe=True, )