Cleanup: pep8
authorCampbell Barton <ideasman42@gmail.com>
Sun, 7 Jun 2015 03:54:13 +0000 (13:54 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 7 Jun 2015 07:28:02 +0000 (17:28 +1000)
build_files/cmake/cmake_consistency_check.py
release/bin/blender-thumbnailer.py
release/scripts/modules/rna_info.py
release/scripts/modules/rna_xml.py
release/scripts/startup/bl_operators/mesh.py
release/scripts/templates_py/ui_previews_dynamic_enum.py
tests/python/bl_run_operators.py
tests/python/pep8.py
tests/python/rst_to_doctree_mini.py

index 1a3668803158cdc3cebc43fa53c2592b6b82f3f6..d0bbdda1870c8c349cf36789baa591341cedc5d5 100755 (executable)
@@ -39,8 +39,6 @@ from cmake_consistency_check_config import (
 import os
 from os.path import join, dirname, normpath, splitext
 
-print("Scanning:", SOURCE_DIR)
-
 global_h = set()
 global_c = set()
 global_refs = {}
@@ -211,7 +209,7 @@ def cmake_get_src(f):
                                 if new_path_rel != l:
                                     print("overly relative path:\n  %s:%d\n  %s\n  %s" % (f, i, l, new_path_rel))
 
-                                    ## Save time. just replace the line
+                                    # # Save time. just replace the line
                                     # replace_line(f, i - 1, new_path_rel)
 
                             else:
@@ -242,10 +240,6 @@ def cmake_get_src(f):
     filen.close()
 
 
-for cmake in source_list(SOURCE_DIR, is_cmake):
-    cmake_get_src(cmake)
-
-
 def is_ignore(f):
     for ig in IGNORE:
         if ig in f:
@@ -253,73 +247,83 @@ def is_ignore(f):
     return False
 
 
-# First do stupid check, do these files exist?
-print("\nChecking for missing references:")
-is_err = False
-errs = []
-for f in (global_h | global_c):
-    if f.startswith(BUILD_DIR):
-        continue
-
-    if not os.path.exists(f):
-        refs = global_refs[f]
-        if refs:
-            for cf, i in refs:
-                errs.append((cf, i))
-        else:
-            raise Exception("CMake referenecs missing, internal error, aborting!")
-        is_err = True
-
-errs.sort()
-errs.reverse()
-for cf, i in errs:
-    print("%s:%d" % (cf, i))
-    # Write a 'sed' script, useful if we get a lot of these
-    # print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
-
-
-if is_err:
-    raise Exception("CMake referenecs missing files, aborting!")
-del is_err
-del errs
-
-# now check on files not accounted for.
-print("\nC/C++ Files CMake doesnt know about...")
-for cf in sorted(source_list(SOURCE_DIR, is_c)):
-    if not is_ignore(cf):
-        if cf not in global_c:
-            print("missing_c: ", cf)
-
-        # check if automake builds a corrasponding .o file.
-        '''
-        if cf in global_c:
-            out1 = os.path.splitext(cf)[0] + ".o"
-            out2 = os.path.splitext(cf)[0] + ".Po"
-            out2_dir, out2_file = out2 = os.path.split(out2)
-            out2 = os.path.join(out2_dir, ".deps", out2_file)
-            if not os.path.exists(out1) and not os.path.exists(out2):
-                print("bad_c: ", cf)
-        '''
-
-print("\nC/C++ Headers CMake doesnt know about...")
-for hf in sorted(source_list(SOURCE_DIR, is_c_header)):
-    if not is_ignore(hf):
-        if hf not in global_h:
-            print("missing_h: ", hf)
-
-if UTF8_CHECK:
-    # test encoding
-    import traceback
-    for files in (global_c, global_h):
-        for f in sorted(files):
-            if os.path.exists(f):
-                # ignore outside of our source tree
-                if "extern" not in f:
-                    i = 1
-                    try:
-                        for l in open(f, "r", encoding="utf8"):
-                            i += 1
-                    except UnicodeDecodeError:
-                        print("Non utf8: %s:%d" % (f, i))
-                        if i > 1:
-                            traceback.print_exc()
+def main():
+
+    print("Scanning:", SOURCE_DIR)
+
+    for cmake in source_list(SOURCE_DIR, is_cmake):
+        cmake_get_src(cmake)
+
+    # First do stupid check, do these files exist?
+    print("\nChecking for missing references:")
+    is_err = False
+    errs = []
+    for f in (global_h | global_c):
+        if f.startswith(BUILD_DIR):
+            continue
+
+        if not os.path.exists(f):
+            refs = global_refs[f]
+            if refs:
+                for cf, i in refs:
+                    errs.append((cf, i))
+            else:
+                raise Exception("CMake referenecs missing, internal error, aborting!")
+            is_err = True
+
+    errs.sort()
+    errs.reverse()
+    for cf, i in errs:
+        print("%s:%d" % (cf, i))
+        # Write a 'sed' script, useful if we get a lot of these
+        # print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
+
+
+    if is_err:
+        raise Exception("CMake referenecs missing files, aborting!")
+    del is_err
+    del errs
+
+    # now check on files not accounted for.
+    print("\nC/C++ Files CMake doesnt know about...")
+    for cf in sorted(source_list(SOURCE_DIR, is_c)):
+        if not is_ignore(cf):
+            if cf not in global_c:
+                print("missing_c: ", cf)
+
+            # check if automake builds a corrasponding .o file.
+            '''
+            if cf in global_c:
+                out1 = os.path.splitext(cf)[0] + ".o"
+                out2 = os.path.splitext(cf)[0] + ".Po"
+                out2_dir, out2_file = out2 = os.path.split(out2)
+                out2 = os.path.join(out2_dir, ".deps", out2_file)
+                if not os.path.exists(out1) and not os.path.exists(out2):
+                    print("bad_c: ", cf)
+            '''
+
+    print("\nC/C++ Headers CMake doesnt know about...")
+    for hf in sorted(source_list(SOURCE_DIR, is_c_header)):
+        if not is_ignore(hf):
+            if hf not in global_h:
+                print("missing_h: ", hf)
+
+    if UTF8_CHECK:
+        # test encoding
+        import traceback
+        for files in (global_c, global_h):
+            for f in sorted(files):
+                if os.path.exists(f):
+                    # ignore outside of our source tree
+                    if "extern" not in f:
+                        i = 1
+                        try:
+                            for l in open(f, "r", encoding="utf8"):
+                                i += 1
+                        except UnicodeDecodeError:
+                            print("Non utf8: %s:%d" % (f, i))
+                            if i > 1:
+                                traceback.print_exc()
+
+if __name__ == "__main__":
+    main()
index 779c6156e70c65018d6d4d7fbd22011a97a3705a..d3b31d63fad94c0235fa4e8dd1a2d9abc925dd7f 100755 (executable)
@@ -170,7 +170,7 @@ def write_png(buf, width, height):
         png_pack(b'IEND', b'')])
 
 
