@@ -44,11 +44,11 @@ def find_ids_in_source_file(file_name, id_to_file_names):
44
44
if in_comment (source , m .start ()):
45
45
continue
46
46
underscore_pos = m .group (0 ).index ("_" )
47
- id = m .group (0 )[0 :underscore_pos ]
48
- if id in id_to_file_names :
49
- id_to_file_names [id ].append (file_name )
47
+ error_id = m .group (0 )[0 :underscore_pos ]
48
+ if error_id in id_to_file_names :
49
+ id_to_file_names [error_id ].append (file_name )
50
50
else :
51
- id_to_file_names [id ] = [file_name ]
51
+ id_to_file_names [error_id ] = [file_name ]
52
52
53
53
54
54
def find_ids_in_source_files (file_names ):
@@ -76,16 +76,16 @@ def fix_ids_in_source_file(file_name, id_to_count, available_ids):
76
76
destination .extend (source [k :m .start ()])
77
77
78
78
underscore_pos = m .group (0 ).index ("_" )
79
- id = m .group (0 )[0 :underscore_pos ]
79
+ error_id = m .group (0 )[0 :underscore_pos ]
80
80
81
81
# incorrect id or id has a duplicate somewhere
82
- if not in_comment (source , m .start ()) and (len (id ) != 4 or id [0 ] == "0" or id_to_count [id ] > 1 ):
83
- assert id in id_to_count
82
+ if not in_comment (source , m .start ()) and (len (error_id ) != 4 or error_id [0 ] == "0" or id_to_count [error_id ] > 1 ):
83
+ assert error_id in id_to_count
84
84
new_id = get_next_id (available_ids )
85
85
assert new_id not in id_to_count
86
- id_to_count [id ] -= 1
86
+ id_to_count [error_id ] -= 1
87
87
else :
88
- new_id = id
88
+ new_id = error_id
89
89
90
90
destination .extend (new_id + "_error" )
91
91
k = m .end ()
@@ -104,7 +104,7 @@ def fix_ids_in_source_files(file_names, id_to_count):
104
104
id_to_count contains number of appearances of every id in sources
105
105
"""
106
106
107
- available_ids = {str (id ) for id in range (1000 , 10000 )} - id_to_count .keys ()
107
+ available_ids = {str (error_id ) for error_id in range (1000 , 10000 )} - id_to_count .keys ()
108
108
for file_name in file_names :
109
109
fix_ids_in_source_file (file_name , id_to_count , available_ids )
110
110
@@ -113,8 +113,8 @@ def find_files(top_dir, sub_dirs, extensions):
113
113
"""Builds a list of files with given extensions in specified subdirectories"""
114
114
115
115
source_file_names = []
116
- for dir in sub_dirs :
117
- for root , _ , file_names in os .walk (os .path .join (top_dir , dir ), onerror = lambda e : exit (f"Walk error: { e } " )):
116
+ for directory in sub_dirs :
117
+ for root , _ , file_names in os .walk (os .path .join (top_dir , directory ), onerror = lambda e : sys . exit (f"Walk error: { e } " )):
118
118
for file_name in file_names :
119
119
_ , ext = path .splitext (file_name )
120
120
if ext in extensions :
@@ -145,27 +145,27 @@ def find_ids_in_cmdline_test_err(file_name):
145
145
146
146
147
147
def print_ids (ids ):
148
- for k , id in enumerate (sorted (ids )):
148
+ for k , error_id in enumerate (sorted (ids )):
149
149
if k % 10 > 0 :
150
150
print (" " , end = "" )
151
151
elif k > 0 :
152
152
print ()
153
- print (id , end = "" )
153
+ print (error_id , end = "" )
154
154
155
155
156
156
def print_ids_per_file (ids , id_to_file_names , top_dir ):
157
157
file_name_to_ids = {}
158
- for id in ids :
159
- for file_name in id_to_file_names [id ]:
158
+ for error_id in ids :
159
+ for file_name in id_to_file_names [error_id ]:
160
160
relpath = path .relpath (file_name , top_dir )
161
161
if relpath not in file_name_to_ids :
162
162
file_name_to_ids [relpath ] = []
163
- file_name_to_ids [relpath ].append (id )
163
+ file_name_to_ids [relpath ].append (error_id )
164
164
165
165
for file_name in sorted (file_name_to_ids ):
166
166
print (file_name )
167
- for id in sorted (file_name_to_ids [file_name ]):
168
- print (f" { id } " , end = "" )
167
+ for error_id in sorted (file_name_to_ids [file_name ]):
168
+ print (f" { error_id } " , end = "" )
169
169
print ()
170
170
171
171
@@ -289,15 +289,15 @@ def main(argv):
289
289
source_id_to_file_names = find_ids_in_source_files (source_file_names )
290
290
291
291
ok = True
292
- for id in sorted (source_id_to_file_names ):
293
- if len (id ) != 4 :
294
- print (f"ID { id } length != 4" )
292
+ for error_id in sorted (source_id_to_file_names ):
293
+ if len (error_id ) != 4 :
294
+ print (f"ID { error_id } length != 4" )
295
295
ok = False
296
- if id [0 ] == "0" :
297
- print (f"ID { id } starts with zero" )
296
+ if error_id [0 ] == "0" :
297
+ print (f"ID { error_id } starts with zero" )
298
298
ok = False
299
- if len (source_id_to_file_names [id ]) > 1 :
300
- print (f"ID { id } appears { len (source_id_to_file_names [id ])} times" )
299
+ if len (source_id_to_file_names [error_id ]) > 1 :
300
+ print (f"ID { error_id } appears { len (source_id_to_file_names [error_id ])} times" )
301
301
ok = False
302
302
303
303
if examine_coverage :
@@ -315,7 +315,7 @@ def main(argv):
315
315
if not ok :
316
316
print ("Incorrect IDs have to be fixed before applying --next" )
317
317
sys .exit (1 )
318
- available_ids = {str (id ) for id in range (1000 , 10000 )} - source_id_to_file_names .keys ()
318
+ available_ids = {str (error_id ) for error_id in range (1000 , 10000 )} - source_id_to_file_names .keys ()
319
319
next_id = get_next_id (available_ids )
320
320
print (f"Next ID: { next_id } " )
321
321
sys .exit (0 )
@@ -341,7 +341,7 @@ def main(argv):
341
341
sys .exit (1 )
342
342
343
343
# number of appearances for every id
344
- source_id_to_count = { id : len (file_names ) for id , file_names in source_id_to_file_names .items () }
344
+ source_id_to_count = { error_id : len (file_names ) for error_id , file_names in source_id_to_file_names .items () }
345
345
346
346
fix_ids_in_source_files (source_file_names , source_id_to_count )
347
347
print ("Fixing completed" )
0 commit comments