From 6e88fc5a17fc2d9e0966e3f20ddee07d24ae3935 Mon Sep 17 00:00:00 2001 From: Campbell Barton <ideasman42@gmail.com> Date: Wed, 20 Apr 2022 15:18:29 +1000 Subject: [PATCH] Cleanup: run autopep8 --- check_source/check_cmake_consistency.py | 1 - check_source/check_licenses.py | 2 +- check_source/check_spelling.py | 2 +- check_source/check_unused_defines.py | 12 ++++++++---- modules/blendfile.py | 9 +++++---- utils/blender_keyconfig_export_permutations.py | 2 +- utils/blender_merge_format_changes.py | 6 ++++-- utils/blender_theme_as_c.py | 1 + utils/cycles_commits_sync.py | 4 ++-- utils/cycles_timeit.py | 2 +- utils_maintenance/c_struct_clean.py | 1 + utils_maintenance/modules/batch_edit_text.py | 5 ++++- 12 files changed, 29 insertions(+), 18 deletions(-) diff --git a/check_source/check_cmake_consistency.py b/check_source/check_cmake_consistency.py index d497292..c34b07d 100755 --- a/check_source/check_cmake_consistency.py +++ b/check_source/check_cmake_consistency.py @@ -216,7 +216,6 @@ def cmake_get_src(f: str) -> None: f_rel_key = f_rel_key.replace(os.sep, "/") local_ignore_source_missing = global_ignore_source_missing.get(f_rel_key, []) - for l, line_number in tokens: # Replace directories. l = l.replace("${CMAKE_SOURCE_DIR}", SOURCE_DIR) diff --git a/check_source/check_licenses.py b/check_source/check_licenses.py index 09a94db..c05b534 100644 --- a/check_source/check_licenses.py +++ b/check_source/check_licenses.py @@ -245,7 +245,7 @@ def check_contents(filepath: str, text: str) -> None: print("Comment Block:", filepath, "failed to find comment end") return comment_end += 2 - comment_block = text[comment_beg + 2 : comment_end - 2] + comment_block = text[comment_beg + 2: comment_end - 2] comment_block = "\n".join( [l.removeprefix(" *") for l in comment_block.split("\n")] ) diff --git a/check_source/check_spelling.py b/check_source/check_spelling.py index 46e8122..4e3fc02 100755 --- a/check_source/check_spelling.py +++ b/check_source/check_spelling.py @@ -73,11 +73,11 @@ files_ignore = { # ----------------------------------------------------------------------------- # Dictionary Utilities + def dictionary_create(): # type: ignore import enchant # type: ignore dict_spelling = enchant.Dict("en_US") - # Don't add ignore to the dictionary, since they will be suggested. for w in dict_custom: # Also, don't use `add(w)`, this will manipulate users personal dictionaries. diff --git a/check_source/check_unused_defines.py b/check_source/check_unused_defines.py index d815fd6..f7a7bed 100755 --- a/check_source/check_unused_defines.py +++ b/check_source/check_unused_defines.py @@ -33,22 +33,25 @@ defines = {} import re re_words = re.compile("[A-Za-z_][A-Za-z_0-9]*") -re_defines = re.compile("^\s*#define\s+([A-Za-z_][A-Za-z_0-9]*)", re.MULTILINE) +re_defines = re.compile("^\\s*#define\\s+([A-Za-z_][A-Za-z_0-9]*)", re.MULTILINE) # From # https://stackoverflow.com/a/18381470/432509 + + def remove_comments(string): pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)" # first group captures quoted strings (double or single) # second group captures comments (//single-line or /* multi-line */) - regex = re.compile(pattern, re.MULTILINE|re.DOTALL) + regex = re.compile(pattern, re.MULTILINE | re.DOTALL) + def _replacer(match): # if the 2nd group (capturing comments) is not None, # it means we have captured a non-quoted (real) comment string. if match.group(2) is not None: - return "" # so we will return empty to remove the comment + return "" # so we will return empty to remove the comment else: # otherwise, we will return the 1st group - return match.group(1) # capture + return match.group(1) # capture return regex.sub(_replacer, string) @@ -67,6 +70,7 @@ def extract_terms(fn, data_src): # Don't edit the file. return None + run( directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS], is_text=lambda fn: fn.endswith(SOURCE_EXT), diff --git a/modules/blendfile.py b/modules/blendfile.py index fc1fbc1..5842f2e 100644 --- a/modules/blendfile.py +++ b/modules/blendfile.py @@ -449,13 +449,14 @@ class BlendFileBlock: for index in range(dna_name.array_size): for f in struct.fields: yield from self.get_recursive_iter( - (index, f.dna_name.name_only), path_full, - default, None, use_nil, use_str, 0) + (index, f.dna_name.name_only), path_full, + default, None, use_nil, use_str, 0) else: for f in struct.fields: yield from self.get_recursive_iter( - f.dna_name.name_only, path_full, - default, None, use_nil, use_str, 0) + f.dna_name.name_only, path_full, + default, None, use_nil, use_str, 0) + def items_recursive_iter(self, use_nil=True): for k in self.keys(): yield from self.get_recursive_iter(k, use_nil=use_nil, use_str=False) diff --git a/utils/blender_keyconfig_export_permutations.py b/utils/blender_keyconfig_export_permutations.py index ae928d1..f199822 100755 --- a/utils/blender_keyconfig_export_permutations.py +++ b/utils/blender_keyconfig_export_permutations.py @@ -126,7 +126,7 @@ def permutation_as_filename(preset, values): return quote( preset + "_" + ".".join([ "-".join((str(key), str(val))) - for key, val in values + for key, val in values ]), # Needed so forward slashes aren't included in the resulting name. safe="", diff --git a/utils/blender_merge_format_changes.py b/utils/blender_merge_format_changes.py index 8813a32..b4a43b6 100755 --- a/utils/blender_merge_format_changes.py +++ b/utils/blender_merge_format_changes.py @@ -11,12 +11,14 @@ format_commits = ( 'e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1', '91a9cd0a94000047248598394c41ac30f893f147', '3076d95ba441cd32706a27d18922a30f8fd28b8a', - ) +) pre_format_commit = format_commits[0] + '~1' + def get_string(cmd): return subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf8').strip() + # Parse arguments. mode = None base_branch = 'master' @@ -73,7 +75,7 @@ if mode == 'rebase': mode_cmd = 'rebase' else: branch = get_string(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) - mode_cmd = 'merge --no-edit -m "Merge \'' + base_branch + '\' into \'' + branch + '\'"'; + mode_cmd = 'merge --no-edit -m "Merge \'' + base_branch + '\' into \'' + branch + '\'"' # Rebase up to the clang-format commit. code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD') diff --git a/utils/blender_theme_as_c.py b/utils/blender_theme_as_c.py index 32acb94..16a7c13 100755 --- a/utils/blender_theme_as_c.py +++ b/utils/blender_theme_as_c.py @@ -60,6 +60,7 @@ def repr_f32(f): return "%.*f" % (i, f_test) return f_str + import os # Avoid maintaining multiple blendfile modules diff --git a/utils/cycles_commits_sync.py b/utils/cycles_commits_sync.py index 12b08df..0a0e150 100755 --- a/utils/cycles_commits_sync.py +++ b/utils/cycles_commits_sync.py @@ -18,8 +18,8 @@ IGNORE_HASHES = { } # Start revisions from both repositories. -CYCLES_START_COMMIT = b"b941eccba81bbb1309a0eb4977fc3a77796f4ada" # blender-v2.92 -BLENDER_START_COMMIT = b"02948a2cab44f74ed101fc1b2ad9fe4431123e85" # v2.92 +CYCLES_START_COMMIT = b"b941eccba81bbb1309a0eb4977fc3a77796f4ada" # blender-v2.92 +BLENDER_START_COMMIT = b"02948a2cab44f74ed101fc1b2ad9fe4431123e85" # v2.92 # Prefix which is common for all the subjects. GIT_SUBJECT_COMMON_PREFIX = b"Subject: [PATCH] " diff --git a/utils/cycles_timeit.py b/utils/cycles_timeit.py index 660cae4..b16594e 100755 --- a/utils/cycles_timeit.py +++ b/utils/cycles_timeit.py @@ -126,7 +126,7 @@ def benchmarkFile(blender, blendfile, stats): re_path_tracing = re.compile(".*Path Tracing Tile ([0-9]+)/([0-9]+)$") re_total_render_time = re.compile(r".*Total render time: ([0-9]+(\.[0-9]+)?)") re_render_time_no_sync = re.compile( - ".*Render time \(without synchronization\): ([0-9]+(\.[0-9]+)?)") + ".*Render time \\(without synchronization\\): ([0-9]+(\\.[0-9]+)?)") re_pipeline_time = re.compile(r"Time: ([0-9:\.]+) \(Saving: ([0-9:\.]+)\)") # Prepare output folder. # TODO(sergey): Use some proper output folder. diff --git a/utils_maintenance/c_struct_clean.py b/utils_maintenance/c_struct_clean.py index 8098888..8e20adb 100755 --- a/utils_maintenance/c_struct_clean.py +++ b/utils_maintenance/c_struct_clean.py @@ -71,6 +71,7 @@ def clean_structs(fn: str, data_src: str) -> Optional[str]: return data_dst return None + run( directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS], is_text=lambda fn: fn.endswith(SOURCE_EXT), diff --git a/utils_maintenance/modules/batch_edit_text.py b/utils_maintenance/modules/batch_edit_text.py index cffaec8..c2760f6 100644 --- a/utils_maintenance/modules/batch_edit_text.py +++ b/utils_maintenance/modules/batch_edit_text.py @@ -15,6 +15,7 @@ TextOpFn = Callable[ Optional[str] ] + def operation_wrap(args: Tuple[str, TextOpFn]) -> None: fn, text_operation = args with open(fn, "r", encoding="utf-8") as f: @@ -27,7 +28,9 @@ def operation_wrap(args: Tuple[str, TextOpFn]) -> None: with open(fn, "w", encoding="utf-8") as f: f.write(data_dst) -def run(*, + +def run( + *, directories: Sequence[str], is_text: Callable[[str], bool], text_operation: TextOpFn, -- GitLab