Commits

Ian Cordasco committed 69cbcce

Tentative independence from vendored pep8

I'm fairly certain we no longer need the copy we had of pep8.

Comments (0)

Files changed (5)

flake8/__init__.py

-#
 
 __version__ = '1.7.0'

flake8/messages.py

-# (c) 2005 Divmod, Inc.  See LICENSE file for details
-
-
-class Message(object):
-    message = ''
-    message_args = ()
-
-    def __init__(self, filename, lineno):
-        self.filename = filename
-        self.lineno = lineno
-
-    def __str__(self):
-        return '%s:%s: %s' % (self.filename, self.lineno,
-                              self.message % self.message_args)
-
-    def __lt__(self, other):
-        if self.filename != other.filename:
-            return self.filename < other.filename
-        return self.lineno < other.lineno
-
-
-class UnusedImport(Message):
-    message = 'W402 %r imported but unused'
-
-    def __init__(self, filename, lineno, name):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name,)
-
-
-class RedefinedWhileUnused(Message):
-    message = 'W801 redefinition of unused %r from line %r'
-
-    def __init__(self, filename, lineno, name, orig_lineno):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name, orig_lineno)
-
-
-class ImportShadowedByLoopVar(Message):
-    message = 'W403 import %r from line %r shadowed by loop variable'
-
-    def __init__(self, filename, lineno, name, orig_lineno):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name, orig_lineno)
-
-
-class ImportStarUsed(Message):
-    message = "W404 'from %s import *' used; unable to detect undefined names"
-
-    def __init__(self, filename, lineno, modname):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (modname,)
-
-
-class UndefinedName(Message):
-    message = 'W802 undefined name %r'
-
-    def __init__(self, filename, lineno, name):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name,)
-
-
-class UndefinedExport(Message):
-    message = 'W803 undefined name %r in __all__'
-
-    def __init__(self, filename, lineno, name):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name,)
-
-
-class UndefinedLocal(Message):
-    message = "W804 local variable %r (defined in enclosing scope on line " \
-            "%r) referenced before assignment"
-
-    def __init__(self, filename, lineno, name, orig_lineno):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name, orig_lineno)
-
-
-class DuplicateArgument(Message):
-    message = 'W805 duplicate argument %r in function definition'
-
-    def __init__(self, filename, lineno, name):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name,)
-
-
-class RedefinedFunction(Message):
-    message = 'W806 redefinition of function %r from line %r'
-
-    def __init__(self, filename, lineno, name, orig_lineno):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (name, orig_lineno)
-
-
-class LateFutureImport(Message):
-    message = 'W405 future import(s) %r after other statements'
-
-    def __init__(self, filename, lineno, names):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (names,)
-
-
-class UnusedVariable(Message):
-    """
-    Indicates that a variable has been explicity assigned to but not actually
-    used.
-    """
-
-    message = 'W806 local variable %r is assigned to but never used'
-
-    def __init__(self, filename, lineno, names):
-        Message.__init__(self, filename, lineno)
-        self.message_args = (names,)
 from subprocess import PIPE, Popen
 import select
 
-from flake8 import pep8
 from flake8 import mccabe
 from flake8.util import skip_file
 from flake8 import __version__
+import pep8
 import flakey
 
 pep8style = None
     return sys.stdin.read()
 
 
-def version(option, opt, value, parser):
-    parser.print_usage()
-    parser.print_version()
-    sys.exit(0)
+def get_parser():
+    """Create a custom OptionParser"""
 
-
-def main():
-    global pep8style
+    def version(option, opt, value, parser):
+        parser.print_usage()
+        parser.print_version()
+        sys.exit(0)
 
     # Create our own parser
     parser = optparse.OptionParser('%prog [options]', version=version)
     parser.add_option('-V', '--version', action='callback',
                       callback=version,
                       help='Print the version info for flake8')
+    return parser
+
+
+def main():
+    global pep8style
+
+    parser = get_parser()
     # parse our flags
     opts, args = parser.parse_args()
 
     global pep8style
     if pep8style is None:
         pep8style = pep8.StyleGuide(config_file=True)
-    #pep8style.options.physical_checks = pep8.find_checks('physical_line')
-    #pep8style.options.logical_checks = pep8.find_checks('logical_line')
+    pep8style.options.physical_checks = pep8.find_checks('physical_line')
+    pep8style.options.logical_checks = pep8.find_checks('logical_line')
     pep8style.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
     pep8style.options.messages = {}
     pep8style.options.max_line_length = 79

flake8/tests/test_flakes.py

 from unittest import TestCase
-from flake8.pyflakes import check
+from flakey import check, print_messages
 
 
 code = """
 
     def test_exception(self):
         for c in (code, code2, code3):
-            warnings = check(code)
-            self.assertEqual(warnings, 0, code)
+            warnings = check(code, '(stdin)')
+            warnings = print_messages(warnings)
+            self.assertEqual(warnings, 0)
 
     def test_from_import_exception_in_scope(self):
-        self.assertEqual(check(code_from_import_exception), 0)
+        warnings = check(code_from_import_exception, '(stdin)')
+        warnings = print_messages(warnings)
+        self.assertEqual(warnings, 0)
 
     def test_import_exception_in_scope(self):
-        self.assertEqual(check(code_import_exception), 0)
+        warnings = check(code_import_exception, '(stdin)')
+        warnings = print_messages(warnings)
+        self.assertEqual(warnings, 0)
 import os
 
 ispy3 = sys.version_info[0] == 3
-iswin = os.name == 'nt' 
+iswin = os.name == 'nt'
 
 kwargs = {}
 scripts = ["flake8/flake8"]
     try:
         from setuptools import setup    # NOQA
         kwargs = {
-            'entry_points':
-                {'distutils.commands': ['flake8 = flake8.run:Flake8Command'],
-                 'console_scripts': ['flake8 = flake8.run:main']},
+            'entry_points': {
+                'distutils.commands': ['flake8 = flake8.run:Flake8Command'],
+                'console_scripts': ['flake8 = flake8.run:main']
+            },
             'tests_require': ['nose'],
             'test_suite': 'nose.collector',
         }
     url="http://bitbucket.org/tarek/flake8",
     packages=["flake8", "flake8.tests"],
     scripts=scripts,
-    requires=["flakey>=2.0",  "pep8"],
+    requires=["flakey (>=2.0)",  "pep8 (>=1.4)"],
     long_description=README,
     classifiers=[
         "Environment :: Console",
         "Programming Language :: Python",
         "Topic :: Software Development",
         "Topic :: Utilities",
-        ],
-    **kwargs)
+    ],
+    **kwargs
+)