Ian Cordasco avatar Ian Cordasco committed a38b3ed

Use pep8's parser

That much closer to a release

Comments (0)

Files changed (2)

 import flakey
 import select
 from flake8 import mccabe
-from flake8.util import _initpep8, skip_file, get_parser, pep8style
+from flake8.util import _initpep8, skip_file, get_parser
+pep8style = None
 def main():
     global pep8style
     # parse out our flags so pep8 doesn't get confused
     parser = get_parser()
-    opts, sys.argv = parser.parse_args()
+    opts, _ = parser.parse_args()
     if opts.install_hook:
         from flake8.hooks import install_hook
+    if opts.builtins:
+        s = '--builtins={0}'.format(opts.builtins)
+        sys.argv.remove(s)
+    if opts.exit_zero:
+        sys.argv.remove('--exit-zero')
+    if opts.install_hook:
+        sys.argv.remove('--install-hook')
+    complexity = opts.max_complexity
+    if complexity > 0:
+        sys.argv.remove('--max-complexity={0}'.format(complexity))
     # make sure pep8 gets the information it expects
+    sys.argv.pop(0)
     sys.argv.insert(0, 'pep8')
     pep8style = pep8.StyleGuide(parse_argv=True, config_file=True)
     options = pep8style.options
-    complexity = opts.max_complexity
-    builtins = set(opts.builtins.split(','))
     warnings = 0
     stdin = None
+    builtins = set(opts.builtins.split(','))
     if builtins:
         orig_builtins = set(flakey.checker._MAGIC_GLOBALS)
         flakey.checker._MAGIC_GLOBALS = orig_builtins | builtins
 from __future__ import with_statement
 import re
 import os
+import sys
 from io import StringIO
 import optparse
     from flake8 import __version__
     import flakey
     import pep8
+    parser = pep8.get_parser()
     def version(option, opt, value, parser):
-    def help(option, opt, value, parser):
-        parser.print_help()
-        p = pep8.get_parser()
-        p.print_help()
-    # Create our own parser
-    parser = optparse.OptionParser('%prog [options] [file.py|directory]',
-                                   version=version, add_help_option=False)
     parser.version = '{0} (pep8: {1}, flakey: {2})'.format(
         __version__, pep8.__version__, flakey.__version__)
-    # don't overlap with pep8's verbose option
     parser.add_option('--builtins', default='', dest='builtins',
                       help="append builtin functions to flakey's "
-    parser.add_option('--ignore', default='',
-                      help='skip errors and warnings (e.g. E4,W)')
     parser.add_option('--exit-zero', action='store_true', default=False,
                       help='Exit with status 0 even if there are errors')
     parser.add_option('--max-complexity', default=-1, action='store',
                       type='int', help='McCabe complexity threshold')
+    parser.add_option('--install-hook', default=False, action='store_true',
+                      help='Install the appropriate hook for this '
+                      'repository.', dest='install_hook')
+    # don't overlap with pep8's verbose option
     parser.add_option('-V', '--version', action='callback',
                       help='Print the version info for flake8')
-    parser.add_option('--install-hook', default=False, action='store_true',
-                      help='Install the appropriate hook for this '
-                      'repository.', dest='install_hook')
-    parser.add_option('-h', '--help', action='callback', callback=help,
-                      help='Print this message and exit')
     return parser
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.