Author: Kirill Bobyrev
Date: 2020-05-18T12:21:27+02:00
New Revision: 968d293063bc008ff93ff8fcf363039ce61574a2

URL: 
https://github.com/llvm/llvm-project/commit/968d293063bc008ff93ff8fcf363039ce61574a2
DIFF: 
https://github.com/llvm/llvm-project/commit/968d293063bc008ff93ff8fcf363039ce61574a2.diff

LOG: [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

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/add_new_check.py
    clang-tools-extra/clang-tidy/rename_check.py
    clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
    clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index 4477444cc127..454d128a5dcb 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -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 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:

diff  --git a/clang-tools-extra/clang-tidy/rename_check.py 
b/clang-tools-extra/clang-tidy/rename_check.py
index 528c2a19a2b7..4d5311c9a293 100755
--- a/clang-tools-extra/clang-tidy/rename_check.py
+++ b/clang-tools-extra/clang-tidy/rename_check.py
@@ -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()

diff  --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
index 8b6ad9045576..17086d15053e 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
@@ -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:

diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 1c4f3ad59ac8..4272ae0957fe 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -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 @@
 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()


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to