diff --git a/.travis.yml b/.travis.yml index 3c7106c..9388563 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ env: - FLAKE8_VERSION="3.2.1" install: - - pip install poetry - - poetry install - - if [[ -n "$FLAKE8_VERSION" ]]; then poetry run pip install flake8=="$FLAKE8_VERSION"; fi + - pip install pycodestyle + - if [[ -n "$FLAKE8_VERSION" ]]; then pip install flake8=="$FLAKE8_VERSION"; fi + - python setup.py install script: - - poetry run pytest + - pytest diff --git a/README.md b/README.md index f0eaeba..ca45d12 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,11 @@ Error codes Changes ------- +##### 3.1.2 - 2019-31-10 + +* Swapped back from poetry to setup.py :(....python ecosystem issues.... +* single function refactor code + ##### 3.1.1 - 2019-03-12 * Fix reading from stdin when it is closed (requires flake8 > 2.1). diff --git a/flake8_print.py b/flake8_print.py index a564646..b85480f 100644 --- a/flake8_print.py +++ b/flake8_print.py @@ -8,7 +8,7 @@ except ImportError: from flake8 import utils as stdin_utils -__version__ = "3.1.1" +__version__ = "3.1.2" PRINT_FUNCTION_NAME = "print" PPRINT_FUNCTION_NAME = "pprint" @@ -91,11 +91,20 @@ def run(self): parser = PrintFinder() parser.visit(self.tree) - for error, message in parser.prints_used.items(): - if not pycodestyle.noqa(self.lines[error[0] - 1]): - yield (error[0], error[1], message, PrintChecker) + error_dicts = (parser.prints_used, parser.prints_redefined) + errors_seen = set() + + for index, error_dict in enumerate(error_dicts): + for error, message in error_dict.items(): + if error in errors_seen: + continue + + code = message.split(' ', 1)[0] + line = self.lines[error[0] - 1] + line_has_noqa = bool(pycodestyle.noqa(line)) - for error, message in parser.prints_redefined.items(): - if error not in parser.prints_used: - if not pycodestyle.noqa(self.lines[error[0] - 1]): - yield (error[0], error[1], message, PrintChecker) + if line_has_noqa is True and code in line: + continue + + errors_seen.add(error) + yield (error[0], error[1], message, PrintChecker) diff --git a/pyproject.toml b/pyproject.toml.bak similarity index 100% rename from pyproject.toml rename to pyproject.toml.bak diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..305cfff --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[aliases] +test=pytest diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..da78b23 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +# coding: utf-8 + +from __future__ import with_statement +from setuptools import setup + + +def get_version(fname='flake8_print.py'): + with open(fname) as f: + for line in f: + if line.startswith('__version__'): + return eval(line.split('=')[-1]) + + +def get_long_description(): + descr = [] + for fname in ('README.md',): + with open(fname) as f: + descr.append(f.read()) + return '\n\n'.join(descr) + + +install_requires = ['flake8>=1.5', 'six', 'pycodestyle'] + +test_requires = ['pytest', 'flake8>=1.5', 'pycodestyle'] + +setup( + name='flake8-print', + version=get_version(), + description="print statement checker plugin for flake8", + long_description=get_long_description(), + keywords='flake8 print', + author='Joseph Kahn', + author_email='josephbkahn@gmail.com', + url='https://github.com/jbkahn/flake8-print', + license='MIT', + py_modules=['flake8_print'], + zip_safe=False, + entry_points={ + 'flake8.extension': [ + 'T00 = flake8_print:PrintChecker', + ], + }, + install_requires=install_requires, + tests_require=test_requires, + setup_requires=['pytest-runner'], + test_suite="nose.collector", + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Environment :: Console', + 'Framework :: Flake8', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Software Development :: Quality Assurance', + ], +) \ No newline at end of file diff --git a/test_linter.py b/test_linter.py index 97a153a..067374a 100644 --- a/test_linter.py +++ b/test_linter.py @@ -64,9 +64,18 @@ def check_code_for_print_statements(code): class TestNoQA(object): @pytest.mark.skipif(sys.version_info < (2, 7), reason="Python 2.6 does not support noqa") def test_skips_noqa(self): - result = check_code_for_print_statements("print(4) # noqa") + result = check_code_for_print_statements("print(4) # noqa") assert result == list() + def test_skips_noqa__with_specific_error_code(self): + result = check_code_for_print_statements("print(4) # noqa: T001") + assert result == list() + + @pytest.mark.skip(reason="not supported by pycodestyle ast checks") + def test_skips_noqa__without_specific_error_code(self): + result = check_code_for_print_statements("print(4) # noqa: E731") + assert result == [1] + @pytest.mark.skipif(True, reason="no idea how to get this to work without local line") def test_skips_noqa_multiline_end(self): result = check_code_for_print_statements(