Commit eece16af authored by Jackson Doak's avatar Jackson Doak

Imported Debian patch 2.1.0-1

CHANGES
=======
2.0.0 - 2013-02-xx
2.1.0 - 2013-10-26
------------------
- Add FLAKE8_LAZY and FLAKE8_IGNORE environment variable support to git and
mercurial hooks
- Force git and mercurial hooks to repsect configuration in setup.cfg
- Only check staged files if that is specified
- Fix hook file permissions
- Fix the git hook on python 3
- Ignore non-python files when running the git hook
- Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23
------------------
- Pyflakes errors are prefixed by an ``F`` instead of an ``E``
......
......@@ -19,3 +19,4 @@ Contributors (by order of appearance) :
- Marc Labbé
- Bruno Miguel Custódio
- Florent Xicluna
- Austin Morton
\ No newline at end of file
== Flake8 License (MIT) ==
Copyright (C) 2011 Tarek Ziade <tarek@ziade.org>
Copyright (C) 2011-2013 Tarek Ziade <tarek@ziade.org>
Copyright (C) 2012-2013 Ian Cordasco <graffatcolmingov@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
......
include *.rst
include CONTRIBUTORS.txt
include LICENSE
recursive-include scripts flake8.*
recursive-include flake8 *
Metadata-Version: 1.0
Metadata-Version: 1.1
Name: flake8
Version: 2.0
Version: 2.1.0
Summary: the modular source code checker: pep8, pyflakes and co
Home-page: http://bitbucket.org/tarek/flake8
Author: Ian Cordasco
......@@ -65,6 +65,13 @@ Description: ======
anything that goes beyond 10 is too complex.
See https://en.wikipedia.org/wiki/Cyclomatic_complexity.
Questions or Feedback
=====================
If you have questions you'd like to ask the developers, or feedback you'd like
to provide, feel free to use the mailing list: code-quality@python.org We
would love to hear from you. Additionally, if you have a feature you'd like to
suggest, the mailing list would be the best place for it.
.. _links:
......@@ -79,7 +86,20 @@ Description: ======
CHANGES
=======
2.0.0 - 2013-02-xx
2.1.0 - 2013-10-26
------------------
- Add FLAKE8_LAZY and FLAKE8_IGNORE environment variable support to git and
mercurial hooks
- Force git and mercurial hooks to repsect configuration in setup.cfg
- Only check staged files if that is specified
- Fix hook file permissions
- Fix the git hook on python 3
- Ignore non-python files when running the git hook
- Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23
------------------
- Pyflakes errors are prefixed by an ``F`` instead of an ``E``
......
......@@ -57,6 +57,13 @@ This feature is quite useful to detect over-complex code. According to McCabe,
anything that goes beyond 10 is too complex.
See https://en.wikipedia.org/wiki/Cyclomatic_complexity.
Questions or Feedback
=====================
If you have questions you'd like to ask the developers, or feedback you'd like
to provide, feel free to use the mailing list: code-quality@python.org We
would love to hear from you. Additionally, if you have a feature you'd like to
suggest, the mailing list would be the best place for it.
.. _links:
......
python-flake8 (2.1.0-1) unstable; urgency=low
* Team upload.
* New upstream release
* Add manpage. Closes: #722704
* debian/control:
- Update versioned depends
* Make basic autopkgtest
-- Jackson Doak <noskcaj@ubuntu.com> Tue, 05 Nov 2013 16:52:26 +1100
python-flake8 (2.0-2) unstable; urgency=low
* Team upload.
......
......@@ -9,22 +9,23 @@ Build-Depends: debhelper (>= 9),
python-setuptools,
python3-all,
python3-setuptools,
pyflakes,
pep8,
python3-pep8,
python3-mccabe
pyflakes (>= 0.7.3),
pep8 (>= 1.4.6),
python3-pep8 (>= 1.4.6),
python3-mccabe (>= 0.2.1)
Standards-Version: 3.9.4
Homepage: http://bitbucket.org/tarek/flake8
Vcs-Svn: svn://anonscm.debian.org/python-modules/packages/python-flake8/trunk/
Vcs-Browser: http://anonscm.debian.org/viewvc/python-modules/packages/python-flake8/trunk/
X-Python-Version: >= 2.6
X-Python3-Version: >=3.1
XS-Testsuite: autopkgtest
Package: python-flake8
Architecture: any
Depends: pep8 (>= 1.4.3),
pyflakes (>= 0.6.1),
python-mccabe (>= 0.2),
Depends: pep8 (>= 1.4.6),
pyflakes (>= 0.7.3),
python-mccabe (>= 0.2.1),
${misc:Depends},
${python:Depends}
Description: code checker using pep8 and pyflakes
......@@ -37,10 +38,10 @@ Description: code checker using pep8 and pyflakes
Package: python3-flake8
Architecture: any
Depends: pep8 (>= 1.4.3),
pyflakes (>= 0.6.1),
Depends: pep8 (>= 1.4.6),
pyflakes (>= 0.7.3),
python-flake8,
python3-mccabe (>= 0.2),
python3-mccabe (>= 0.2.1),
${misc:Depends},
${python3:Depends}
Description: code checker using pep8 and pyflakes (Python 3)
......
.TH FLAKE8 "1" "November 2013" "flake8 2.0 (pep8: 1.4.6, mccabe: 0.2, pyflakes: 0.7.3)" "User Commands"
.SH NAME
flake8 \- code checker using pep8 and pyflakes
.SH SYNOPSIS
.B flake8
[\fIoptions\fR] \fIinput \fR...
.SH OPTIONS
.TP
\fB\-\-version\fR
show program's version number and exit
.TP
\fB\-h\fR, \fB\-\-help\fR
show this help message and exit
.TP
\fB\-v\fR, \fB\-\-verbose\fR
print status messages, or debug with \fB\-vv\fR
.TP
\fB\-q\fR, \fB\-\-quiet\fR
report only file names, or nothing with \fB\-qq\fR
.TP
\fB\-\-first\fR
show first occurrence of each error
.TP
\fB\-\-exclude\fR=\fIpatterns\fR
exclude files or directories which match these comma
separated patterns (default:
\&.svn,CVS,.bzr,.hg,.git,__pycache__)
.TP
\fB\-\-filename\fR=\fIpatterns\fR
when parsing directories, only check filenames
matching these comma separated patterns (default:
*.py)
.TP
\fB\-\-select\fR=\fIerrors\fR
select errors and warnings (e.g. E,W6)
.TP
\fB\-\-ignore\fR=\fIerrors\fR
skip errors and warnings (e.g. E4,W)
.TP
\fB\-\-show\-source\fR
show source code for each error
.TP
\fB\-\-show\-pep8\fR
show text of PEP 8 for each error (implies \fB\-\-first\fR)
.TP
\fB\-\-statistics\fR
count errors and warnings
.TP
\fB\-\-count\fR
print total number of errors and warnings to standard
error and set exit code to 1 if total is not null
.TP
\fB\-\-max\-line\-length\fR=\fIn\fR
set maximum allowed line length (default: 79)
.TP
\fB\-\-hang\-closing\fR
hang closing bracket instead of matching indentation
of opening bracket's line
.TP
\fB\-\-format\fR=\fIformat\fR
set the error format [default|pylint|<custom>]
.TP
\fB\-\-diff\fR
report only lines changed according to the unified
diff received on STDIN
.TP
\fB\-\-exit\-zero\fR
exit with code 0 even if there are errors
.TP
\fB\-\-max\-complexity\fR=\fIMAX_COMPLEXITY\fR
McCabe complexity threshold
.TP
\fB\-\-builtins\fR=\fIBUILTINS\fR
define more built\-ins, comma separated
.TP
\fB\-\-install\-hook\fR
Install the appropriate hook for this repository.
.IP
Testing Options:
.TP
\fB\-\-benchmark\fR
measure processing speed
.IP
Configuration:
.IP
The project options are read from the [flake8] section of the tox.ini
file or the setup.cfg file located in any parent folder of the path(s)
being processed. Allowed options are: exclude, filename, select,
ignore, max\-line\-length, hang\-closing, count, format, quiet, showpep8, show\-source, statistics, verbose, max\-complexity, builtins.
.TP
\fB\-\-config\fR=\fIpath\fR
user config file location (default:
~/.config/flake8)
debian/flake8.1
\ No newline at end of file
Tests: tools
Depends: @
\ No newline at end of file
#!/bin/sh
set -efu
cd $ADTTMP
flake8
\ No newline at end of file
Metadata-Version: 1.0
Metadata-Version: 1.1
Name: flake8
Version: 2.0
Version: 2.1.0
Summary: the modular source code checker: pep8, pyflakes and co
Home-page: http://bitbucket.org/tarek/flake8
Author: Ian Cordasco
......@@ -65,6 +65,13 @@ Description: ======
anything that goes beyond 10 is too complex.
See https://en.wikipedia.org/wiki/Cyclomatic_complexity.
Questions or Feedback
=====================
If you have questions you'd like to ask the developers, or feedback you'd like
to provide, feel free to use the mailing list: code-quality@python.org We
would love to hear from you. Additionally, if you have a feature you'd like to
suggest, the mailing list would be the best place for it.
.. _links:
......@@ -79,7 +86,20 @@ Description: ======
CHANGES
=======
2.0.0 - 2013-02-xx
2.1.0 - 2013-10-26
------------------
- Add FLAKE8_LAZY and FLAKE8_IGNORE environment variable support to git and
mercurial hooks
- Force git and mercurial hooks to repsect configuration in setup.cfg
- Only check staged files if that is specified
- Fix hook file permissions
- Fix the git hook on python 3
- Ignore non-python files when running the git hook
- Ignore .tox directories by default
- Flake8 now reports the column number for PyFlakes messages
2.0.0 - 2013-02-23
------------------
- Pyflakes errors are prefixed by an ``F`` instead of an ``E``
......
......@@ -5,18 +5,31 @@ MANIFEST.in
README.rst
setup.py
flake8/__init__.py
flake8/__init__.pyc
flake8/_pyflakes.py
flake8/_pyflakes.pyc
flake8/engine.py
flake8/engine.pyc
flake8/hooks.py
flake8/hooks.py.orig
flake8/hooks.pyc
flake8/main.py
flake8/main.pyc
flake8/run.py
flake8/util.py
flake8/util.pyc
flake8.egg-info/PKG-INFO
flake8.egg-info/SOURCES.txt
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/test_flakes.py
scripts/flake8.cmd
\ No newline at end of file
flake8/tests/__init__.pyc
flake8/tests/test_engine.py
flake8/tests/test_engine.pyc
\ No newline at end of file
setuptools
pyflakes >= 0.6.1
pep8 >= 1.4.3
mccabe >= 0.2
\ No newline at end of file
pyflakes >= 0.7.3
pep8 >= 1.4.6
mccabe >= 0.2.1
\ No newline at end of file
__version__ = '2.0'
__version__ = '2.1.0'
......@@ -44,4 +44,5 @@ class FlakesChecker(pyflakes.checker.Checker):
def run(self):
for m in self.messages:
yield m.lineno, 0, (m.flake8_msg % m.message_args), m.__class__
col = getattr(m, 'col', 0)
yield m.lineno, col, (m.flake8_msg % m.message_args), m.__class__
# -*- coding: utf-8 -*-
import re
import platform
import pep8
......@@ -37,7 +38,10 @@ def get_parser():
"""
(extensions, parser_hooks, options_hooks) = _register_extensions()
details = ', '.join(['%s: %s' % ext for ext in extensions])
parser = pep8.get_parser('flake8', '%s (%s)' % (__version__, details))
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)
......@@ -78,3 +82,12 @@ def get_style_guide(**kwargs):
for options_hook in options_hooks:
options_hook(options)
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())
......@@ -2,7 +2,16 @@
from __future__ import with_statement
import os
import sys
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
......@@ -14,7 +23,7 @@ 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
......@@ -25,15 +34,59 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
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"
gitcmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB 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)
# We only want to pass ignore and max_complexity if they differ from the
# defaults so that we don't override a local configuration file
options = {}
if ignore:
options['ignore'] = ignore
if complexity > -1:
options['max_complexity'] = complexity
files_modified = [f for f in files_modified if f.endswith('.py')]
flake8_style = get_style_guide(
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
report = flake8_style.check_files(files_modified)
parse_argv=True,
config_file=DEFAULT_CONFIG,
**options
)
# Copy staged versions to temporary directory
tmpdir = mkdtemp()
files_to_check = []
try:
for file_ in files_modified:
# get the staged version of the file
gitcmd_getstaged = "git show :%s" % file_
_, out, _ = run(gitcmd_getstaged, raw_output=True, decode=False)
# write the staged version to temp dir with its full path to
# avoid overwriting files with the same name
dirname, filename = os.path.split(os.path.abspath(file_))
prefix = os.path.commonprefix([dirname, tmpdir])
dirname = os.path.relpath(dirname, start=prefix)
dirname = os.path.join(tmpdir, dirname)
if not os.path.isdir(dirname):
os.makedirs(dirname)
filename = os.path.join(dirname, filename)
# write staged version of file to temporary directory
with open(filename, "wb") as fh:
fh.write(out)
files_to_check.append(filename)
# Run the checks
report = flake8_style.check_files(files_to_check)
# remove temporary directory
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
if strict:
return report.total_errors
......@@ -49,14 +102,23 @@ 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
paths = _get_files(repo, **kwargs)
flake8_style = get_style_guide(
config_file=config, max_complexity=complexity)
# We only want to pass ignore and max_complexity if they differ from the
# defaults so that we don't override a local configuration file
options = {}
if ignore:
options['ignore'] = ignore
if complexity > -1:
options['max_complexity'] = complexity
flake8_style = get_style_guide(parse_argv=True, config_file=config,
**options)
report = flake8_style.check_files(paths)
if strict:
......@@ -65,11 +127,23 @@ def hg_hook(ui, repo, **kwargs):
return 0
def run(command):
def run(command, raw_output=False, decode=True):
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()])
# On python 3, subprocess.Popen returns bytes objects which expect
# endswith to be given a bytes object or a tuple of bytes but not native
# string objects. This is simply less mysterious than using b'.py' in the
# endswith method. That should work but might still fail horribly.
if hasattr(stdout, 'decode'):
if decode:
stdout = stdout.decode()
if hasattr(stderr, 'decode'):
if decode:
stderr = stderr.decode()
if not raw_output:
stdout = [line.strip() for line in stdout.splitlines()]
stderr = [line.strip() for line in stderr.splitlines()]
return (p.returncode, stdout, stderr)
def _get_files(repo, **kwargs):
......@@ -85,12 +159,14 @@ def _get_files(repo, **kwargs):
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'
_, git_dir, _ = run('git rev-parse --git-dir')
if git_dir and os.path.isdir(git_dir[0]):
if not os.path.isdir(os.path.join(git_dir[0], 'hooks')):
os.mkdir(os.path.join(git_dir[0], 'hooks'))
return os.path.join(git_dir[0], 'hooks', 'pre-commit')
_, hg_dir, _ = run('hg root')
if hg_dir and os.path.isdir(hg_dir[0]):
return os.path.join(hg_dir[0], '.hg', 'hgrc')
return ''
......@@ -101,14 +177,25 @@ from flake8.hooks import git_hook
COMPLEXITY = os.getenv('FLAKE8_COMPLEXITY', 10)
STRICT = os.getenv('FLAKE8_STRICT', False)
IGNORE = os.getenv('FLAKE8_IGNORE')
LAZY = os.getenv('FLAKE8_LAZY', False)
if __name__ == '__main__':
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT))
sys.exit(git_hook(
complexity=COMPLEXITY,
strict=STRICT,
ignore=IGNORE,
lazy=LAZY,
))
"""
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'):
......@@ -129,6 +216,12 @@ def _install_hg_hook(path):
if not c.has_option('flake8', 'strict'):
c.set('flake8', 'strict', os.getenv('FLAKE8_STRICT', False))
if not c.has_option('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+'))
......@@ -136,7 +229,7 @@ def install_hook():
vcs = find_vcs()
if not vcs:
p = get_parser()
p = get_parser()[0]
sys.stderr.write('Error: could not find either a git or mercurial '
'directory. Please re-run this in a proper '
'repository.')
......@@ -147,7 +240,8 @@ def install_hook():
if 'git' in vcs:
with open(vcs, 'w+') as fd:
fd.write(git_hook_file)
os.chmod(vcs, 744)
# rwxr--r--
os.chmod(vcs, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)
elif 'hg' in vcs:
_install_hg_hook(vcs)
else:
......
# -*- 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'):