From bf010c4a15840964ec92912e5582095d029bc314 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 7 Jun 2015 13:54:13 +1000 Subject: Cleanup: pep8 --- build_files/cmake/cmake_consistency_check.py | 158 +++++++++++---------- release/bin/blender-thumbnailer.py | 6 +- release/scripts/modules/rna_info.py | 6 +- release/scripts/modules/rna_xml.py | 2 +- release/scripts/startup/bl_operators/mesh.py | 1 - .../templates_py/ui_previews_dynamic_enum.py | 2 +- tests/python/bl_run_operators.py | 2 +- tests/python/pep8.py | 13 +- tests/python/rst_to_doctree_mini.py | 21 +-- 9 files changed, 119 insertions(+), 92 deletions(-) diff --git a/build_files/cmake/cmake_consistency_check.py b/build_files/cmake/cmake_consistency_check.py index 1a366880315..d0bbdda1870 100755 --- a/build_files/cmake/cmake_consistency_check.py +++ b/build_files/cmake/cmake_consistency_check.py @@ -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() diff --git a/release/bin/blender-thumbnailer.py b/release/bin/blender-thumbnailer.py index 779c6156e70..d3b31d63fad 100755 --- a/release/bin/blender-thumbnailer.py +++ b/release/bin/blender-thumbnailer.py @@ -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() diff --git a/release/scripts/modules/rna_info.py b/release/scripts/modules/rna_info.py index ed80423023e..dae262e93d7 100644 --- a/release/scripts/modules/rna_info.py +++ b/release/scripts/modules/rna_info.py @@ -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() diff --git a/release/scripts/modules/rna_xml.py b/release/scripts/modules/rna_xml.py index 729d6238ac3..ad4809efbe1 100644 --- a/release/scripts/modules/rna_xml.py +++ b/release/scripts/modules/rna_xml.py @@ -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(): diff --git a/release/scripts/startup/bl_operators/mesh.py b/release/scripts/startup/bl_operators/mesh.py index f86c31cd9cc..ea504d48448 100644 --- a/release/scripts/startup/bl_operators/mesh.py +++ b/release/scripts/startup/bl_operators/mesh.py @@ -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)): diff --git a/release/scripts/templates_py/ui_previews_dynamic_enum.py b/release/scripts/templates_py/ui_previews_dynamic_enum.py index 5169b82992e..0cfa232116d 100644 --- a/release/scripts/templates_py/ui_previews_dynamic_enum.py +++ b/release/scripts/templates_py/ui_previews_dynamic_enum.py @@ -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) diff --git a/tests/python/bl_run_operators.py b/tests/python/bl_run_operators.py index d511cd19ff7..f3c553cf3ef 100644 --- a/tests/python/bl_run_operators.py +++ b/tests/python/bl_run_operators.py @@ -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(): diff --git a/tests/python/pep8.py b/tests/python/pep8.py index 551e2a87e9b..0d6db729767 100644 --- a/tests/python/pep8.py +++ b/tests/python/pep8.py @@ -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: diff --git a/tests/python/rst_to_doctree_mini.py b/tests/python/rst_to_doctree_mini.py index 6a885a108f8..dfc6cd57db6 100644 --- a/tests/python/rst_to_doctree_mini.py +++ b/tests/python/rst_to_doctree_mini.py @@ -28,13 +28,14 @@ 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() -- cgit v1.2.3