mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-13 16:14:18 +00:00
Transition to pyflakes 0.6.1
That was less painful than I thought it would be.
This commit is contained in:
parent
1d247709a0
commit
d220a65222
4 changed files with 70 additions and 40 deletions
28
README.rst
28
README.rst
|
|
@ -210,17 +210,17 @@ pep8:
|
||||||
|
|
||||||
flakey:
|
flakey:
|
||||||
|
|
||||||
- YW402: <module> imported but unused
|
- W402: <module> imported but unused
|
||||||
- YW403: import <module> from line <n> shadowed by loop variable
|
- W403: import <module> from line <n> shadowed by loop variable
|
||||||
- YW404: 'from <module> import ``*``' used; unable to detect undefined names
|
- W404: 'from <module> import ``*``' used; unable to detect undefined names
|
||||||
- YW405: future import(s) <name> after other statements
|
- W405: future import(s) <name> after other statements
|
||||||
- YW801: redefinition of unused <name> from line <n>
|
- W801: redefinition of unused <name> from line <n>
|
||||||
- YW802: undefined name <name>
|
- W802: undefined name <name>
|
||||||
- YW803: undefined name <name> in __all__
|
- W803: undefined name <name> in __all__
|
||||||
- YW804: local variable <name> (defined in enclosing scope on line <n>) referenced before assignment
|
- W804: local variable <name> (defined in enclosing scope on line <n>) referenced before assignment
|
||||||
- YW805: duplicate argument <name> in function definition
|
- W805: duplicate argument <name> in function definition
|
||||||
- YW806: redefinition of function <name> from line <n>
|
- W806: redefinition of function <name> from line <n>
|
||||||
- YW806: local variable <name> is assigned to but never used
|
- W806: local variable <name> is assigned to but never used
|
||||||
|
|
||||||
McCabe:
|
McCabe:
|
||||||
|
|
||||||
|
|
@ -232,13 +232,11 @@ CHANGES
|
||||||
2.0.0 - 2013-01-xx
|
2.0.0 - 2013-01-xx
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
- Fixes #13: pep8 and flakey are now external dependencies
|
- Fixes #13: pep8 and pyflakes are now external dependencies
|
||||||
- Split run.py into main.py and hooks.py for better logic
|
- Split run.py into main.py and hooks.py for better logic
|
||||||
- Expose our parser for our users
|
- Expose our parser for our users
|
||||||
- New feature: Install git and hg hooks automagically
|
- New feature: Install git and hg hooks automagically
|
||||||
- By relying on flakey, we also fixed #45 and #35
|
- By relying on pyflakes (0.6.1), we also fixed #45 and #35
|
||||||
- Changed the way flakey errors are printed. Both the old and new versions
|
|
||||||
will be ignored when specified at the command-line though.
|
|
||||||
|
|
||||||
1.7.0 - 2012-12-21
|
1.7.0 - 2012-12-21
|
||||||
------------------
|
------------------
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pep8
|
import pep8
|
||||||
import flakey
|
import pyflakes.api
|
||||||
|
import pyflakes.checker
|
||||||
import select
|
import select
|
||||||
from flake8 import mccabe
|
from flake8 import mccabe
|
||||||
from flake8.util import (_initpep8, skip_file, get_parser, read_config,
|
from flake8.util import (_initpep8, skip_file, get_parser, read_config,
|
||||||
merge_opts)
|
merge_opts, Flake8Reporter)
|
||||||
|
|
||||||
pep8style = None
|
pep8style = None
|
||||||
|
|
||||||
|
|
@ -49,8 +50,11 @@ def main():
|
||||||
|
|
||||||
builtins = set(opts.builtins.split(','))
|
builtins = set(opts.builtins.split(','))
|
||||||
if builtins:
|
if builtins:
|
||||||
orig_builtins = set(flakey.checker._MAGIC_GLOBALS)
|
orig_builtins = set(pyflakes.checker._MAGIC_GLOBALS)
|
||||||
flakey.checker._MAGIC_GLOBALS = orig_builtins | builtins
|
pyflakes.checker._MAGIC_GLOBALS = orig_builtins | builtins
|
||||||
|
|
||||||
|
# This is needed so we can ignore some items
|
||||||
|
pyflakes_reporter = Flake8Reporter(opts.ignore)
|
||||||
|
|
||||||
if pep8style.paths and pep8style.options.filename is not None:
|
if pep8style.paths and pep8style.options.filename is not None:
|
||||||
for path in _get_python_files(pep8style.paths):
|
for path in _get_python_files(pep8style.paths):
|
||||||
|
|
@ -59,10 +63,12 @@ def main():
|
||||||
stdin = read_stdin()
|
stdin = read_stdin()
|
||||||
warnings += check_code(stdin, opts.ignore, complexity)
|
warnings += check_code(stdin, opts.ignore, complexity)
|
||||||
else:
|
else:
|
||||||
warnings += check_file(path, opts.ignore, complexity)
|
warnings += check_file(path, opts.ignore, complexity,
|
||||||
|
pyflakes_reporter)
|
||||||
else:
|
else:
|
||||||
stdin = read_stdin()
|
stdin = read_stdin()
|
||||||
warnings += check_code(stdin, opts.ignore, complexity)
|
warnings += check_code(stdin, opts.ignore, complexity,
|
||||||
|
pyflakes_reporter)
|
||||||
|
|
||||||
if opts.exit_zero:
|
if opts.exit_zero:
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
@ -70,27 +76,18 @@ def main():
|
||||||
raise SystemExit(warnings)
|
raise SystemExit(warnings)
|
||||||
|
|
||||||
|
|
||||||
def _set_alt(warning):
|
def check_file(path, ignore=(), complexity=-1, reporter=None):
|
||||||
for m in warning.messages:
|
|
||||||
m.error_code, m.alt_error_code = m.alt_error_code, m.error_code
|
|
||||||
|
|
||||||
|
|
||||||
def check_file(path, ignore=(), complexity=-1):
|
|
||||||
if pep8style.excluded(path):
|
if pep8style.excluded(path):
|
||||||
return 0
|
return 0
|
||||||
warning = flakey.check_path(path)
|
warnings = pyflakes.api.checkPath(path, reporter)
|
||||||
_set_alt(warning)
|
|
||||||
warnings = flakey.print_messages(warning, ignore=ignore)
|
|
||||||
warnings += pep8style.input_file(path)
|
warnings += pep8style.input_file(path)
|
||||||
if complexity > -1:
|
if complexity > -1:
|
||||||
warnings += mccabe.get_module_complexity(path, complexity)
|
warnings += mccabe.get_module_complexity(path, complexity)
|
||||||
return warnings
|
return warnings
|
||||||
|
|
||||||
|
|
||||||
def check_code(code, ignore=(), complexity=-1):
|
def check_code(code, ignore=(), complexity=-1, reporter=None):
|
||||||
warning = flakey.check(code, '<stdin>')
|
warnings = pyflakes.api.check(code, '<stdin>', reporter)
|
||||||
_set_alt(warning)
|
|
||||||
warnings = flakey.print_messages(warning, ignore=ignore, code=code)
|
|
||||||
warnings += pep8style.input_file('-', lines=code.split('\n'))
|
warnings += pep8style.input_file('-', lines=code.split('\n'))
|
||||||
if complexity > -1:
|
if complexity > -1:
|
||||||
warnings += mccabe.get_code_complexity(code, complexity)
|
warnings += mccabe.get_code_complexity(code, complexity)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import optparse
|
import optparse
|
||||||
import pep8
|
import pep8
|
||||||
|
import pyflakes
|
||||||
|
from pyflakes import reporter, messages
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Python 2
|
# Python 2
|
||||||
|
|
@ -19,7 +21,6 @@ pep8style = None
|
||||||
def get_parser():
|
def get_parser():
|
||||||
"""Create a custom OptionParser"""
|
"""Create a custom OptionParser"""
|
||||||
from flake8 import __version__
|
from flake8 import __version__
|
||||||
import flakey
|
|
||||||
parser = pep8.get_parser()
|
parser = pep8.get_parser()
|
||||||
|
|
||||||
def version(option, opt, value, parser):
|
def version(option, opt, value, parser):
|
||||||
|
|
@ -27,11 +28,11 @@ def get_parser():
|
||||||
parser.print_version()
|
parser.print_version()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
parser.version = '{0} (pep8: {1}, flakey: {2})'.format(
|
parser.version = '{0} (pep8: {1}, pyflakes: {2})'.format(
|
||||||
__version__, pep8.__version__, flakey.__version__)
|
__version__, pep8.__version__, pyflakes.__version__)
|
||||||
parser.remove_option('--version')
|
parser.remove_option('--version')
|
||||||
parser.add_option('--builtins', default='', dest='builtins',
|
parser.add_option('--builtins', default='', dest='builtins',
|
||||||
help="append builtin functions to flakey's "
|
help="append builtin functions to pyflakes' "
|
||||||
"_MAGIC_BUILTINS")
|
"_MAGIC_BUILTINS")
|
||||||
parser.add_option('--exit-zero', action='store_true', default=False,
|
parser.add_option('--exit-zero', action='store_true', default=False,
|
||||||
help='Exit with status 0 even if there are errors')
|
help='Exit with status 0 even if there are errors')
|
||||||
|
|
@ -48,7 +49,7 @@ def get_parser():
|
||||||
|
|
||||||
|
|
||||||
def read_config(opts, opt_parser):
|
def read_config(opts, opt_parser):
|
||||||
configs = ('.flake8', '.pep8', 'tox.ini', 'setup.cfg')
|
configs = ('.flake8', '.pep8', 'tox.ini', 'setup.cfg',)
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
files_found = parser.read(configs)
|
files_found = parser.read(configs)
|
||||||
if not (files_found and parser.has_section('flake8')):
|
if not (files_found and parser.has_section('flake8')):
|
||||||
|
|
@ -161,3 +162,37 @@ def _initpep8(config_file=True):
|
||||||
pep8style.options.max_line_length = 79
|
pep8style.options.max_line_length = 79
|
||||||
pep8style.args = []
|
pep8style.args = []
|
||||||
return pep8style
|
return pep8style
|
||||||
|
|
||||||
|
|
||||||
|
error_mapping = {
|
||||||
|
'W402': messages.UnusedImport,
|
||||||
|
'W403': messages.ImportShadowedByLoopVar,
|
||||||
|
'W404': messages.ImportStarUsed,
|
||||||
|
'W405': messages.LateFutureImport,
|
||||||
|
'W801': (messages.RedefinedWhileUnused,
|
||||||
|
messages.RedefinedInListComp,),
|
||||||
|
'W802': messages.UndefinedName,
|
||||||
|
'W803': messages.UndefinedExport,
|
||||||
|
'W804': (messages.UndefinedLocal,
|
||||||
|
messages.UnusedVariable,),
|
||||||
|
'W805': messages.DuplicateArgument,
|
||||||
|
'W806': messages.Redefined,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Flake8Reporter(reporter.Reporter):
|
||||||
|
"""Our own instance of a Reporter so that we can silence some messages."""
|
||||||
|
#class_mapping = dict((k, c) for (c, v) in error_mapping.items() for k in
|
||||||
|
#v)
|
||||||
|
def __init__(self, ignore=None):
|
||||||
|
super(Flake8Reporter, self).__init__(sys.stdout, sys.stderr)
|
||||||
|
self.ignore = ignore or []
|
||||||
|
|
||||||
|
def flake(self, message):
|
||||||
|
classes = [error_mapping[i] for i in self.ignore if i in error_mapping]
|
||||||
|
|
||||||
|
if (any(isinstance(message, c) for c in classes) or
|
||||||
|
skip_warning(message)):
|
||||||
|
return
|
||||||
|
|
||||||
|
super(Flake8Reporter, self).flake(message)
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -42,7 +42,7 @@ setup(
|
||||||
url="http://bitbucket.org/tarek/flake8",
|
url="http://bitbucket.org/tarek/flake8",
|
||||||
packages=["flake8", "flake8.tests"],
|
packages=["flake8", "flake8.tests"],
|
||||||
scripts=scripts,
|
scripts=scripts,
|
||||||
install_requires=["flakey (==2.0)", "pep8 (==1.4.1)"],
|
install_requires=["pyflakes==0.6.1", "pep8"],
|
||||||
long_description=README,
|
long_description=README,
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Environment :: Console",
|
"Environment :: Console",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue