[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
This commit is contained in:
Kirill Bobyrev
2020-05-18 12:21:27 +02:00
parent a2a4e5aae8
commit 968d293063
4 changed files with 27 additions and 21 deletions
@@ -1,12 +1,12 @@
#!/usr/bin/env python
#
#===- add_new_check.py - clang-tidy check generator ----------*- python -*--===#
#===- add_new_check.py - clang-tidy check generator ---------*- python -*--===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===------------------------------------------------------------------------===#
#===-----------------------------------------------------------------------===#
from __future__ import print_function
@@ -15,8 +15,9 @@ import os
import re
import sys
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
# and 'False' if the entry already existed.
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
# entry and 'False' if the entry already existed.
def adapt_cmake(module_path, check_name_camel):
filename = os.path.join(module_path, 'CMakeLists.txt')
with open(filename, 'r') as f:
@@ -227,7 +228,6 @@ def add_release_notes(module_path, module, check_name):
with open(filename, 'w') as f:
note_added = False
header_found = False
next_header_found = False
add_note_here = False
for line in lines:
@@ -241,7 +241,6 @@ def add_release_notes(module_path, module, check_name):
add_note_here = True
if match_next:
next_header_found = True
add_note_here = True
if match:
+9 -6
View File
@@ -1,12 +1,12 @@
#!/usr/bin/env python
#
#===- rename_check.py - clang-tidy check renamer -------------*- python -*--===#
#===- rename_check.py - clang-tidy check renamer ------------*- python -*--===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===------------------------------------------------------------------------===#
#===-----------------------------------------------------------------------===#
import argparse
import glob
@@ -26,6 +26,7 @@ def replaceInFileRegex(fileName, sFrom, sTo):
with open(fileName, "w") as f:
f.write(txt)
def replaceInFile(fileName, sFrom, sTo):
if sFrom == sTo:
return
@@ -66,6 +67,7 @@ def fileRename(fileName, sFrom, sTo):
os.rename(fileName, newFileName)
return newFileName
def deleteMatchingLines(fileName, pattern):
lines = None
with open(fileName, "r") as f:
@@ -82,6 +84,7 @@ def deleteMatchingLines(fileName, pattern):
return True
def getListOfFiles(clang_tidy_path):
files = glob.glob(os.path.join(clang_tidy_path, '*'))
for dirname in files:
@@ -93,8 +96,9 @@ def getListOfFiles(clang_tidy_path):
'clang-tidy', 'checks', '*'))
return [filename for filename in files if os.path.isfile(filename)]
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
# and 'False' if the entry already existed.
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
# entry and 'False' if the entry already existed.
def adapt_cmake(module_path, check_name_camel):
filename = os.path.join(module_path, 'CMakeLists.txt')
with open(filename, 'r') as f:
@@ -177,7 +181,6 @@ def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
with open(filename, 'wb') as f:
note_added = False
header_found = False
next_header_found = False
add_note_here = False
for line in lines:
@@ -191,7 +194,6 @@ def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
add_note_here = True
if match_next:
next_header_found = True
add_note_here = True
if match:
@@ -313,5 +315,6 @@ def main():
+ ' --update-docs')
add_release_notes(clang_tidy_path, args.old_check_name, args.new_check_name)
if __name__ == '__main__':
main()
@@ -1,12 +1,12 @@
#!/usr/bin/env python
#
#===- clang-tidy-diff.py - ClangTidy Diff Checker ------------*- python -*--===#
#===- clang-tidy-diff.py - ClangTidy Diff Checker -----------*- python -*--===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===------------------------------------------------------------------------===#
#===-----------------------------------------------------------------------===#
r"""
ClangTidy Diff Checker
@@ -75,7 +75,7 @@ def run_tidy(task_queue, lock, timeout):
sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n')
finally:
with lock:
if (not timeout is None) and (not watchdog is None):
if not (timeout is None or watchdog is None):
if not watchdog.is_alive():
sys.stderr.write('Terminated by timeout: ' +
' '.join(command) + '\n')
@@ -89,6 +89,7 @@ def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
t.daemon = True
t.start()
def merge_replacement_files(tmpdir, mergefile):
"""Merge all replacement files in a directory into a single file"""
# The fixes suggested by clang-tidy >= 4.0.0 are given under
@@ -106,7 +107,7 @@ def merge_replacement_files(tmpdir, mergefile):
# include/clang/Tooling/ReplacementsYaml.h, but the value
# is actually never used inside clang-apply-replacements,
# so we set it to '' here.
output = { 'MainSourceFile': '', mergekey: merged }
output = {'MainSourceFile': '', mergekey: merged}
with open(mergefile, 'w') as out:
yaml.safe_dump(output, out)
else:
@@ -1,14 +1,15 @@
#!/usr/bin/env python
#
#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===#
#===- run-clang-tidy.py - Parallel clang-tidy runner --------*- python -*--===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===------------------------------------------------------------------------===#
#===-----------------------------------------------------------------------===#
# FIXME: Integrate with clang-tidy-diff.py
"""
Parallel clang-tidy runner
==========================
@@ -60,6 +61,7 @@ if is_py2:
else:
import queue as queue
def find_compilation_database(path):
"""Adjusts the directory until a compilation database is found."""
result = './'
@@ -112,7 +114,7 @@ def merge_replacement_files(tmpdir, mergefile):
"""Merge all replacement files in a directory into a single file"""
# The fixes suggested by clang-tidy >= 4.0.0 are given under
# the top level key 'Diagnostics' in the output yaml files
mergekey="Diagnostics"
mergekey = "Diagnostics"
merged=[]
for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
content = yaml.safe_load(open(replacefile, 'r'))
@@ -125,7 +127,7 @@ def merge_replacement_files(tmpdir, mergefile):
# include/clang/Tooling/ReplacementsYaml.h, but the value
# is actually never used inside clang-apply-replacements,
# so we set it to '' here.
output = { 'MainSourceFile': '', mergekey: merged }
output = {'MainSourceFile': '', mergekey: merged}
with open(mergefile, 'w') as out:
yaml.safe_dump(output, out)
else:
@@ -324,11 +326,12 @@ def main():
except:
print('Error applying fixes.\n', file=sys.stderr)
traceback.print_exc()
return_code=1
return_code = 1
if tmpdir:
shutil.rmtree(tmpdir)
sys.exit(return_code)
if __name__ == '__main__':
main()