PKLH*H((pytest_flake8.py"""py.test plugin to test with flake8.""" import os import re from flake8.engine import get_style_guide import py import pytest __version__ = '0.2' HISTKEY = "flake8/mtimes" def pytest_addoption(parser): """Hook up additional options.""" group = parser.getgroup("general") group.addoption( '--flake8', action='store_true', help="perform some flake8 sanity checks on .py files") parser.addini( "flake8-ignore", type="linelist", help="each line specifies a glob pattern and whitespace " "separated FLAKE8 errors or warnings which will be ignored, " "example: *.py W293") parser.addini( "flake8-max-line-length", help="maximum line length") def pytest_sessionstart(session): """Start a new session.""" config = session.config if config.option.flake8: config._flake8ignore = Ignorer(config.getini("flake8-ignore")) config._flake8maxlen = config.getini("flake8-max-line-length") config._flake8mtimes = config.cache.get(HISTKEY, {}) def pytest_collect_file(path, parent): """Filter files down to which ones should be checked.""" config = parent.config if config.option.flake8 and path.ext == '.py': flake8ignore = config._flake8ignore(path) if flake8ignore is not None: return Flake8Item(path, parent, flake8ignore, config._flake8maxlen) def pytest_sessionfinish(session): """Flush cache at end of run.""" config = session.config if hasattr(config, "_flake8mtimes"): config.cache.set(HISTKEY, config._flake8mtimes) class Flake8Error(Exception): """ indicates an error during flake8 checks. """ class Flake8Item(pytest.Item, pytest.File): def __init__(self, path, parent, flake8ignore, maxlength): super(Flake8Item, self).__init__(path, parent) self.add_marker("flake8") self.flake8ignore = flake8ignore self.maxlength = maxlength def setup(self): flake8mtimes = self.config._flake8mtimes self._flake8mtime = self.fspath.mtime() old = flake8mtimes.get(str(self.fspath), (0, [])) if old == (self._flake8mtime, self.flake8ignore): pytest.skip("file(s) previously passed FLAKE8 checks") def runtest(self): call = py.io.StdCapture.call found_errors, out, err = call( check_file, self.fspath, self.flake8ignore, self.maxlength) if found_errors: raise Flake8Error(out, err) # update mtime only if test passed # otherwise failures would not be re-run next time self.config._flake8mtimes[str(self.fspath)] = (self._flake8mtime, self.flake8ignore) def repr_failure(self, excinfo): if excinfo.errisinstance(Flake8Error): return excinfo.value.args[0] return super(Flake8Item, self).repr_failure(excinfo) def reportinfo(self): if self.flake8ignore: ignores = "(ignoring %s)" % " ".join(self.flake8ignore) else: ignores = "" return (self.fspath, -1, "FLAKE8-check%s" % ignores) class Ignorer: def __init__(self, ignorelines, coderex=re.compile("[EW]\d\d\d")): self.ignores = ignores = [] for line in ignorelines: i = line.find("#") if i != -1: line = line[:i] try: glob, ign = line.split(None, 1) except ValueError: glob, ign = None, line if glob and coderex.match(glob): glob, ign = None, line ign = ign.split() if "ALL" in ign: ign = None if glob and "/" != os.sep and "/" in glob: glob = glob.replace("/", os.sep) ignores.append((glob, ign)) def __call__(self, path): l = [] for (glob, ignlist) in self.ignores: if not glob or path.fnmatch(glob): if ignlist is None: return None l.extend(ignlist) return l def check_file(path, flake8ignore, maxlength): """Run flake8 over a single file, and return the number of failures.""" if maxlength: flake8_style = get_style_guide( parse_argv=False, paths=['--max-line-length', maxlength]) else: flake8_style = get_style_guide(parse_argv=False) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() return flake8_style.input_file(str(path), expected=flake8ignore) PKLHL|, +pytest_flake8-0.2.dist-info/DESCRIPTION.rstpy.test plugin for efficiently checking PEP8 compliance ======================================================= Usage ----- Install by running the command:: pip install pytest-flake8 After installing it, when you run tests with the option:: py.test --flake8 every file ending in ``.py`` will be discovered and checked with flake8. .. note:: If optional flake8 plugins are installed, those will be used automatically. No provisions have been made for configuring these via py.test. .. warning:: Running flake8 tests on your project is likely to cause a number of issues. The plugin allows one to configure on a per-project and per-file basis which errors or warnings to ignore, see flake8-ignore_. .. _flake8-ignore: Configuring FLAKE8 options per project and file ----------------------------------------------- Maximum line length can be configured for the whole project by adding a ``flake8-max-line-length`` option to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-max-line-length = 99 Note that the default will be what naturally comes with flake8_ (which it turn gets its default from pep8_). You may configure flake8-checking options for your project by adding an ``flake8-ignore`` entry to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-ignore = E201 E231 This would globally prevent complaints about two whitespace issues. Rerunning with the above example will now look better:: $ py.test -q --flake8 collecting ... collected 1 items . 1 passed in 0.01 seconds If you have some files where you want to specifically ignore some errors or warnings you can start a flake8-ignore line with a glob-pattern and a space-separated list of codes:: # content of setup.cfg [pytest] flake8-ignore = *.py E201 doc/conf.py ALL So if you have a conf.py like this:: # content of doc/conf.py func ( [1,2,3]) #this line lots pep8 errors :) then running again with the previous example will show a single failure and it will ignore doc/conf.py alltogether:: $ py.test --flake8 -v # verbose shows what is ignored ======================================= test session starts ======================================== platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.0 -- /Users/tholo/Source/pytest/bin/python cachedir: /Users/tholo/Source/pytest/src/verify/.cache rootdir: /Users/tholo/Source/angular/src/verify, inifile: setup.cfg plugins: flake8, cache collected 1 items myfile.py PASSED ========================================= 1 passed in 0.00 seconds ========================================= Note that doc/conf.py was not considered or imported. Notes ----- The repository of this plugin is at https://github.com/tholo/pytest-flake8 For more info on py.test see http://pytest.org The code is partially based on Ronny Pfannschmidt's pytest-codecheckers plugin. PKLH##,pytest_flake8-0.2.dist-info/entry_points.txt[pytest11] flake8 = pytest_flake8 PKLHtrr)pytest_flake8-0.2.dist-info/metadata.json{"classifiers": ["Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development", "Topic :: Software Development :: Quality Assurance", "Topic :: Software Development :: Testing"], "extensions": {"python.details": {"contacts": [{"email": "tholo@sigmasoft.com", "name": "Thorsten Lockert", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/tholo/pytest-flake8"}}, "python.exports": {"pytest11": {"flake8": "pytest_flake8"}}}, "extras": [], "generator": "bdist_wheel (0.27.0)", "license": "BSD License", "metadata_version": "2.0", "name": "pytest-flake8", "run_requires": [{"requires": ["flake8 (>=2.5)", "pytest (>=2.8)", "pytest-cache"]}], "summary": "pytest plugin to check FLAKE8 requirements", "version": "0.2"}PKLH>Z)pytest_flake8-0.2.dist-info/top_level.txtpytest_flake8 PKLHyCQ%nn!pytest_flake8-0.2.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.27.0) Root-Is-Purelib: true Tag: py2-none-any Tag: py3-none-any PKLHJ$pytest_flake8-0.2.dist-info/METADATAMetadata-Version: 2.0 Name: pytest-flake8 Version: 0.2 Summary: pytest plugin to check FLAKE8 requirements Home-page: https://github.com/tholo/pytest-flake8 Author: Thorsten Lockert Author-email: tholo@sigmasoft.com License: BSD License Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 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 Classifier: Topic :: Software Development :: Quality Assurance Classifier: Topic :: Software Development :: Testing Requires-Dist: flake8 (>=2.5) Requires-Dist: pytest (>=2.8) Requires-Dist: pytest-cache py.test plugin for efficiently checking PEP8 compliance ======================================================= Usage ----- Install by running the command:: pip install pytest-flake8 After installing it, when you run tests with the option:: py.test --flake8 every file ending in ``.py`` will be discovered and checked with flake8. .. note:: If optional flake8 plugins are installed, those will be used automatically. No provisions have been made for configuring these via py.test. .. warning:: Running flake8 tests on your project is likely to cause a number of issues. The plugin allows one to configure on a per-project and per-file basis which errors or warnings to ignore, see flake8-ignore_. .. _flake8-ignore: Configuring FLAKE8 options per project and file ----------------------------------------------- Maximum line length can be configured for the whole project by adding a ``flake8-max-line-length`` option to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-max-line-length = 99 Note that the default will be what naturally comes with flake8_ (which it turn gets its default from pep8_). You may configure flake8-checking options for your project by adding an ``flake8-ignore`` entry to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-ignore = E201 E231 This would globally prevent complaints about two whitespace issues. Rerunning with the above example will now look better:: $ py.test -q --flake8 collecting ... collected 1 items . 1 passed in 0.01 seconds If you have some files where you want to specifically ignore some errors or warnings you can start a flake8-ignore line with a glob-pattern and a space-separated list of codes:: # content of setup.cfg [pytest] flake8-ignore = *.py E201 doc/conf.py ALL So if you have a conf.py like this:: # content of doc/conf.py func ( [1,2,3]) #this line lots pep8 errors :) then running again with the previous example will show a single failure and it will ignore doc/conf.py alltogether:: $ py.test --flake8 -v # verbose shows what is ignored ======================================= test session starts ======================================== platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.0 -- /Users/tholo/Source/pytest/bin/python cachedir: /Users/tholo/Source/pytest/src/verify/.cache rootdir: /Users/tholo/Source/angular/src/verify, inifile: setup.cfg plugins: flake8, cache collected 1 items myfile.py PASSED ========================================= 1 passed in 0.00 seconds ========================================= Note that doc/conf.py was not considered or imported. Notes ----- The repository of this plugin is at https://github.com/tholo/pytest-flake8 For more info on py.test see http://pytest.org The code is partially based on Ronny Pfannschmidt's pytest-codecheckers plugin. PKLH1"pytest_flake8-0.2.dist-info/RECORDpytest_flake8.py,sha256=-sH5ez9fZ97a8Ua8IDwzfSljM14-7BCquNVKxlrJTxQ,4648 pytest_flake8-0.2.dist-info/DESCRIPTION.rst,sha256=sv7kUNh03erQViDyjCRhPz7g4reUy83Ych9CSlxVl9A,3038 pytest_flake8-0.2.dist-info/METADATA,sha256=ULSVagRjKV0W1gtFt-uM4L3FvaERvmYKiB08YRQj6DQ,4017 pytest_flake8-0.2.dist-info/RECORD,, pytest_flake8-0.2.dist-info/WHEEL,sha256=22a9oDdbpVoTeukNLAOY0JJtL4OnhDR-_josH9ArXbA,110 pytest_flake8-0.2.dist-info/entry_points.txt,sha256=PCaFT17ijyW9YA9dih7ERf-PDLzfQwFvXnQ_OiRrGgs,35 pytest_flake8-0.2.dist-info/metadata.json,sha256=WS2rsSyMQAtXcL059BW9vNMQMnxapcC7NXWYLwY6-YE,1138 pytest_flake8-0.2.dist-info/top_level.txt,sha256=v9R6Kge5Ary-JmC0xn4fZsk9M7WXZ02Nu2LXB1k6s-4,14 PKLH*H((pytest_flake8.pyPKLHL|, +Vpytest_flake8-0.2.dist-info/DESCRIPTION.rstPKLH##,}pytest_flake8-0.2.dist-info/entry_points.txtPKLHtrr)pytest_flake8-0.2.dist-info/metadata.jsonPKLH>Z)#pytest_flake8-0.2.dist-info/top_level.txtPKLHyCQ%nn!#pytest_flake8-0.2.dist-info/WHEELPKLHJ$$pytest_flake8-0.2.dist-info/METADATAPKLH1"4pytest_flake8-0.2.dist-info/RECORDPK7