mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-13 08:04:18 +00:00
Add --builtins option to appending list of builtins
Useful for projects using gettext that add '_' as a builtin
This commit is contained in:
parent
625834cfff
commit
b8575081ed
2 changed files with 8 additions and 1 deletions
|
|
@ -1272,6 +1272,9 @@ def process_options(arglist=None):
|
||||||
__version__)
|
__version__)
|
||||||
parser = OptionParser(version=version,
|
parser = OptionParser(version=version,
|
||||||
usage="%prog [options] input ...")
|
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',
|
parser.add_option('--max-complexity', default=-1, action='store',
|
||||||
type='int', help="McCabe complexity treshold")
|
type='int', help="McCabe complexity treshold")
|
||||||
parser.add_option('-v', '--verbose', default=0, action='count',
|
parser.add_option('-v', '--verbose', default=0, action='count',
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,18 @@ def _get_python_files(paths):
|
||||||
def main():
|
def main():
|
||||||
options, args = pep8.process_options()
|
options, args = pep8.process_options()
|
||||||
complexity = options.max_complexity
|
complexity = options.max_complexity
|
||||||
|
builtins = set(options.builtins)
|
||||||
warnings = 0
|
warnings = 0
|
||||||
|
|
||||||
|
if builtins:
|
||||||
|
orig_builtins = set(pyflakes._MAGIC_GLOBALS)
|
||||||
|
pyflakes._MAGIC_GLOBALS = orig_builtins | builtins
|
||||||
if args:
|
if args:
|
||||||
for path in _get_python_files(args):
|
for path in _get_python_files(args):
|
||||||
warnings += check_file(path, complexity)
|
warnings += check_file(path, complexity)
|
||||||
else:
|
else:
|
||||||
stdin = sys.stdin.read()
|
stdin = sys.stdin.read()
|
||||||
warnings += check_code(stdin, complexity)
|
warnings += check_code(stdin, complexity)
|
||||||
|
|
||||||
raise SystemExit(warnings > 0)
|
raise SystemExit(warnings > 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue