mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 00:14:46 +00:00
Incorporate patch review on Flake8Command
* add a note about the setuptools command to README * don't install the Flake8Command entry point without setuptools * fix a bug in Flake8Command that might cause double checking of files in 'packages'
This commit is contained in:
parent
2e04e30d51
commit
c6ac38cd70
3 changed files with 44 additions and 9 deletions
25
README
25
README
|
|
@ -123,6 +123,31 @@ In order to use Flake8 inside a buildout, edit your buildout.cfg and add this::
|
||||||
entry-points =
|
entry-points =
|
||||||
flake8=flake8.run:main
|
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
|
Original projects
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ def check_code(code, complexity=-1):
|
||||||
|
|
||||||
|
|
||||||
def _get_python_files(paths):
|
def _get_python_files(paths):
|
||||||
|
seen = set()
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
for dirpath, dirnames, filenames in os.walk(path):
|
for dirpath, dirnames, filenames in os.walk(path):
|
||||||
|
|
@ -42,11 +43,11 @@ def _get_python_files(paths):
|
||||||
if not filename.endswith('.py'):
|
if not filename.endswith('.py'):
|
||||||
continue
|
continue
|
||||||
fullpath = os.path.join(dirpath, filename)
|
fullpath = os.path.join(dirpath, filename)
|
||||||
if not skip_file(fullpath):
|
if not skip_file(fullpath) and fullpath not in seen:
|
||||||
yield fullpath
|
yield fullpath
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not skip_file(path):
|
if not skip_file(path) and path not in seen:
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -183,7 +184,7 @@ else:
|
||||||
def distribution_files(self):
|
def distribution_files(self):
|
||||||
if self.distribution.packages:
|
if self.distribution.packages:
|
||||||
for package in self.distribution.packages:
|
for package in self.distribution.packages:
|
||||||
yield package
|
yield package.replace(".", os.path.sep)
|
||||||
|
|
||||||
if self.distribution.py_modules:
|
if self.distribution.py_modules:
|
||||||
for filename in self.distribution.py_modules:
|
for filename in self.distribution.py_modules:
|
||||||
|
|
@ -192,9 +193,16 @@ else:
|
||||||
def run(self):
|
def run(self):
|
||||||
_initpep8()
|
_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
|
warnings = 0
|
||||||
for path in _get_python_files(self.distribution_files()):
|
for path in _get_python_files(self.distribution_files()):
|
||||||
warnings += check_file(path)
|
if path not in checked:
|
||||||
|
warnings += check_file(path)
|
||||||
|
checked.add(path)
|
||||||
|
|
||||||
raise SystemExit(warnings > 0)
|
raise SystemExit(warnings > 0)
|
||||||
|
|
||||||
|
|
|
||||||
12
setup.py
12
setup.py
|
|
@ -1,12 +1,14 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
ispy3 = sys.version_info[0] == 3
|
ispy3 = sys.version_info[0] == 3
|
||||||
|
issetuptools = False
|
||||||
|
|
||||||
if ispy3:
|
if ispy3:
|
||||||
from distutils.core import setup # NOQA
|
from distutils.core import setup # NOQA
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from setuptools import setup # NOQA
|
from setuptools import setup # NOQA
|
||||||
|
issetuptools = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from distutils.core import setup # NOQA
|
from distutils.core import setup # NOQA
|
||||||
|
|
||||||
|
|
@ -14,6 +16,10 @@ from flake8 import __version__
|
||||||
|
|
||||||
README = open('README').read()
|
README = open('README').read()
|
||||||
|
|
||||||
|
entry_points = {}
|
||||||
|
if issetuptools:
|
||||||
|
entry_points["distutils.commands"] = ["flake8 = flake8.run:Flake8Command"]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="flake8",
|
name="flake8",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
|
|
@ -24,11 +30,7 @@ setup(
|
||||||
url="http://bitbucket.org/tarek/flake8",
|
url="http://bitbucket.org/tarek/flake8",
|
||||||
packages=["flake8", "flake8.tests"],
|
packages=["flake8", "flake8.tests"],
|
||||||
scripts=["flake8/flake8"],
|
scripts=["flake8/flake8"],
|
||||||
entry_points = {
|
entry_points=entry_points,
|
||||||
"distutils.commands": [
|
|
||||||
"flake8 = flake8.run:Flake8Command",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
long_description=README,
|
long_description=README,
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Environment :: Console",
|
"Environment :: Console",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue