1. Tarek Ziadé
  2. flake8

Commits

Peter Teichman  committed ec655cc

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'

  • Participants
  • Parent commits 7eb8a10
  • Branches default

Comments (0)

Files changed (3)

File README

View file
  • Ignore whitespace
     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
 =================
 

File flake8/run.py

View file
  • Ignore whitespace
 
 
 def _get_python_files(paths):
+    seen = set()
     for path in paths:
         if os.path.isdir(path):
             for dirpath, dirnames, filenames in os.walk(path):
                     if not filename.endswith('.py'):
                         continue
                     fullpath = os.path.join(dirpath, filename)
-                    if not skip_file(fullpath):
+                    if not skip_file(fullpath) and fullpath not in seen:
                         yield fullpath
 
         else:
-            if not skip_file(path):
+            if not skip_file(path) and path not in seen:
                 yield path
 
 
         def distribution_files(self):
             if self.distribution.packages:
                 for package in self.distribution.packages:
-                    yield package
+                    yield package.replace(".", os.path.sep)
 
             if self.distribution.py_modules:
                 for filename in self.distribution.py_modules:
         def run(self):
             _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()):
-                warnings += check_file(path)
+                if path not in checked:
+                    warnings += check_file(path)
+                checked.add(path)
 
             raise SystemExit(warnings > 0)
 

File setup.py

View file
  • Ignore whitespace
 import sys
 
 ispy3 = sys.version_info[0] == 3
+issetuptools = False
 
 if ispy3:
     from distutils.core import setup    # NOQA
 else:
     try:
         from setuptools import setup    # NOQA
+        issetuptools = True
     except ImportError:
         from distutils.core import setup   # NOQA
 
 
 README = open('README').read()
 
+entry_points = {}
+if issetuptools:
+    entry_points["distutils.commands"] = ["flake8 = flake8.run:Flake8Command"]
+
 setup(
     name="flake8",
     license="MIT",
     url="http://bitbucket.org/tarek/flake8",
     packages=["flake8", "flake8.tests"],
     scripts=["flake8/flake8"],
-    entry_points = {
-        "distutils.commands": [
-            "flake8 = flake8.run:Flake8Command",
-        ],
-    },
+    entry_points=entry_points,
     long_description=README,
     classifiers=[
         "Environment :: Console",