Skip to content

Commit 208c671

Browse files
committed
Rollup merge of rust-lang#22029 - iKevinY:tidy-changes, r=brson
Currently, the list of files linted in `tidy.py` is unordered. It seems more appropriate for more frequently appearing files (like `.rs`) to appear at the top of the list and for \"other files\" to appear at the very end. This PR also changes the wildcard import of `check_license()` into an explicit one. ``` Before: After: * linted 4 .sh files * linted 5034 .rs files * linted 4 .h files * linted 29 .c files * linted 29 .c files * linted 28 .py files * linted 2 .js files * linted 4 .sh files * linted 0 other files * linted 4 .h files * linted 28 .py files * linted 2 .js files * linted 5034 .rs files * linted 0 other files ``` r? @brson
2 parents a3f2342 + 9569691 commit 208c671

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

src/etc/tidy.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import subprocess
1414
import re
1515
import os
16-
from licenseck import *
16+
from licenseck import check_license
1717
import snapshot
1818

1919
err = 0
@@ -22,13 +22,8 @@
2222
tab_flag = "ignore-tidy-tab"
2323
linelength_flag = "ignore-tidy-linelength"
2424

25-
# Be careful to support Python 2.4, 2.6, and 3.x here!
26-
config_proc = subprocess.Popen(["git", "config", "core.autocrlf"],
27-
stdout=subprocess.PIPE)
28-
result = config_proc.communicate()[0]
29-
30-
true = "true".encode('utf8')
31-
autocrlf = result.strip() == true if result is not None else False
25+
interesting_files = ['.rs', '.py', '.js', '.sh', '.c', '.h']
26+
uninteresting_files = ['miniz.c', 'jquery', 'rust_android_dummy']
3227

3328

3429
def report_error_name_no(name, no, s):
@@ -51,6 +46,34 @@ def do_license_check(name, contents):
5146
if not check_license(name, contents):
5247
report_error_name_no(name, 1, "incorrect license")
5348

49+
50+
def update_counts(current_name):
51+
global file_counts
52+
global count_other_linted_files
53+
54+
_, ext = os.path.splitext(current_name)
55+
56+
if ext in interesting_files:
57+
file_counts[ext] += 1
58+
else:
59+
count_other_linted_files += 1
60+
61+
62+
def interesting_file(f):
63+
if any(x in f for x in uninteresting_files):
64+
return False
65+
66+
return any(os.path.splitext(f)[1] == ext for ext in interesting_files)
67+
68+
69+
# Be careful to support Python 2.4, 2.6, and 3.x here!
70+
config_proc = subprocess.Popen(["git", "config", "core.autocrlf"],
71+
stdout=subprocess.PIPE)
72+
result = config_proc.communicate()[0]
73+
74+
true = "true".encode('utf8')
75+
autocrlf = result.strip() == true if result is not None else False
76+
5477
current_name = ""
5578
current_contents = ""
5679
check_tab = True
@@ -63,28 +86,16 @@ def do_license_check(name, contents):
6386

6487
src_dir = sys.argv[1]
6588

66-
try:
67-
count_lines = 0
68-
count_non_blank_lines = 0
89+
count_lines = 0
90+
count_non_blank_lines = 0
91+
count_other_linted_files = 0
6992

70-
interesting_files = ['.rs', '.py', '.js', '.sh', '.c', '.h']
93+
file_counts = {ext: 0 for ext in interesting_files}
7194

72-
file_counts = {ext: 0 for ext in interesting_files}
73-
file_counts['other'] = 0
74-
75-
def update_counts(current_name):
76-
global file_counts
77-
_, ext = os.path.splitext(current_name)
78-
79-
if ext in file_counts:
80-
file_counts[ext] += 1
81-
else:
82-
file_counts['other'] += 1
83-
84-
all_paths = set()
95+
all_paths = set()
8596

97+
try:
8698
for (dirpath, dirnames, filenames) in os.walk(src_dir):
87-
8899
# Skip some third-party directories
89100
skippable_dirs = {
90101
'src/jemalloc',
@@ -103,14 +114,6 @@ def update_counts(current_name):
103114
if any(d in dirpath for d in skippable_dirs):
104115
continue
105116

106-
def interesting_file(f):
107-
if "miniz.c" in f \
108-
or "jquery" in f \
109-
or "rust_android_dummy" in f:
110-
return False
111-
112-
return any(os.path.splitext(f)[1] == ext for ext in interesting_files)
113-
114117
file_names = [os.path.join(dirpath, f) for f in filenames
115118
if interesting_file(f)
116119
and not f.endswith("_gen.rs")
@@ -196,10 +199,11 @@ def interesting_file(f):
196199
report_err("UTF-8 decoding error " + str(e))
197200

198201
print
199-
for ext in file_counts:
200-
print "* linted " + str(file_counts[ext]) + " " + ext + " files"
201-
print "* total lines of code: " + str(count_lines)
202-
print "* total non-blank lines of code: " + str(count_non_blank_lines)
202+
for ext in sorted(file_counts, key=file_counts.get, reverse=True):
203+
print "* linted {} {} files".format(file_counts[ext], ext)
204+
print "* linted {} other files".format(count_other_linted_files)
205+
print "* total lines of code: {}".format(count_lines)
206+
print "* total non-blank lines of code: {}".format(count_non_blank_lines)
203207
print
204208

205209
sys.exit(err)

0 commit comments

Comments
 (0)