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

Imported Upstream version 2.2.2

parent 48f682f3
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
------------------
......@@ -14,6 +40,7 @@ CHANGES
- Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23
------------------
......@@ -78,7 +105,7 @@ CHANGES
- make sure mccabe catches the syntax errors as warnings
- pep8 upgrade
- 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
......
Metadata-Version: 1.1
Name: flake8
Version: 2.1.0
Version: 2.2.2
Summary: the modular source code checker: pep8, pyflakes and co
Home-page: http://bitbucket.org/tarek/flake8
Author: Ian Cordasco
......@@ -86,6 +86,32 @@ Description: ======
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
------------------
......@@ -99,6 +125,7 @@ Description: ======
- Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23
------------------
......@@ -163,7 +190,7 @@ Description: ======
- make sure mccabe catches the syntax errors as warnings
- pep8 upgrade
- 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
......
Metadata-Version: 1.1
Name: flake8
Version: 2.1.0
Version: 2.2.2
Summary: the modular source code checker: pep8, pyflakes and co
Home-page: http://bitbucket.org/tarek/flake8
Author: Ian Cordasco
......@@ -86,6 +86,32 @@ Description: ======
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
------------------
......@@ -99,6 +125,7 @@ Description: ======
- Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23
------------------
......@@ -163,7 +190,7 @@ Description: ======
- make sure mccabe catches the syntax errors as warnings
- pep8 upgrade
- 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
......
......@@ -3,18 +3,21 @@ CONTRIBUTORS.txt
LICENSE
MANIFEST.in
README.rst
setup.cfg
setup.py
flake8/__init__.py
flake8/__init__.pyc
flake8/__main__.py
flake8/_pyflakes.py
flake8/_pyflakes.pyc
flake8/engine.py
flake8/engine.py.orig
flake8/engine.pyc
flake8/hooks.py
flake8/hooks.py.orig
flake8/hooks.pyc
flake8/main.py
flake8/main.pyc
flake8/reporter.py
flake8/reporter.pyc
flake8/run.py
flake8/util.py
flake8/util.pyc
......@@ -24,11 +27,6 @@ flake8.egg-info/dependency_links.txt
flake8.egg-info/entry_points.txt
flake8.egg-info/requires.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__.pyc
flake8/tests/test_engine.py
......
pyflakes >= 0.7.3
pep8 >= 1.4.6
pyflakes >= 0.8.1
pep8 >= 1.5.7
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 -*-
try:
# The 'demandimport' breaks pyflakes and flake8._pyflakes
from mercurial import demandimport
except ImportError:
pass
else:
demandimport.disable()
import pyflakes
import pyflakes.checker
......@@ -31,16 +38,23 @@ class FlakesChecker(pyflakes.checker.Checker):
name = 'pyflakes'
version = pyflakes.__version__
def __init__(self, tree, filename):
super(FlakesChecker, self).__init__(tree, filename,
withDoctest=self.withDoctest)
@classmethod
def add_options(cls, parser):
parser.add_option('--builtins',
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
def parse_options(cls, options):
if options.builtins:
cls.builtIns = cls.builtIns.union(options.builtins.split(','))
cls.withDoctest = options.doctests
def run(self):
for m in self.messages:
......
No preview for this file type
......@@ -5,6 +5,7 @@ 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
......@@ -47,6 +48,17 @@ def get_parser():
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:
......@@ -58,8 +70,6 @@ def get_parser():
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):
"""Run all checks on a Python source file."""
......@@ -81,6 +91,22 @@ def get_style_guide(**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
......
# -*- 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
from subprocess import Popen, PIPE
import shutil
from tempfile import mkdtemp
try:
# The 'demandimport' breaks pyflakes and flake8._pyflakes
from mercurial import demandimport
demandimport.disable()
except ImportError:
pass
try:
from configparser import ConfigParser
except ImportError: # Python 2
......@@ -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')]
flake8_style = get_style_guide(
parse_argv=True,
config_file=DEFAULT_CONFIG,
**options
)
flake8_style = get_style_guide(config_file=DEFAULT_CONFIG, paths=['.'],
**options)
# Copy staged versions to temporary directory
tmpdir = mkdtemp()
......@@ -103,9 +94,7 @@ def hg_hook(ui, repo, **kwargs):
complexity = ui.config('flake8', 'complexity', default=-1)
strict = ui.configbool('flake8', 'strict', default=True)
ignore = ui.config('flake8', 'ignore', default=None)
config = ui.config('flake8', 'config', default=True)
if config is True:
config = DEFAULT_CONFIG
config = ui.config('flake8', 'config', default=DEFAULT_CONFIG)
paths = _get_files(repo, **kwargs)
......@@ -117,7 +106,7 @@ def hg_hook(ui, repo, **kwargs):
if complexity > -1:
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)
report = flake8_style.check_files(paths)
......@@ -136,10 +125,10 @@ def run(command, raw_output=False, decode=True):
# endswith method. That should work but might still fail horribly.
if hasattr(stdout, 'decode'):
if decode:
stdout = stdout.decode()
stdout = stdout.decode('utf-8')
if hasattr(stderr, 'decode'):
if decode:
stderr = stderr.decode()
stderr = stderr.decode('utf-8')
if not raw_output:
stdout = [line.strip() for line in stdout.splitlines()]
stderr = [line.strip() for line in stderr.splitlines()]
......@@ -194,7 +183,7 @@ if __name__ == '__main__':
def _install_hg_hook(path):
if not os.path.isfile(path):
# Make the file so we can avoid IOError's
open(path, 'w+').close()
open(path, 'w').close()
c = ConfigParser()
c.readfp(open(path, 'r'))
......@@ -217,12 +206,13 @@ def _install_hg_hook(path):
c.set('flake8', 'strict', os.getenv('FLAKE8_STRICT', False))
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'):
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():
......@@ -238,7 +228,9 @@ def install_hook():
status = 0
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)
# rwxr--r--
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'):
yield file_
def find_vcs():
if os.path.isdir('.git'):
if not os.path.isdir('.git/hooks'):
os.mkdir('.git/hooks')
return '.git/hooks/pre-commit'
elif os.path.isdir('.hg'):
return '.hg/hgrc'
return ''
git_hook_file = """#!/usr/bin/env python
import sys
import os
from flake8.hooks import git_hook
COMPLEXITY = os.getenv('FLAKE8_COMPLEXITY', 10)
STRICT = os.getenv('FLAKE8_STRICT', False)
if __name__ == '__main__':
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT))
"""
def _install_hg_hook(path):
if not os.path.isfile(path):
# Make the file so we can avoid IOError's
open(path, 'w+').close()
c = ConfigParser()
c.readfp(open(path, 'r'))
if not c.has_section('hooks'):
c.add_section('hooks')
if not c.has_option('hooks', 'commit'):
c.set('hooks', 'commit', 'python:flake8.hooks.hg_hook')
if not c.has_option('hooks', 'qrefresh'):
c.set('hooks', 'qrefresh', 'python:flake8.hooks.hg_hook')
if not c.has_section('flake8'):
c.add_section('flake8')
if not c.has_option('flake8', 'complexity'):
c.set('flake8', 'complexity', str(os.getenv('FLAKE8_COMPLEXITY', 10)))
if not c.has_option('flake8', 'strict'):
c.set('flake8', 'strict', os.getenv('FLAKE8_STRICT', False))
c.write(open(path, 'w+'))
def install_hook():
vcs = find_vcs()
if not vcs:
p = get_parser()
sys.stderr.write('Error: could not find either a git or mercurial '
'directory. Please re-run this in a proper '
'repository.')
p.print_help()
sys.exit(1)
status = 0
if 'git' in vcs:
with open(vcs, 'w+') as fd:
fd.write(git_hook_file)
# 0b111100100 == rwxr--r--
# Python 2.5 doesn't support 0b syntax so note that the above binary
# value is equivalent to 484 in decimal
os.chmod(vcs, 484)
elif 'hg' in vcs:
_install_hg_hook(vcs)
else:
status = 1
sys.exit(status)
......@@ -120,11 +120,17 @@ class Flake8Command(setuptools.Command):
if self.distribution.py_modules:
for filename in self.distribution.py_modules:
yield "%s.py" % filename
# Don't miss the setup.py file itself
yield "setup.py"
def run(self):
# Prepare
paths = list(self.distribution_files())
flake8_style = get_style_guide(config_file=DEFAULT_CONFIG,
paths=paths,
**self.options_dict)
paths = self.distribution_files()
report = flake8_style.check_files(paths)
# Run the checkers
report = flake8_style.check_files()
exit_code = print_report(report, flake8_style)
raise SystemExit(exit_code > 0)
No preview for this file type
# -*- coding: utf-8 -*-
# Adapted from a contribution of Johan Dahlin
import collections
import sys
try:
import multiprocessing
except ImportError: # Python 2.5
multiprocessing = None
import pep8
__all__ = ['multiprocessing', 'BaseQReport', 'QueueReport']
class BaseQReport(pep8.BaseReport):
"""Base Queue Report."""
_loaded = False # Windows support
def __init__(self, options):
assert options.jobs > 0
super(BaseQReport, self).__init__(options)
self.counters = collections.defaultdict(int)
self.n_jobs = options.jobs
# init queues
self.task_queue = multiprocessing.Queue()
self.result_queue = multiprocessing.Queue()
if sys.platform == 'win32':
# Work around http://bugs.python.org/issue10845
sys.modules['__main__'].__file__ = __file__
def start(self):
super(BaseQReport, self).start()
self.__class__._loaded = True
# spawn processes