Cleanup: pep8

This commit is contained in:
Campbell Barton 2016-07-29 21:22:27 +10:00
parent 3d7cf808b8
commit ca983d1825
15 changed files with 110 additions and 94 deletions

View File

@ -26,7 +26,7 @@ __all__ = (
"disable",
"reset_all",
"module_bl_info",
)
)
import bpy as _bpy
_user_preferences = _bpy.context.user_preferences
@ -458,7 +458,7 @@ def module_bl_info(mod, info_basis=None):
"category": "",
"warning": "",
"show_expanded": False,
}
}
addon_info = getattr(mod, "bl_info", {})

View File

@ -31,7 +31,7 @@ __all__ = (
"props",
"types",
"utils",
)
)
# internal blender C module
@ -57,11 +57,11 @@ def main():
# fake module to allow:
# from bpy.types import Panel
sys.modules.update({
"bpy.app": app,
"bpy.app.handlers": app.handlers,
"bpy.app.translations": app.translations,
"bpy.types": types,
})
"bpy.app": app,
"bpy.app.handlers": app.handlers,
"bpy.app.translations": app.translations,
"bpy.types": types,
})
# Initializes Python classes.
# (good place to run a profiler or trace).

View File

@ -39,16 +39,16 @@ __all__ = (
"reduce_dirs",
"relpath",
"resolve_ncase",
)
)
import bpy as _bpy
import os as _os
from _bpy_path import (
extensions_audio,
extensions_movie,
extensions_image,
)
extensions_audio,
extensions_movie,
extensions_image,
)
def _getattr_bytes(var, attr):
@ -71,22 +71,22 @@ def abspath(path, start=None, library=None):
if path.startswith(b"//"):
if library:
start = _os.path.dirname(
abspath(_getattr_bytes(library, "filepath")))
abspath(_getattr_bytes(library, "filepath")))
return _os.path.join(
_os.path.dirname(_getattr_bytes(_bpy.data, "filepath"))
if start is None else start,
path[2:],
)
_os.path.dirname(_getattr_bytes(_bpy.data, "filepath"))
if start is None else start,
path[2:],
)
else:
if path.startswith("//"):
if library:
start = _os.path.dirname(
abspath(library.filepath))
abspath(library.filepath))
return _os.path.join(
_os.path.dirname(_bpy.data.filepath)
if start is None else start,
path[2:],
)
_os.path.dirname(_bpy.data.filepath)
if start is None else start,
path[2:],
)
return path
@ -175,7 +175,7 @@ def clean_name(name, replace="_"):
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
)
)
trans = str.maketrans({char: replace for char in bad_chars})
trans_cache[replace] = trans
return trans

View File

