Skip to content
Snippets Groups Projects
Commit 6e88fc5a authored by Campbell Barton's avatar Campbell Barton
Browse files

Cleanup: run autopep8

parent ca75cf51
No related branches found
No related tags found
No related merge requests found
...@@ -216,7 +216,6 @@ def cmake_get_src(f: str) -> None: ...@@ -216,7 +216,6 @@ def cmake_get_src(f: str) -> None:
f_rel_key = f_rel_key.replace(os.sep, "/") f_rel_key = f_rel_key.replace(os.sep, "/")
local_ignore_source_missing = global_ignore_source_missing.get(f_rel_key, []) local_ignore_source_missing = global_ignore_source_missing.get(f_rel_key, [])
for l, line_number in tokens: for l, line_number in tokens:
# Replace directories. # Replace directories.
l = l.replace("${CMAKE_SOURCE_DIR}", SOURCE_DIR) l = l.replace("${CMAKE_SOURCE_DIR}", SOURCE_DIR)
......
...@@ -73,11 +73,11 @@ files_ignore = { ...@@ -73,11 +73,11 @@ files_ignore = {
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Dictionary Utilities # Dictionary Utilities
def dictionary_create(): # type: ignore def dictionary_create(): # type: ignore
import enchant # type: ignore import enchant # type: ignore
dict_spelling = enchant.Dict("en_US") dict_spelling = enchant.Dict("en_US")
# Don't add ignore to the dictionary, since they will be suggested. # Don't add ignore to the dictionary, since they will be suggested.
for w in dict_custom: for w in dict_custom:
# Also, don't use `add(w)`, this will manipulate users personal dictionaries. # Also, don't use `add(w)`, this will manipulate users personal dictionaries.
......
...@@ -33,15 +33,18 @@ defines = {} ...@@ -33,15 +33,18 @@ defines = {}
import re import re
re_words = re.compile("[A-Za-z_][A-Za-z_0-9]*") 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 # From
# https://stackoverflow.com/a/18381470/432509 # https://stackoverflow.com/a/18381470/432509
def remove_comments(string): def remove_comments(string):
pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)" pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)"
# first group captures quoted strings (double or single) # first group captures quoted strings (double or single)
# second group captures comments (//single-line or /* multi-line */) # 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): def _replacer(match):
# if the 2nd group (capturing comments) is not None, # if the 2nd group (capturing comments) is not None,
# it means we have captured a non-quoted (real) comment string. # it means we have captured a non-quoted (real) comment string.
...@@ -67,6 +70,7 @@ def extract_terms(fn, data_src): ...@@ -67,6 +70,7 @@ def extract_terms(fn, data_src):
# Don't edit the file. # Don't edit the file.
return None return None
run( run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS], directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith(SOURCE_EXT), is_text=lambda fn: fn.endswith(SOURCE_EXT),
......
...@@ -456,6 +456,7 @@ class BlendFileBlock: ...@@ -456,6 +456,7 @@ class BlendFileBlock:
yield from self.get_recursive_iter( yield from self.get_recursive_iter(
f.dna_name.name_only, path_full, f.dna_name.name_only, path_full,
default, None, use_nil, use_str, 0) default, None, use_nil, use_str, 0)
def items_recursive_iter(self, use_nil=True): def items_recursive_iter(self, use_nil=True):
for k in self.keys(): for k in self.keys():
yield from self.get_recursive_iter(k, use_nil=use_nil, use_str=False) yield from self.get_recursive_iter(k, use_nil=use_nil, use_str=False)
......
...@@ -14,9 +14,11 @@ format_commits = ( ...@@ -14,9 +14,11 @@ format_commits = (
) )
pre_format_commit = format_commits[0] + '~1' pre_format_commit = format_commits[0] + '~1'
def get_string(cmd): def get_string(cmd):
return subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf8').strip() return subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf8').strip()
# Parse arguments. # Parse arguments.
mode = None mode = None
base_branch = 'master' base_branch = 'master'
...@@ -73,7 +75,7 @@ if mode == 'rebase': ...@@ -73,7 +75,7 @@ if mode == 'rebase':
mode_cmd = 'rebase' mode_cmd = 'rebase'
else: else:
branch = get_string(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) 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. # Rebase up to the clang-format commit.
code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD') code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD')
......
...@@ -60,6 +60,7 @@ def repr_f32(f): ...@@ -60,6 +60,7 @@ def repr_f32(f):
return "%.*f" % (i, f_test) return "%.*f" % (i, f_test)
return f_str return f_str
import os import os
# Avoid maintaining multiple blendfile modules # Avoid maintaining multiple blendfile modules
......
...@@ -126,7 +126,7 @@ def benchmarkFile(blender, blendfile, stats): ...@@ -126,7 +126,7 @@ def benchmarkFile(blender, blendfile, stats):
re_path_tracing = re.compile(".*Path Tracing Tile ([0-9]+)/([0-9]+)$") 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_total_render_time = re.compile(r".*Total render time: ([0-9]+(\.[0-9]+)?)")
re_render_time_no_sync = re.compile( 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:\.]+)\)") re_pipeline_time = re.compile(r"Time: ([0-9:\.]+) \(Saving: ([0-9:\.]+)\)")
# Prepare output folder. # Prepare output folder.
# TODO(sergey): Use some proper output folder. # TODO(sergey): Use some proper output folder.
......
...@@ -71,6 +71,7 @@ def clean_structs(fn: str, data_src: str) -> Optional[str]: ...@@ -71,6 +71,7 @@ def clean_structs(fn: str, data_src: str) -> Optional[str]:
return data_dst return data_dst
return None return None
run( run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS], directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith(SOURCE_EXT), is_text=lambda fn: fn.endswith(SOURCE_EXT),
......
...@@ -15,6 +15,7 @@ TextOpFn = Callable[ ...@@ -15,6 +15,7 @@ TextOpFn = Callable[
Optional[str] Optional[str]
] ]
def operation_wrap(args: Tuple[str, TextOpFn]) -> None: def operation_wrap(args: Tuple[str, TextOpFn]) -> None:
fn, text_operation = args fn, text_operation = args
with open(fn, "r", encoding="utf-8") as f: with open(fn, "r", encoding="utf-8") as f:
...@@ -27,7 +28,9 @@ def operation_wrap(args: Tuple[str, TextOpFn]) -> None: ...@@ -27,7 +28,9 @@ def operation_wrap(args: Tuple[str, TextOpFn]) -> None:
with open(fn, "w", encoding="utf-8") as f: with open(fn, "w", encoding="utf-8") as f:
f.write(data_dst) f.write(data_dst)
def run(*,
def run(
*,
directories: Sequence[str], directories: Sequence[str],
is_text: Callable[[str], bool], is_text: Callable[[str], bool],
text_operation: TextOpFn, text_operation: TextOpFn,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment