Merged changes from origin

This commit is contained in:
mrlabbe 2012-10-03 07:38:20 -04:00
commit 164a32126c
4 changed files with 76 additions and 4 deletions

View file

@ -13,3 +13,4 @@ Contributors (by order of appearance) :
- Jannis Leidel
- Miki Tebeka
- David Cramer
- Peter Teichman

25
README
View file

@ -123,6 +123,31 @@ In order to use Flake8 inside a buildout, edit your buildout.cfg and add this::
entry-points =
flake8=flake8.run:main
setuptools integration
======================
If setuptools is available, Flake8 provides a command that checks the
Python files declared by your project. To use it, add flake8 to your
setup_requires::
setup(
name="project",
packages=["project"],
setup_requires=[
"flake8"
]
)
Running ``python setup.py flake8`` on the command line will check the
files listed in your ``py_modules`` and ``packages``. If any warnings
are found, the command will exit with an error code::
$ python setup.py flake8
Original projects
=================

View file

@ -114,6 +114,7 @@ class _PEP8Options(object):
benchmark = False
testsuite = ''
doctest = False
max_line_length = pep8.MAX_LINE_LENGTH
def _initpep8():
@ -171,5 +172,50 @@ def hg_hook(ui, repo, **kwargs):
return 0
try:
from setuptools import Command
except ImportError:
Flake8Command = None
else:
class Flake8Command(Command):
description = "Run flake8 on modules registered in setuptools"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def distribution_files(self):
if self.distribution.packages:
for package in self.distribution.packages:
yield package.replace(".", os.path.sep)
if self.distribution.py_modules:
for filename in self.distribution.py_modules:
yield "%s.py" % filename
def run(self):
global pep8style
pep8style = pep8.StyleGuide(config_file=True)
_initpep8()
# _get_python_files can produce the same file several
# times, if one of its paths is a parent of another. Keep
# a set of checked files to de-duplicate.
checked = set()
warnings = 0
for path in _get_python_files(self.distribution_files()):
if path not in checked:
warnings += check_file(path)
checked.add(path)
raise SystemExit(warnings > 0)
if __name__ == '__main__':
main()

View file

@ -1,4 +1,4 @@
import sys
import sys
import os
ispy3 = sys.version_info[0] == 3
@ -14,11 +14,11 @@ else:
try:
from setuptools import setup # NOQA
kwargs = {
'entry_points':
{'distutils.commands': ['flake8 = flake8.run:Flake8Command'],
'console_scripts': ['flake8 = flake8.run:main']},
'tests_require': ['nose'],
'test_suite': 'nose.collector',
'entry_points': {
'console_scripts': ['flake8 = flake8.run:main']
},
}
except ImportError:
from distutils.core import setup # NOQA