From b8575081edbd52c7393760ff0bac78c44b4e0396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20K=C3=B6lker?= Date: Wed, 15 Feb 2012 11:17:17 -0600 Subject: [PATCH] Add --builtins option to appending list of builtins Useful for projects using gettext that add '_' as a builtin --- flake8/pep8.py | 3 +++ flake8/run.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/flake8/pep8.py b/flake8/pep8.py index a3e93cd..6b95648 100644 --- a/flake8/pep8.py +++ b/flake8/pep8.py @@ -1272,6 +1272,9 @@ def process_options(arglist=None): __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', diff --git a/flake8/run.py b/flake8/run.py index a24807b..e95d57a 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -47,14 +47,18 @@ def _get_python_files(paths): 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)