Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc86a4e

Browse files
committed
Added a -q ('quiet') option to tabnanny, which causes only the names of
offending files to be printed. Good for emacs `tabnanny.py *.py`
1 parent ea51632 commit dc86a4e

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

Lib/tabnanny.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tokenize
1313

1414
verbose = 0
15+
filename_only = 0
1516

1617
def errprint(*args):
1718
sep = ""
@@ -21,13 +22,15 @@ def errprint(*args):
2122
sys.stderr.write("\n")
2223

2324
def main():
24-
global verbose
25+
global verbose, filename_only
2526
try:
26-
opts, args = getopt.getopt(sys.argv[1:], "v")
27+
opts, args = getopt.getopt(sys.argv[1:], "qv")
2728
except getopt.error, msg:
2829
errprint(msg)
2930
return
3031
for o, a in opts:
32+
if o == '-q':
33+
filename_only = filename_only + 1
3134
if o == '-v':
3235
verbose = verbose + 1
3336
if not args:
@@ -85,7 +88,8 @@ def check(file):
8588
print "offending line:", `line`
8689
print nag.get_msg()
8790
else:
88-
print file, badline, `line`
91+
if filename_only: print file
92+
else: print file, badline, `line`
8993
return
9094

9195
if verbose:

Tools/idle/tabnanny.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tokenize
1313

1414
verbose = 0
15+
filename_only = 0
1516

1617
def errprint(*args):
1718
sep = ""
@@ -21,13 +22,15 @@ def errprint(*args):
2122
sys.stderr.write("\n")
2223

2324
def main():
24-
global verbose
25+
global verbose, filename_only
2526
try:
26-
opts, args = getopt.getopt(sys.argv[1:], "v")
27+
opts, args = getopt.getopt(sys.argv[1:], "qv")
2728
except getopt.error, msg:
2829
errprint(msg)
2930
return
3031
for o, a in opts:
32+
if o == '-q':
33+
filename_only = filename_only + 1
3134
if o == '-v':
3235
verbose = verbose + 1
3336
if not args:
@@ -85,7 +88,8 @@ def check(file):
8588
print "offending line:", `line`
8689
print nag.get_msg()
8790
else:
88-
print file, badline, `line`
91+
if filename_only: print file
92+
else: print file, badline, `line`
8993
return
9094

9195
if verbose:

Tools/scripts/tabnanny.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tokenize
1313

1414
verbose = 0
15+
filename_only = 0
1516

1617
def errprint(*args):
1718
sep = ""
@@ -21,13 +22,15 @@ def errprint(*args):
2122
sys.stderr.write("\n")
2223

2324
def main():
24-
global verbose
25+
global verbose, filename_only
2526
try:
26-
opts, args = getopt.getopt(sys.argv[1:], "v")
27+
opts, args = getopt.getopt(sys.argv[1:], "qv")
2728
except getopt.error, msg:
2829
errprint(msg)
2930
return
3031
for o, a in opts:
32+
if o == '-q':
33+
filename_only = filename_only + 1
3134
if o == '-v':
3235
verbose = verbose + 1
3336
if not args:
@@ -85,7 +88,8 @@ def check(file):
8588
print "offending line:", `line`
8689
print nag.get_msg()
8790
else:
88-
print file, badline, `line`
91+
if filename_only: print file
92+
else: print file, badline, `line`
8993
return
9094

9195
if verbose:

0 commit comments

Comments
 (0)