Skip to content

Commit 968d293

Browse files
committed
[clang-tidy] NFC: Cleanup Python scripts
Summary: Silence few PEP8 warnings. Reviewers: hokein Reviewed By: hokein Subscribers: Eugene.Zelenko, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78985
1 parent a2a4e5a commit 968d293

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
#
3-
#===- add_new_check.py - clang-tidy check generator ----------*- python -*--===#
3+
#===- add_new_check.py - clang-tidy check generator ---------*- python -*--===#
44
#
55
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
66
# See https://llvm.org/LICENSE.txt for license information.
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
9-
#===------------------------------------------------------------------------===#
9+
#===-----------------------------------------------------------------------===#
1010

1111
from __future__ import print_function
1212

@@ -15,8 +15,9 @@
1515
import re
1616
import sys
1717

18-
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
19-
# and 'False' if the entry already existed.
18+
19+
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
20+
# entry and 'False' if the entry already existed.
2021
def adapt_cmake(module_path, check_name_camel):
2122
filename = os.path.join(module_path, 'CMakeLists.txt')
2223
with open(filename, 'r') as f:
@@ -227,7 +228,6 @@ def add_release_notes(module_path, module, check_name):
227228
with open(filename, 'w') as f:
228229
note_added = False
229230
header_found = False
230-
next_header_found = False
231231
add_note_here = False
232232

233233
for line in lines:
@@ -241,7 +241,6 @@ def add_release_notes(module_path, module, check_name):
241241
add_note_here = True
242242

243243
if match_next:
244-
next_header_found = True
245244
add_note_here = True
246245

247246
if match:

clang-tools-extra/clang-tidy/rename_check.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
#
3-
#===- rename_check.py - clang-tidy check renamer -------------*- python -*--===#
3+
#===- rename_check.py - clang-tidy check renamer ------------*- python -*--===#
44
#
55
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
66
# See https://llvm.org/LICENSE.txt for license information.
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
9-
#===------------------------------------------------------------------------===#
9+
#===-----------------------------------------------------------------------===#
1010

1111
import argparse
1212
import glob
@@ -26,6 +26,7 @@ def replaceInFileRegex(fileName, sFrom, sTo):
2626
with open(fileName, "w") as f:
2727
f.write(txt)
2828

29+
2930
def replaceInFile(fileName, sFrom, sTo):
3031
if sFrom == sTo:
3132
return
@@ -66,6 +67,7 @@ def fileRename(fileName, sFrom, sTo):
6667
os.rename(fileName, newFileName)
6768
return newFileName
6869

70+
6971
def deleteMatchingLines(fileName, pattern):
7072
lines = None
7173
with open(fileName, "r") as f:
@@ -82,6 +84,7 @@ def deleteMatchingLines(fileName, pattern):
8284

8385
return True
8486

87+
8588
def getListOfFiles(clang_tidy_path):
8689
files = glob.glob(os.path.join(clang_tidy_path, '*'))
8790
for dirname in files:
@@ -93,8 +96,9 @@ def getListOfFiles(clang_tidy_path):
9396
'clang-tidy', 'checks', '*'))
9497
return [filename for filename in files if os.path.isfile(filename)]
9598

96-
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
97-
# and 'False' if the entry already existed.
99+
100+
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
101+
# entry and 'False' if the entry already existed.
98102
def adapt_cmake(module_path, check_name_camel):
99103
filename = os.path.join(module_path, 'CMakeLists.txt')
100104
with open(filename, 'r') as f:
@@ -177,7 +181,6 @@ def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
177181
with open(filename, 'wb') as f:
178182
note_added = False
179183
header_found = False
180-
next_header_found = False
181184
add_note_here = False
182185

183186
for line in lines:
@@ -191,7 +194,6 @@ def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
191194
add_note_here = True
192195

193196
if match_next:
194-
next_header_found = True
195197
add_note_here = True
196198

197199
if match:
@@ -313,5 +315,6 @@ def main():
313315
+ ' --update-docs')
314316
add_release_notes(clang_tidy_path, args.old_check_name, args.new_check_name)
315317