-if __name__ == '__main__':
+def main():
     import sys
 
     if len(sys.argv) < 3:
@@ -186,3 +186,7 @@ if __name__ == '__main__':
             f = open(file_out, "wb")
             f.write(write_png(buf, width, height))
             f.close()
+
+
+if __name__ == '__main__':
+    main()
index ed80423023e16caa1d0d4bb68c0ee0e54a534bed..dae262e93d72d8fa102153fe0460f181fb12be67 100644 (file)
@@ -696,7 +696,7 @@ def BuildRNAInfo():
     return InfoStructRNA.global_lookup, InfoFunctionRNA.global_lookup, InfoOperatorRNA.global_lookup, InfoPropertyRNA.global_lookup
 
 
-if __name__ == "__main__":
+def main():
     import rna_info
     struct = rna_info.BuildRNAInfo()[0]
     data = []
@@ -724,3 +724,7 @@ if __name__ == "__main__":
     else:
         text = bpy.data.texts.new(name="api.py")
         text.from_string(data)
+
+
+if __name__ == "__main__":
+    main()
index 729d6238ac32b8b33def57eefc477f0f3e8036cb..ad4809efbe1c71f7c1f749d0bf3b864c1f705673 100644 (file)
@@ -32,7 +32,7 @@ def build_property_typemap(skip_classes, skip_typemap):
         if issubclass(cls, skip_classes):
             continue
 