@ -28,14 +28,14 @@ KM_HIERARCHY = [
('Screen', 'EMPTY', 'WINDOW', [ # full screen, undo, screenshot
('Screen Editing', 'EMPTY', 'WINDOW', []), # re-sizing, action corners
('Header', 'EMPTY', 'WINDOW', []), # header stuff (per region)
]),
]),
('View2D', 'EMPTY', 'WINDOW', []), # view 2d navigation (per region)
('View2D Buttons List', 'EMPTY', 'WINDOW', []), # view 2d with buttons navigation
('User Interface', 'EMPTY', 'WINDOW', [
('Eyedropper Modal Map', 'EMPTY', 'WINDOW', []),
]),
]),
('3D View', 'VIEW_3D', 'WINDOW', [ # view 3d navigation and generic stuff (select, transform)
('Object Mode', 'EMPTY', 'WINDOW', []),
@ -71,18 +71,18 @@ KM_HIERARCHY = [
('View3D Dolly Modal', 'EMPTY', 'WINDOW', []),
('3D View Generic', 'VIEW_3D', 'WINDOW', []), # toolbar and properties
]),
]),
('Graph Editor', 'GRAPH_EDITOR', 'WINDOW', [
('Graph Editor Generic', 'GRAPH_EDITOR', 'WINDOW', []),
]),
]),
('Dopesheet', 'DOPESHEET_EDITOR', 'WINDOW', [
('Dopesheet Generic', 'DOPESHEET_EDITOR', 'WINDOW', []),
]),
]),
('NLA Editor', 'NLA_EDITOR', 'WINDOW', [
('NLA Channels', 'NLA_EDITOR', 'WINDOW', []),
('NLA Generic', 'NLA_EDITOR', 'WINDOW', []),
]),
]),
('Timeline', 'TIMELINE', 'WINDOW', []),
('Image', 'IMAGE_EDITOR', 'WINDOW', [
@ -90,23 +90,23 @@ KM_HIERARCHY = [
('Image Paint', 'EMPTY', 'WINDOW', []), # image and view3d
('UV Sculpt', 'EMPTY', 'WINDOW', []),
('Image Generic', 'IMAGE_EDITOR', 'WINDOW', []),
]),
]),
('Outliner', 'OUTLINER', 'WINDOW', []),
('Node Editor', 'NODE_EDITOR', 'WINDOW', [
('Node Generic', 'NODE_EDITOR', 'WINDOW', []),
]),
]),
('Sequencer', 'SEQUENCE_EDITOR', 'WINDOW', [
('SequencerCommon', 'SEQUENCE_EDITOR', 'WINDOW', []),
('SequencerPreview', 'SEQUENCE_EDITOR', 'WINDOW', []),
]),
]),
('Logic Editor', 'LOGIC_EDITOR', 'WINDOW', []),
('File Browser', 'FILE_BROWSER', 'WINDOW', [
('File Browser Main', 'FILE_BROWSER', 'WINDOW', []),
('File Browser Buttons', 'FILE_BROWSER', 'WINDOW', []),
]),
]),
('Info', 'INFO', 'WINDOW', []),
@ -114,17 +114,17 @@ KM_HIERARCHY = [
('Text', 'TEXT_EDITOR', 'WINDOW', [
('Text Generic', 'TEXT_EDITOR', 'WINDOW', []),
]),
]),
('Console', 'CONSOLE', 'WINDOW', []),
('Clip', 'CLIP_EDITOR', 'WINDOW', [
('Clip Editor', 'CLIP_EDITOR', 'WINDOW', []),
('Clip Graph Editor', 'CLIP_EDITOR', 'WINDOW', []),
('Clip Dopesheet Editor', 'CLIP_EDITOR', 'WINDOW', []),
]),
]),
('Grease Pencil', 'EMPTY', 'WINDOW', [ # grease pencil stuff (per region)
('Grease Pencil Stroke Edit Mode', 'EMPTY', 'WINDOW', []),
]),
]),
('Mask Editing', 'EMPTY', 'WINDOW', []),
('Frames', 'EMPTY', 'WINDOW', []), # frame navigation (per region)
('Markers', 'EMPTY', 'WINDOW', []), # markers (per region)
@ -138,7 +138,7 @@ KM_HIERARCHY = [
('Standard Modal Map', 'EMPTY', 'WINDOW', []),
('Transform Modal Map', 'EMPTY', 'WINDOW', []),
]
]
# -----------------------------------------------------------------------------
@ -239,7 +239,8 @@ def keyconfig_export(wm, kc, filepath):
" except Exception as e:\n"
" print(\"Warning: %r\" % e)\n\n")
f.write("wm = bpy.context.window_manager\n")
f.write("kc = wm.keyconfigs.new(os.path.splitext(os.path.basename(__file__))[0])\n\n") # keymap must be created by caller
# keymap must be created by caller
f.write("kc = wm.keyconfigs.new(os.path.splitext(os.path.basename(__file__))[0])\n\n")
# Generate a list of keymaps to export:
#
@ -267,7 +268,8 @@ def keyconfig_export(wm, kc, filepath):
km = km.active()
f.write("# Map %s\n" % km.name)
f.write("km = kc.keymaps.new('%s', space_type='%s', region_type='%s', modal=%s)\n\n" % (km.name, km.space_type, km.region_type, km.is_modal))
f.write("km = kc.keymaps.new('%s', space_type='%s', region_type='%s', modal=%s)\n\n" %
(km.name, km.space_type, km.region_type, km.is_modal))
for kmi in km.keymap_items:
f.write(_kmistr(kmi, km.is_modal))
f.write("\n")

View File

@ -23,7 +23,7 @@ __all__ = (
"region_2d_to_origin_3d",
"region_2d_to_location_3d",
"location_3d_to_region_2d",
)
)
def region_2d_to_vector_3d(region, rv3d, coord):
@ -50,7 +50,7 @@ def region_2d_to_vector_3d(region, rv3d, coord):
out = Vector(((2.0 * coord[0] / region.width) - 1.0,
(2.0 * coord[1] / region.height) - 1.0,
-0.5
))
))
w = out.dot(persinv[3].xyz) + persinv[3][3]

