Commit 149cf8e7 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 2.2.2

parent 48f682f3
CHANGES CHANGES
======= =======
2.2.2 - 2014-07-04
------------------
- Re-enable multiprocessing by default while fixing the issue Windows users
were seeing.
2.2.1 - 2014-06-30
------------------
- Turn off multiple jobs by default. To enable automatic use of all CPUs, use
``--jobs=auto``. Fixes #155 and #154.
2.2.0 - 2014-06-22
------------------
- New option ``doctests`` to run Pyflakes checks on doctests too
- New option ``jobs`` to launch multiple jobs in parallel
- Turn on using multiple jobs by default using the CPU count
- Add support for ``python -m flake8`` on Python 2.7 and Python 3
- Fix Git and Mercurial hooks: issues #88, #133, #148 and #149
- Fix crashes with Python 3.4 by upgrading dependencies
- Fix traceback when running tests with Python 2.6
- Fix the setuptools command ``python setup.py flake8`` to read
the project configuration
2.1.0 - 2013-10-26 2.1.0 - 2013-10-26
------------------ ------------------
...@@ -14,6 +40,7 @@ CHANGES ...@@ -14,6 +40,7 @@ CHANGES
- Ignore .tox directories by default - Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages - Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23 2.0.0 - 2013-02-23
------------------ ------------------
...@@ -78,7 +105,7 @@ CHANGES ...@@ -78,7 +105,7 @@ CHANGES
- make sure mccabe catches the syntax errors as warnings - make sure mccabe catches the syntax errors as warnings
- pep8 upgrade - pep8 upgrade
- added max_line_length default value - added max_line_length default value
- added Flake8Command and entry points is setuptools is around - added Flake8Command and entry points if setuptools is around
- using the setuptools console wrapper when available - using the setuptools console wrapper when available
......
Metadata-Version: 1.1 Metadata-Version: 1.1
Name: flake8 Name: flake8
Version: 2.1.0 Version: 2.2.2
Summary: the modular source code checker: pep8, pyflakes and co Summary: the modular source code checker: pep8, pyflakes and co
Home-page: http://bitbucket.org/tarek/flake8 Home-page: http://bitbucket.org/tarek/flake8
Author: Ian Cordasco Author: Ian Cordasco
...@@ -86,6 +86,32 @@ Description: ====== ...@@ -86,6 +86,32 @@ Description: ======
CHANGES CHANGES
======= =======
2.2.2 - 2014-07-04
------------------
- Re-enable multiprocessing by default while fixing the issue Windows users
were seeing.
2.2.1 - 2014-06-30
------------------
- Turn off multiple jobs by default. To enable automatic use of all CPUs, use
``--jobs=auto``. Fixes #155 and #154.
2.2.0 - 2014-06-22
------------------
- New option ``doctests`` to run Pyflakes checks on doctests too
- New option ``jobs`` to launch multiple jobs in parallel
- Turn on using multiple jobs by default using the CPU count
- Add support for ``python -m flake8`` on Python 2.7 and Python 3
- Fix Git and Mercurial hooks: issues #88, #133, #148 and #149
- Fix crashes with Python 3.4 by upgrading dependencies
- Fix traceback when running tests with Python 2.6
- Fix the setuptools command ``python setup.py flake8`` to read
the project configuration
2.1.0 - 2013-10-26 2.1.0 - 2013-10-26
------------------ ------------------
...@@ -99,6 +125,7 @@ Description: ====== ...@@ -99,6 +125,7 @@ Description: ======
- Ignore .tox directories by default - Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages - Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23 2.0.0 - 2013-02-23
------------------ ------------------
...@@ -163,7 +190,7 @@ Description: ====== ...@@ -163,7 +190,7 @@ Description: ======
- make sure mccabe catches the syntax errors as warnings - make sure mccabe catches the syntax errors as warnings
- pep8 upgrade - pep8 upgrade
- added max_line_length default value - added max_line_length default value
- added Flake8Command and entry points is setuptools is around - added Flake8Command and entry points if setuptools is around
- using the setuptools console wrapper when available - using the setuptools console wrapper when available
......
Metadata-Version: 1.1 Metadata-Version: 1.1
Name: flake8 Name: flake8
Version: 2.1.0 Version: 2.2.2
Summary: the modular source code checker: pep8, pyflakes and co Summary: the modular source code checker: pep8, pyflakes and co
Home-page: http://bitbucket.org/tarek/flake8 Home-page: http://bitbucket.org/tarek/flake8
Author: Ian Cordasco Author: Ian Cordasco
...@@ -86,6 +86,32 @@ Description: ====== ...@@ -86,6 +86,32 @@ Description: ======
CHANGES CHANGES
======= =======
2.2.2 - 2014-07-04
------------------
- Re-enable multiprocessing by default while fixing the issue Windows users
were seeing.
2.2.1 - 2014-06-30
------------------
- Turn off multiple jobs by default. To enable automatic use of all CPUs, use
``--jobs=auto``. Fixes #155 and #154.
2.2.0 - 2014-06-22
------------------
- New option ``doctests`` to run Pyflakes checks on doctests too
- New option ``jobs`` to launch multiple jobs in parallel
- Turn on using multiple jobs by default using the CPU count
- Add support for ``python -m flake8`` on Python 2.7 and Python 3
- Fix Git and Mercurial hooks: issues #88, #133, #148 and #149
- Fix crashes with Python 3.4 by upgrading dependencies
- Fix traceback when running tests with Python 2.6
- Fix the setuptools command ``python setup.py flake8`` to read
the project configuration
2.1.0 - 2013-10-26 2.1.0 - 2013-10-26
------------------ ------------------
...@@ -99,6 +125,7 @@ Description: ====== ...@@ -99,6 +125,7 @@ Description: ======
- Ignore .tox directories by default - Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages - Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23 2.0.0 - 2013-02-23
------------------ ------------------
...@@ -163,7 +190,7 @@ Description: ====== ...@@ -163,7 +190,7 @@ Description: ======
- make sure mccabe catches the syntax errors as warnings - make sure mccabe catches the syntax errors as warnings
- pep8 upgrade - pep8 upgrade
- added max_line_length default value - added max_line_length default value
- added Flake8Command and entry points is setuptools is around - added Flake8Command and entry points if setuptools is around
- using the setuptools console wrapper when available - using the setuptools console wrapper when available
......
...@@ -3,18 +3,21 @@ CONTRIBUTORS.txt ...@@ -3,18 +3,21 @@ CONTRIBUTORS.txt
LICENSE LICENSE
MANIFEST.in MANIFEST.in
README.rst README.rst
setup.cfg
setup.py setup.py
flake8/__init__.py flake8/__init__.py
flake8/__init__.pyc flake8/__init__.pyc
flake8/__main__.py
flake8/_pyflakes.py flake8/_pyflakes.py
flake8/_pyflakes.pyc flake8/_pyflakes.pyc
flake8/engine.py flake8/engine.py
flake8/engine.py.orig
flake8/engine.pyc flake8/engine.pyc
flake8/hooks.py flake8/hooks.py
flake8/hooks.py.orig
flake8/hooks.pyc
flake8/main.py flake8/main.py
flake8/main.pyc flake8/main.pyc
flake8/reporter.py
flake8/reporter.pyc
flake8/run.py flake8/run.py
flake8/util.py flake8/util.py
flake8/util.pyc flake8/util.pyc
...@@ -24,11 +27,6 @@ flake8.egg-info/dependency_links.txt ...@@ -24,11 +27,6 @@ flake8.egg-info/dependency_links.txt
flake8.egg-info/entry_points.txt flake8.egg-info/entry_points.txt
flake8.egg-info/requires.txt flake8.egg-info/requires.txt
flake8.egg-info/top_level.txt flake8.egg-info/top_level.txt
flake8/__pycache__/__init__.cpython-32.pyc
flake8/__pycache__/_pyflakes.cpython-32.pyc
flake8/__pycache__/engine.cpython-32.pyc
flake8/__pycache__/main.cpython-32.pyc
flake8/__pycache__/util.cpython-32.pyc
flake8/tests/__init__.py flake8/tests/__init__.py
flake8/tests/__init__.pyc flake8/tests/__init__.pyc
flake8/tests/test_engine.py flake8/tests/test_engine.py
......
pyflakes >= 0.7.3 pyflakes >= 0.8.1
pep8 >= 1.4.6 pep8 >= 1.5.7
mccabe >= 0.2.1 mccabe >= 0.2.1
\ No newline at end of file
__version__ = '2.1.0' __version__ = '2.2.2'
No preview for this file type
from flake8.main import main
# python -m flake8 (with Python >= 2.7)
main()
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
try:
# The 'demandimport' breaks pyflakes and flake8._pyflakes
from mercurial import demandimport
except ImportError:
pass
else:
demandimport.disable()
import pyflakes import pyflakes
import pyflakes.checker import pyflakes.checker
...@@ -31,16 +38,23 @@ class FlakesChecker(pyflakes.checker.Checker): ...@@ -31,16 +38,23 @@ class FlakesChecker(pyflakes.checker.Checker):
name = 'pyflakes' name = 'pyflakes'
version = pyflakes.__version__ version = pyflakes.__version__
def __init__(self, tree, filename):
super(FlakesChecker, self).__init__(tree, filename,
withDoctest=self.withDoctest)
@classmethod @classmethod
def add_options(cls, parser): def add_options(cls, parser):
parser.add_option('--builtins', parser.add_option('--builtins',
help="define more built-ins, comma separated") help="define more built-ins, comma separated")
parser.config_options.append('builtins') parser.add_option('--doctests', default=False, action='store_true',
help="check syntax of the doctests")
parser.config_options.extend(['builtins', 'doctests'])
@classmethod @classmethod
def parse_options(cls, options): def parse_options(cls, options):
if options.builtins: if options.builtins:
cls.builtIns = cls.builtIns.union(options.builtins.split(',')) cls.builtIns = cls.builtIns.union(options.builtins.split(','))
cls.withDoctest = options.doctests
def run(self): def run(self):
for m in self.messages: for m in self.messages:
......
No preview for this file type
...@@ -5,6 +5,7 @@ import platform ...@@ -5,6 +5,7 @@ import platform
import pep8 import pep8
from flake8 import __version__ from flake8 import __version__
from flake8.reporter import multiprocessing, BaseQReport, QueueReport
from flake8.util import OrderedSet from flake8.util import OrderedSet
_flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search _flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search
...@@ -47,6 +48,17 @@ def get_parser(): ...@@ -47,6 +48,17 @@ def get_parser():
parser.remove_option(opt) parser.remove_option(opt)
except ValueError: except ValueError:
pass pass
if multiprocessing:
try:
auto = multiprocessing.cpu_count() or 1
except NotImplementedError:
auto = 1
parser.config_options.append('jobs')
parser.add_option('-j', '--jobs', type='string', default='',
help="number of jobs to run simultaneously, "
"or 'auto'")
parser.add_option('--exit-zero', action='store_true', parser.add_option('--exit-zero', action='store_true',
help="exit with code 0 even if there are errors") help="exit with code 0 even if there are errors")
for parser_hook in parser_hooks: for parser_hook in parser_hooks:
...@@ -58,8 +70,6 @@ def get_parser(): ...@@ -58,8 +70,6 @@ def get_parser():
class StyleGuide(pep8.StyleGuide): class StyleGuide(pep8.StyleGuide):
# Backward compatibility pep8 <= 1.4.2
checker_class = pep8.Checker
def input_file(self, filename, lines=None, expected=None, line_offset=0): def input_file(self, filename, lines=None, expected=None, line_offset=0):
"""Run all checks on a Python source file.""" """Run all checks on a Python source file."""
...@@ -81,6 +91,22 @@ def get_style_guide(**kwargs): ...@@ -81,6 +91,22 @@ def get_style_guide(**kwargs):
options = styleguide.options options = styleguide.options
for options_hook in options_hooks: for options_hook in options_hooks:
options_hook(options) options_hook(options)
if multiprocessing and options.jobs:
if options.jobs.isdigit():
n_jobs = int(options.jobs)
else:
try:
n_jobs = multiprocessing.cpu_count()
except NotImplementedError:
n_jobs = 1
if n_jobs > 1:
options.jobs = n_jobs
reporter = BaseQReport if options.quiet else QueueReport
report = styleguide.init_report(reporter)
report.input_file = styleguide.input_file
styleguide.runner = report.task_queue.put
return styleguide return styleguide
......
# -*- coding: utf-8 -*-
import re
import platform
import pep8
from flake8 import __version__
from flake8.reporter import multiprocessing, BaseQReport, QueueReport
from flake8.util import OrderedSet
_flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search
def _register_extensions():
"""Register all the extensions."""
extensions = OrderedSet()
extensions.add(('pep8', pep8.__version__))
parser_hooks = []
options_hooks = []
try:
from pkg_resources import iter_entry_points
except ImportError:
pass
else:
for entry in iter_entry_points('flake8.extension'):
checker = entry.load()
pep8.register_check(checker, codes=[entry.name])
extensions.add((checker.name, checker.version))
if hasattr(checker, 'add_options'):
parser_hooks.append(checker.add_options)
if hasattr(checker, 'parse_options'):
options_hooks.append(checker.parse_options)
return extensions, parser_hooks, options_hooks
def get_parser():
"""This returns an instance of optparse.OptionParser with all the
extensions registered and options set. This wraps ``pep8.get_parser``.
"""
(extensions, parser_hooks, options_hooks) = _register_extensions()
details = ', '.join(['%s: %s' % ext for ext in extensions])
python_version = get_python_version()
parser = pep8.get_parser('flake8', '%s (%s) %s' % (
__version__, details, python_version
))
for opt in ('--repeat', '--testsuite', '--doctest'):
try:
parser.remove_option(opt)
except ValueError:
pass
if multiprocessing:
try:
auto = multiprocessing.cpu_count() or 1
except NotImplementedError:
auto = 1
parser.config_options.append('jobs')
parser.add_option('-j', '--jobs', type='string', default='',
help="number of jobs to run simultaneously, "
"or 'auto'")
parser.add_option('--exit-zero', action='store_true',
help="exit with code 0 even if there are errors")
for parser_hook in parser_hooks:
parser_hook(parser)
parser.add_option('--install-hook', default=False, action='store_true',
help='Install the appropriate hook for this '
'repository.', dest='install_hook')
return parser, options_hooks
class StyleGuide(pep8.StyleGuide):
def input_file(self, filename, lines=None, expected=None, line_offset=0):
"""Run all checks on a Python source file."""
if self.options.verbose:
print('checking %s' % filename)
fchecker = self.checker_class(
filename, lines=lines, options=self.options)
# Any "# flake8: noqa" line?
if any(_flake8_noqa(line) for line in fchecker.lines):
return 0
return fchecker.check_all(expected=expected, line_offset=line_offset)
def get_style_guide(**kwargs):
"""Parse the options and configure the checker. This returns a sub-class
of ``pep8.StyleGuide``."""
kwargs['parser'], options_hooks = get_parser()
styleguide = StyleGuide(**kwargs)
options = styleguide.options
for options_hook in options_hooks:
options_hook(options)
if multiprocessing and options.jobs:
if options.jobs.isdigit():
n_jobs = int(options.jobs)
else:
try:
n_jobs = multiprocessing.cpu_count()
except NotImplementedError:
n_jobs = 1
if n_jobs > 1:
options.jobs = n_jobs
reporter = BaseQReport if options.quiet else QueueReport
report = styleguide.init_report(reporter)
report.input_file = styleguide.input_file
styleguide.runner = report.task_queue.put
return styleguide
def get_python_version():
# The implementation isn't all that important.
try:
impl = platform.python_implementation() + " "
except AttributeError: # Python 2.5
impl = ''
return '%s%s on %s' % (impl, platform.python_version(), platform.system())
No preview for this file type
...@@ -6,12 +6,6 @@ import stat ...@@ -6,12 +6,6 @@ import stat
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import shutil import shutil
from tempfile import mkdtemp from tempfile import mkdtemp
try:
# The 'demandimport' breaks pyflakes and flake8._pyflakes
from mercurial import demandimport
demandimport.disable()
except ImportError:
pass
try: try:
from configparser import ConfigParser from configparser import ConfigParser
except ImportError: # Python 2 except ImportError: # Python 2
...@@ -55,11 +49,8 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): ...@@ -55,11 +49,8 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
files_modified = [f for f in files_modified if f.endswith('.py')] files_modified = [f for f in files_modified if f.endswith('.py')]
flake8_style = get_style_guide( flake8_style = get_style_guide(config_file=DEFAULT_CONFIG, paths=['.'],
parse_argv=True, **options)
config_file=DEFAULT_CONFIG,
**options
)
# Copy staged versions to temporary directory # Copy staged versions to temporary directory
tmpdir = mkdtemp() tmpdir = mkdtemp()
...@@ -103,9 +94,7 @@ def hg_hook(ui, repo, **kwargs): ...@@ -103,9 +94,7 @@ def hg_hook(ui, repo, **kwargs):
complexity = ui.config('flake8', 'complexity', default=-1) complexity = ui.config('flake8', 'complexity', default=-1)
strict = ui.configbool('flake8', 'strict', default=True) strict = ui.configbool('flake8', 'strict', default=True)
ignore = ui.config('flake8', 'ignore', default=None) ignore = ui.config('flake8', 'ignore', default=None)
config = ui.config('flake8', 'config', default=True) config = ui.config('flake8', 'config', default=DEFAULT_CONFIG)
if config is True:
config = DEFAULT_CONFIG
paths = _get_files(repo, **kwargs) paths = _get_files(repo, **kwargs)
...@@ -117,7 +106,7 @@ def hg_hook(ui, repo, **kwargs): ...@@ -117,7 +106,7 @@ def hg_hook(ui, repo, **kwargs):
if complexity > -1: if complexity > -1:
options['max_complexity'] = complexity options['max_complexity'] = complexity
flake8_style = get_style_guide(parse_argv=True, config_file=config, flake8_style = get_style_guide(config_file=config, paths=['.'],
**options) **options)
report = flake8_style.check_files(paths) report = flake8_style.check_files(paths)
...@@ -136,10 +125,10 @@ def run(command, raw_output=False, decode=True): ...@@ -136,10 +125,10 @@ def run(command, raw_output=False, decode=True):
# endswith method. That should work but might still fail horribly. # endswith method. That should work but might still fail horribly.
if hasattr(stdout, 'decode'): if hasattr(stdout, 'decode'):
if decode: if decode:
stdout = stdout.decode() stdout = stdout.decode('utf-8')
if hasattr(stderr, 'decode'): if hasattr(stderr, 'decode'):
if decode: if decode:
stderr = stderr.decode() stderr = stderr.decode('utf-8')
if not raw_output: if not raw_output:
stdout = [line.strip() for line in stdout.splitlines()] stdout = [line.strip() for line in stdout.splitlines()]
stderr = [line.strip() for line in stderr.splitlines()] stderr = [line.strip() for line in stderr.splitlines()]
...@@ -194,7 +183,7 @@ if __name__ == '__main__': ...@@ -194,7 +183,7 @@ if __name__ == '__main__':
def _install_hg_hook(path): def _install_hg_hook(path):
if not os.path.isfile(path): if not os.path.isfile(path):
# Make the file so we can avoid IOError's # Make the file so we can avoid IOError's
open(path, 'w+').close() open(path, 'w').close()
c = ConfigParser() c = ConfigParser()
c.readfp(open(path, 'r')) c.readfp(open(path, 'r'))
...@@ -217,12 +206,13 @@ def _install_hg_hook(path): ...@@ -217,12 +206,13 @@ def _install_hg_hook(path):
c.set('flake8', 'strict', os.getenv('FLAKE8_STRICT', False)) c.set('flake8', 'strict', os.getenv('FLAKE8_STRICT', False))
if not c.has_option('flake8', 'ignore'): if not c.has_option('flake8', 'ignore'):
c.set('flake8', 'ignore', os.getenv('FLAKE8_IGNORE')) c.set('flake8', 'ignore', os.getenv('FLAKE8_IGNORE', ''))
if not c.has_option('flake8', 'lazy'): if not c.has_option('flake8', 'lazy'):
c.set('flake8', 'lazy', os.getenv('FLAKE8_LAZY', False)) c.set('flake8', 'lazy', os.getenv('FLAKE8_LAZY', False))
c.write(open(path, 'w+')) with open(path, 'w') as fd:
c.write(fd)
def install_hook(): def install_hook():
...@@ -238,7 +228,9 @@ def install_hook(): ...@@ -238,7 +228,9 @@ def install_hook():
status = 0 status = 0
if 'git' in vcs: if 'git' in vcs:
with open(vcs, 'w+') as fd: if os.path.exists(vcs):
sys.exit('Error: hook already exists (%s)' % vcs)
with open(vcs, 'w') as fd:
fd.write(git_hook_file) fd.write(git_hook_file)
# rwxr--r-- # rwxr--r--
os.chmod(vcs, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) os.chmod(vcs, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)
......
# -*- coding: utf-8 -*-
from __future__ import with_statement
import os
import sys
from subprocess import Popen, PIPE
try:
from mercurial import demandimport
demandimport.disable()
except ImportError:
pass
try:
from configparser import ConfigParser
except ImportError: # Python 2
from ConfigParser import ConfigParser
from flake8.engine import get_parser, get_style_guide
from flake8.main import DEFAULT_CONFIG
def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
"""This is the function used by the git hook.
:param int complexity: (optional), any value > 0 enables complexity
checking with mccabe
:param bool strict: (optional), if True, this returns the total number of
errors which will cause the hook to fail
:param str ignore: (optional), a comma-separated list of errors and
warnings to ignore
:param bool lazy: (optional), allows for the instances where you don't add
the files to the index before running a commit, e.g., git commit -a
:returns: total number of errors if strict is True, otherwise 0
"""
gitcmd = "git diff-index --cached --name-only HEAD"
if lazy:
# Catch all files, including those not added to the index
gitcmd = gitcmd.replace('--cached ', '')
if hasattr(ignore, 'split'):
ignore = ignore.split(',')
# Returns the exit code, list of files modified, list of error messages
_, files_modified, _ = run(gitcmd)
# Run the checks
flake8_style = get_style_guide(
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
report = flake8_style.check_files([f for f in files_modified if
f.endswith('.py')])
if strict:
return report.total_errors
return 0
def hg_hook(ui, repo, **kwargs):
"""This is the function executed directly by Mercurial as part of the
hook. This is never called directly by the user, so the parameters are
undocumented. If you would like to learn more about them, please feel free
to read the official Mercurial documentation.
"""
complexity = ui.config('flake8', 'complexity', default=-1)
strict = ui.configbool('flake8', 'strict', default=True)
config = ui.config('flake8', 'config', default=True)
if config is True:
config = DEFAULT_CONFIG
paths = _get_files(repo, **kwargs)
flake8_style = get_style_guide(
config_file=config, max_complexity=complexity)
report = flake8_style.check_files(paths)
if strict:
return report.total_errors
return 0
def run(command):
p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
(stdout, stderr) = p.communicate()
return (p.returncode, [line.strip() for line in stdout.splitlines()],
[line.strip() for line in stderr.splitlines()])
def _get_files(repo, **kwargs):
seen = set()
for rev in range(repo[kwargs['node']], len(repo)):
for file_ in repo[rev].files():
file_ = os.path.join(repo.root, file_)
if file_ in seen or not os.path.exists(file_):
continue
seen.add(file_)
if file_.endswith('.py'):