-        ## to support skip-save we cant get all props
+        # # to support skip-save we cant get all props
         # properties = cls.bl_rna.properties.keys()
         properties = []
         for prop_id, prop in cls.bl_rna.properties.items():
index f86c31cd9cc3d923f00cf2705685265089ee3de2..ea504d48448dbb47199e8dba09ff836c05df407b 100644 (file)
@@ -75,7 +75,6 @@ class MeshMirrorUV(Operator):
                 double_warn += co in mirror_lt
                 mirror_lt[co] = i
 
-        #for i, v in enumerate(mesh.vertices):
         vmap = {}
         for mirror_a, mirror_b in ((mirror_gt, mirror_lt),
                                    (mirror_lt, mirror_gt)):
index 5169b82992e7361376d2344a33bc331710f2587d..0cfa232116dcd93038a7315441984b33d298a750 100644 (file)
@@ -44,7 +44,7 @@ def enum_previews_from_directory_items(self, context):
     if directory and os.path.exists(directory):
         # Scan the directory for png files
         image_paths = []
-        for fn in  os.listdir(directory):
+        for fn in os.listdir(directory):
             if fn.lower().endswith(".png"):
                 image_paths.append(fn)
 
index d511cd19ff7867853aca54de364ddac0cda320a9..f3c553cf3ef8c46f96980c14462d5c2322016fbb 100644 (file)
@@ -163,7 +163,7 @@ if USE_ATTRSET:
             if issubclass(cls, skip_classes):
                 continue
 
-            ## to support skip-save we cant get all props
+            # # to support skip-save we cant get all props
             # properties = cls.bl_rna.properties.keys()
             properties = []
             for prop_id, prop in cls.bl_rna.properties.items():
index 551e2a87e9bdcde91e2e986f4d275126a8ffd4e6..0d6db7297672405e4648da0cab6f9fc2123de967 100644 (file)
@@ -117,7 +117,18 @@ def main():
 
     # these are very picky and often hard to follow
     # while keeping common script formatting.
-    ignore = "E122", "E123", "E124", "E125", "E126", "E127", "E128"
+    ignore = (
+        "E122",
+        "E123",
+        "E124",
+        "E125",
+        "E126",
+        "E127",
+        "E128",
+        # "imports not at top of file."
+        # prefer to load as needed (lazy load addons etc).
+        "E402",
+        )
 
     for f, pep8_type in files:
 
index 6a885a108f80b1fc3c10b415911d4fe937c8f0c6..dfc6cd57db6042fd42ca6f99a62874da0c9c0f4b 100644 (file)
 
 import collections
 
-Directive = collections.namedtuple('Directive',
-                                   ("type",
-                                    "value",
-                                    "value_strip",
-                                    "line",
-                                    "indent",
-                                    "members"))
+Directive = collections.namedtuple(
+    "Directive",
+    ("type",
+     "value",
+     "value_strip",
+     "line",
+     "indent",
+     "members"))
 
 
 def parse_rst_py(filepath):
@@ -80,7 +81,7 @@ def parse_rst_py(filepath):
     return tree[0]
 
 
-if __name__ == "__main__":
+def main():
     # not intended use, but may as well print rst files passed as a test.
     import sys
     for arg in sys.argv:
@@ -88,3 +89,7 @@ if __name__ == "__main__":
             items = parse_rst_py(arg)
             for i in items:
                 print(i)
+
+
+if __name__ == "__main__":
+    main()