Commits

Jason Kölker  committed b8fe4f7

Add --builtins option to appending list of builtins

Useful for projects using gettext that add '_' as a builtin

  • Participants
  • Parent commits fcd0603

Comments (0)

Files changed (2)

File flake8/pep8.py

             __version__)
     parser = OptionParser(version=version,
                           usage="%prog [options] input ...")
+    parser.add_option('--builtins', default=[], action="append",
+                      help="append builtin function (pyflakes "
+                           "_MAGIC_GLOBALS)")
     parser.add_option('--max-complexity', default=-1, action='store',
                       type='int', help="McCabe complexity treshold")
     parser.add_option('-v', '--verbose', default=0, action='count',

File flake8/run.py

 def main():
     options, args = pep8.process_options()
     complexity = options.max_complexity
+    builtins = set(options.builtins)
     warnings = 0
+
+    if builtins:
+        orig_builtins = set(pyflakes._MAGIC_GLOBALS)
+        pyflakes._MAGIC_GLOBALS = orig_builtins | builtins
     if args:
         for path in _get_python_files(args):
             warnings += check_file(path, complexity)
     else:
         stdin = sys.stdin.read()
         warnings += check_code(stdin, complexity)
-
     raise SystemExit(warnings > 0)