View File

@ -24,7 +24,7 @@ This module contains RestrictBlend context manager.
__all__ = (
"RestrictBlend",
)
)
import bpy as _bpy

View File

@ -39,7 +39,7 @@ class Context(StructRNA):
generic_attrs = (
*StructRNA.__dict__.keys(),
"bl_rna", "rna_type", "copy",
)
)
for attr in dir(self):
if not (attr.startswith("_") or attr in generic_attrs):
value = getattr(self, attr)
@ -542,6 +542,7 @@ class Sound(bpy_types.ID):
class RNAMeta(type):
def __new__(cls, name, bases, classdict, **args):
result = type.__new__(cls, name, bases, classdict)
if bases and bases[0] is not StructRNA:
@ -562,6 +563,7 @@ class RNAMeta(type):
class OrderedDictMini(dict):
def __init__(self, *args):
self.order = []
dict.__init__(self, args)
@ -581,6 +583,7 @@ class RNAMetaPropGroup(StructMetaPropGroup, RNAMeta):
class OrderedMeta(RNAMeta):
def __init__(cls, name, bases, attributes):
if attributes.__class__ is OrderedDictMini:
cls.order = attributes.order
@ -635,7 +638,7 @@ class Macro(StructRNA, metaclass=OrderedMeta):
class PropertyGroup(StructRNA, metaclass=RNAMetaPropGroup):
__slots__ = ()
__slots__ = ()
class RenderEngine(StructRNA, metaclass=RNAMeta):

View File

@ -112,10 +112,10 @@ def module_list(path):
folder_list = []
#folder_list = glob.glob(os.path.join(path,'*'))
folder_list = [
p for p in folder_list
if (os.path.exists(os.path.join(path, p, '__init__.py')) or
p[-3:] in {'.py', '.so'} or
p[-4:] in {'.pyc', '.pyo', '.pyd'})]
p for p in folder_list
if (os.path.exists(os.path.join(path, p, '__init__.py')) or
p[-3:] in {'.py', '.so'} or
p[-4:] in {'.pyc', '.pyo', '.pyd'})]
folder_list = [os.path.basename(p).split('.')[0] for p in folder_list]
return folder_list
@ -161,7 +161,7 @@ def complete(line):
if (not hasattr(m, '__file__')) or (not only_modules) or\
(hasattr(m, '__file__') and '__init__' in m.__file__):
completion_list = [attr for attr in dir(m)
if is_importable(m, attr)]
if is_importable(m, attr)]
else:
completion_list = []
completion_list.extend(getattr(m, '__all__', []))

View File

@ -85,7 +85,7 @@ def complete_indices(word, namespace, obj=None, base=None):
>>> complete_indices("foo['b", {'foo': {'bar':0, 1:2}}, base='foo')
["foo['bar']"]
"""
#FIXME: 'foo["b'
# FIXME: 'foo["b'
if base is None:
base = word
if obj is None:
@ -148,7 +148,7 @@ def complete(word, namespace, private=True):
if re_incomplete_index:
# ignore incomplete index at the end, e.g 'a[1' -> 'a'
matches = complete_indices(word, namespace,
base=re_incomplete_index.group(1))
base=re_incomplete_index.group(1))
elif not('[' in word):
matches = complete_names(word, namespace)

View File

@ -121,8 +121,8 @@ def expand(line, cursor, namespace, private=True):
"""
if line[:cursor].strip().endswith('('):
from . import complete_calltip
matches, word, scrollback = complete_calltip.complete(line,
cursor, namespace)
matches, word, scrollback = complete_calltip.complete(
line, cursor, namespace)
prefix = os.path.commonprefix(matches)[len(word):]
no_calltip = False
else:
@ -138,11 +138,11 @@ def expand(line, cursor, namespace, private=True):
white_space = " " + (" " * (cursor + len(prefix)))
word_prefix = word + prefix
scrollback = '\n'.join(
[white_space + m[len(word_prefix):]
if (word_prefix and m.startswith(word_prefix))
else
white_space + m.split('.')[-1]
for m in matches])
[white_space + m[len(word_prefix):]
if (word_prefix and m.startswith(word_prefix))
else
white_space + m.split('.')[-1]
for m in matches])
no_calltip = True

View File