318+
316319
if __name__ == '__main__':
317320
main()

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
#
3-
#===- clang-tidy-diff.py - ClangTidy Diff Checker ------------*- python -*--===#
3+
#===- clang-tidy-diff.py - ClangTidy Diff Checker -----------*- python -*--===#
44
#
55
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
66
# See https://llvm.org/LICENSE.txt for license information.
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
9-
#===------------------------------------------------------------------------===#
9+
#===-----------------------------------------------------------------------===#
1010

1111
r"""
1212
ClangTidy Diff Checker
@@ -75,7 +75,7 @@ def run_tidy(task_queue, lock, timeout):
7575
sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n')
7676
finally:
7777
with lock:
78-
if (not timeout is None) and (not watchdog is None):
78+
if not (timeout is None or watchdog is None):
7979
if not watchdog.is_alive():
8080
sys.stderr.write('Terminated by timeout: ' +
8181
' '.join(command) + '\n')
@@ -89,6 +89,7 @@ def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
8989
t.daemon = True
9090
t.start()
9191

92+
9293
def merge_replacement_files(tmpdir, mergefile):
9394
"""Merge all replacement files in a directory into a single file"""
9495
# The fixes suggested by clang-tidy >= 4.0.0 are given under
@@ -106,7 +107,7 @@ def merge_replacement_files(tmpdir, mergefile):
106107
# include/clang/Tooling/ReplacementsYaml.h, but the value
107108
# is actually never used inside clang-apply-replacements,
108109
# so we set it to '' here.
109-
output = { 'MainSourceFile': '', mergekey: merged }
110+
output = {'MainSourceFile': '', mergekey: merged}
110111
with open(mergefile, 'w') as out:
111112
yaml.safe_dump(output, out)
112113
else:

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env python
22
#
3-
#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===#
3+
#===- run-clang-tidy.py - Parallel clang-tidy runner --------*- python -*--===#
44
#
55
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
66
# See https://llvm.org/LICENSE.txt for license information.
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
9-
#===------------------------------------------------------------------------===#
9+
#===-----------------------------------------------------------------------===#
1010
# FIXME: Integrate with clang-tidy-diff.py
1111

12+
1213
"""
1314
Parallel clang-tidy runner
1415
==========================
@@ -60,6 +61,7 @@
6061
else:
6162
import queue as queue
6263

64+
6365
def find_compilation_database(path):
6466
"""Adjusts the directory until a compilation database is found."""
6567
result = './'
@@ -112,7 +114,7 @@ def merge_replacement_files(tmpdir, mergefile):
112114
"""Merge all replacement files in a directory into a single file"""
113115
# The fixes suggested by clang-tidy >= 4.0.0 are given under
114116
# the top level key 'Diagnostics' in the output yaml files
115-
mergekey="Diagnostics"
117+
mergekey = "Diagnostics"
116118
merged=[]
117119
for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
118120
content = yaml.safe_load(open(replacefile, 'r'))
@@ -125,7 +127,7 @@ def merge_replacement_files(tmpdir, mergefile):
125127
# include/clang/Tooling/ReplacementsYaml.h, but the value
126128
# is actually never used inside clang-apply-replacements,
127129
# so we set it to '' here.
128-
output = { 'MainSourceFile': '', mergekey: merged }
130+
output = {'MainSourceFile': '', mergekey: merged}
129131
with open(mergefile, 'w') as out:
130132
yaml.safe_dump(output, out)
131133
else:
@@ -324,11 +326,12 @@ def main():
324326
except:
325327
print('Error applying fixes.\n', file=sys.stderr)
326328
traceback.print_exc()
327-
return_code=1
329+
return_code = 1
328330

329331
if tmpdir:
330332
shutil.rmtree(tmpdir)
331333
sys.exit(return_code)
332334

335+
333336
if __name__ == '__main__':
334337
main()

0 commit comments

Comments
 (0)