@ -142,9 +142,9 @@ def execute(context, is_interactive):
# redirect output
from contextlib import (
redirect_stdout,
redirect_stderr,
)
redirect_stdout,
redirect_stderr,
)
# not included with Python
class redirect_stdin(redirect_stdout.__base__):
@ -152,8 +152,8 @@ def execute(context, is_interactive):
# don't allow the stdin to be used, can lock blender.
with redirect_stdout(stdout), \
redirect_stderr(stderr), \
redirect_stdin(None):
redirect_stderr(stderr), \
redirect_stdin(None):
# in case exception happens
line = "" # in case of encoding error
@ -258,10 +258,10 @@ def autocomplete(context):
# This function isn't aware of the text editor or being an operator
# just does the autocomplete then copy its results back
result = intellisense.expand(
line=line,
cursor=current_line.current_character,
namespace=console.locals,
private=bpy.app.debug_python)
line=line,
cursor=current_line.current_character,
namespace=console.locals,
private=bpy.app.debug_python)
line_new = result[0]
current_line.body, current_line.current_character, scrollback = result

View File

@ -92,7 +92,8 @@ class ProgressReport:
self.wm.progress_update(steps)
if msg:
prefix = " " * (len(self.steps) - 1)
print(prefix + "(%8.4f sec | %8.4f sec) %s\nProgress: %6.2f%%\r" % (tm, loc_tm, msg, steps_percent), end='')
print(prefix + "(%8.4f sec | %8.4f sec) %s\nProgress: %6.2f%%\r" %
(tm, loc_tm, msg, steps_percent), end='')
else:
print("Progress: %6.2f%%\r" % (steps_percent,), end='')

View File

@ -95,7 +95,7 @@ class InfoStructRNA:
"children",
"references",
"properties",
)
)
global_lookup = {}
@ -119,8 +119,10 @@ class InfoStructRNA:
def build(self):
rna_type = self.bl_rna
parent_id = self.identifier
self.properties[:] = [GetInfoPropertyRNA(rna_prop, parent_id) for rna_prop in get_direct_properties(rna_type) if rna_prop.identifier != "rna_type"]
self.functions[:] = [GetInfoFunctionRNA(rna_prop, parent_id) for rna_prop in get_direct_functions(rna_type)]
self.properties[:] = [GetInfoPropertyRNA(rna_prop, parent_id)
for rna_prop in get_direct_properties(rna_type) if rna_prop.identifier != "rna_type"]
self.functions[:] = [GetInfoFunctionRNA(rna_prop, parent_id)
for rna_prop in get_direct_functions(rna_type)]
def get_bases(self):
bases = []
@ -216,7 +218,7 @@ class InfoPropertyRNA:
"is_required",
"is_readonly",
"is_never_none",
)
)
global_lookup = {}
def __init__(self, rna_prop):
@ -362,7 +364,7 @@ class InfoFunctionRNA:
"args",
"return_values",
"is_classmethod",
)
)
global_lookup = {}
def __init__(self, rna_func):
@ -408,7 +410,7 @@ class InfoOperatorRNA:
"func_name",
"description",
"args",
)
)
global_lookup = {}
def __init__(self, rna_op):
@ -532,7 +534,7 @@ def BuildRNAInfo():
rna_struct = getattr(rna_type, "bl_rna", None)
if rna_struct:
#if not rna_type_name.startswith('__'):
# if not rna_type_name.startswith('__'):
identifier = rna_struct.identifier
@ -600,7 +602,8 @@ def BuildRNAInfo():
for rna_prop_ptr in (getattr(rna_prop, "fixed_type", None), getattr(rna_prop, "srna", None)):
# Does this property point to me?
if rna_prop_ptr:
rna_references_dict[rna_prop_ptr.identifier].append("%s.%s" % (rna_struct_path, rna_prop_identifier))
rna_references_dict[rna_prop_ptr.identifier].append(
"%s.%s" % (rna_struct_path, rna_prop_identifier))
for rna_func in get_direct_functions(rna_struct):
for rna_prop_identifier, rna_prop in rna_func.parameters.items():
@ -612,7 +615,8 @@ def BuildRNAInfo():
# Does this property point to me?
if rna_prop_ptr:
rna_references_dict[rna_prop_ptr.identifier].append("%s.%s" % (rna_struct_path, rna_func.identifier))
rna_references_dict[rna_prop_ptr.identifier].append(
"%s.%s" % (rna_struct_path, rna_func.identifier))
# Store nested children
nested = rna_struct.nested
@ -625,8 +629,8 @@ def BuildRNAInfo():
info_structs = []
for (rna_base, identifier, rna_struct) in structs:
#if rna_struct.nested:
# continue
# if rna_struct.nested:
# continue
#write_struct(rna_struct, '')
info_struct = GetInfoStructRNA(rna_struct)
@ -664,7 +668,8 @@ def BuildRNAInfo():
default = prop.default
if type(default) in {float, int}:
if default < prop.min or default > prop.max:
print("\t %s.%s, %s not in [%s - %s]" % (rna_info.identifier, prop.identifier, default, prop.min, prop.max))
print("\t %s.%s, %s not in [%s - %s]" %
(rna_info.identifier, prop.identifier, default, prop.min, prop.max))
# now for operators
op_mods = dir(bpy.ops)
@ -691,8 +696,8 @@ def BuildRNAInfo():
for rna_prop in rna_info.args:
rna_prop.build()
#for rna_info in InfoStructRNA.global_lookup.values():
# print(rna_info)
# for rna_info in InfoStructRNA.global_lookup.values():
# print(rna_info)
return InfoStructRNA.global_lookup, InfoFunctionRNA.global_lookup, InfoOperatorRNA.global_lookup, InfoPropertyRNA.global_lookup
@ -701,7 +706,7 @@ def main():
struct = rna_info.BuildRNAInfo()[0]
data = []
for struct_id, v in sorted(struct.items()):
struct_id_str = v.identifier #~ "".join(sid for sid in struct_id if struct_id)
struct_id_str = v.identifier # "".join(sid for sid in struct_id if struct_id)
for base in v.get_bases():
struct_id_str = base.identifier + "|" + struct_id_str
@ -714,7 +719,10 @@ def main():
if prop.array_length > 0:
prop_type += "[%d]" % prop.array_length
data.append("%s.%s -> %s: %s%s %s" % (struct_id_str, prop.identifier, prop.identifier, prop_type, ", (read-only)" if prop.is_readonly else "", prop.description))
data.append(
"%s.%s -> %s: %s%s %s" %
(struct_id_str, prop.identifier, prop.identifier, prop_type,
", (read-only)" if prop.is_readonly else "", prop.description))
data.sort()
if bpy.app.background:

View File

@ -90,7 +90,7 @@ def rna2xml(fw=print_ln,
bpy.types.PoseBone,
bpy.types.Node,
bpy.types.Sequence,
)
)
def number_to_str(val, val_type):
if val_type == int:
@ -276,7 +276,8 @@ def xml2rna(root_xml,
if value_xml.startswith("#"):
# read hexidecimal value as float array
value_xml_split = value_xml[1:]
value_xml_coerce = [int(value_xml_split[i:i + 2], 16) / 255 for i in range(0, len(value_xml_split), 2)]
value_xml_coerce = [int(value_xml_split[i:i + 2], 16) /
255 for i in range(0, len(value_xml_split), 2)]
del value_xml_split
else:
value_xml_split = value_xml.split()

View File

@ -53,7 +53,8 @@ def write_sysinfo(filepath):
# build info
output.write(title("Blender"))
output.write("version: %s, branch: %s, commit date: %s %s, hash: %s, type: %s\n" %
output.write(
"version: %s, branch: %s, commit date: %s %s, hash: %s, type: %s\n" %
(bpy.app.version_string,
prepr(bpy.app.build_branch),
prepr(bpy.app.build_commit_date),
@ -81,9 +82,9 @@ def write_sysinfo(filepath):
output.write("binary path: %s\n" % prepr(bpy.app.binary_path_python))
try:
py_ver = prepr(subprocess.check_output([
bpy.app.binary_path_python,
"--version",
]).strip())
bpy.app.binary_path_python,
"--version",
]).strip())
except Exception as e:
py_ver = str(e)
output.write("version: %s\n" % py_ver)
@ -105,8 +106,9 @@ def write_sysinfo(filepath):
ffmpeg = bpy.app.ffmpeg
if ffmpeg.supported:
for lib in ("avcodec", "avdevice", "avformat", "avutil", "swscale"):
output.write("%s:%s%r\n" % (lib, " " * (10 - len(lib)),
getattr(ffmpeg, lib + "_version_string")))
output.write(
"%s:%s%r\n" % (lib, " " * (10 - len(lib)),
getattr(ffmpeg, lib + "_version_string")))
else:
output.write("Blender was built without FFmpeg support\n")
@ -205,4 +207,3 @@ def write_sysinfo(filepath):
output.write(cycles.engine.system_info())
output.close()