script for automating pep8 checks.

On ubuntu/debian install these tools...

   sudo apt-get install pylint pyflakes python-setuptools python-pip
   sudo pip install pep8

then run from blenders source dir...
   python release/test/pep8.py

This searches for the comments "# <pep8 compliant>" and "# <pep8-80 compliant>", running the checking tools on these scripts only.

* some minor pep8 corrections too.
This commit is contained in:
Campbell Barton 2009-12-13 13:59:16 +00:00
parent c1bfd014bd
commit a1656300ba
20 changed files with 230 additions and 116 deletions

View File

@ -36,6 +36,7 @@ ops = _ops_module.ops_fake_module
import sys import sys
DEBUG = ("-d" in sys.argv) DEBUG = ("-d" in sys.argv)
def load_scripts(reload_scripts=False): def load_scripts(reload_scripts=False):
import os import os
import traceback import traceback
@ -47,7 +48,7 @@ def load_scripts(reload_scripts=False):
def test_import(module_name): def test_import(module_name):
try: try:
t = time.time() t = time.time()
ret= __import__(module_name) ret = __import__(module_name)
if DEBUG: if DEBUG:
print("time %s %.4f" % (module_name, time.time() - t)) print("time %s %.4f" % (module_name, time.time() - t))
return ret return ret
@ -78,6 +79,7 @@ def load_scripts(reload_scripts=False):
if DEBUG: if DEBUG:
print("Time %.4f" % (time.time() - t_main)) print("Time %.4f" % (time.time() - t_main))
def _main(): def _main():
# a bit nasty but this prevents help() and input() from locking blender # a bit nasty but this prevents help() and input() from locking blender
@ -99,5 +101,3 @@ def _main():
load_scripts() load_scripts()
_main() _main()

View File

@ -134,7 +134,6 @@ class bpy_ops_submodule_op(object):
__keys__ = ('module', 'func') __keys__ = ('module', 'func')
def _get_doc(self): def _get_doc(self):
return op_as_string(self.idname()) return op_as_string(self.idname())

View File

@ -21,6 +21,7 @@
import bpy import bpy
import os import os
def expandpath(path): def expandpath(path):
if path.startswith("//"): if path.startswith("//"):
return os.path.join(os.path.dirname(bpy.data.filename), path[2:]) return os.path.join(os.path.dirname(bpy.data.filename), path[2:])
@ -44,15 +45,17 @@ _unclean_chars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, \
_unclean_chars = ''.join([chr(i) for i in _unclean_chars]) _unclean_chars = ''.join([chr(i) for i in _unclean_chars])
def clean_name(name, replace="_"): def clean_name(name, replace="_"):
''' '''
All characters besides A-Z/a-z, 0-9 are replaced with "_" All characters besides A-Z/a-z, 0-9 are replaced with "_"
or the replace argumet if defined. or the replace argumet if defined.
''' '''
for ch in _unclean_chars: for ch in _unclean_chars:
name = name.replace(ch, replace) name = name.replace(ch, replace)
return name return name
def display_name(name): def display_name(name):
''' '''
Only capitalize all lowercase names, mixed case use them as is. Only capitalize all lowercase names, mixed case use them as is.
@ -75,6 +78,7 @@ def display_name(name):
_scripts = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir) _scripts = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
_scripts = (os.path.normpath(_scripts), ) _scripts = (os.path.normpath(_scripts), )
def script_paths(*args): def script_paths(*args):
scripts = list(_scripts) scripts = list(_scripts)
@ -105,6 +109,7 @@ def script_paths(*args):
_presets = os.path.join(_scripts[0], "presets") # FIXME - multiple paths _presets = os.path.join(_scripts[0], "presets") # FIXME - multiple paths
def preset_paths(subdir): def preset_paths(subdir):
''' '''
Returns a list of paths for a spesific preset. Returns a list of paths for a spesific preset.

View File

@ -25,14 +25,18 @@ from Mathutils import Vector
from rna_prop_ui import rna_idprop_ui_prop_get from rna_prop_ui import rna_idprop_ui_prop_get
SPECIAL_TYPES = "root", SPECIAL_TYPES = "root",
class RigifyError(Exception): class RigifyError(Exception):
"""Exception raised for errors in the metarig. """Exception raised for errors in the metarig.
""" """
def __init__(self, message): def __init__(self, message):
self.message = message self.message = message
def __str__(self): def __str__(self):
return repr(self.message) return repr(self.message)
def submodule_func_from_type(bone_type): def submodule_func_from_type(bone_type):
type_pair = bone_type.split(".") type_pair = bone_type.split(".")
@ -48,7 +52,7 @@ def submodule_func_from_type(bone_type):
submod = __import__(name="%s.%s" % (__package__, type_name), fromlist=[type_name]) submod = __import__(name="%s.%s" % (__package__, type_name), fromlist=[type_name])
except ImportError: except ImportError:
raise RigifyError("python module for type '%s' not found" % type_name) raise RigifyError("python module for type '%s' not found" % type_name)
reload(submod) reload(submod)
return type_name, submod, getattr(submod, func_name) return type_name, submod, getattr(submod, func_name)
@ -60,9 +64,10 @@ def get_submodule_types():
for f in files: for f in files:
if not f.startswith("_") and f.endswith(".py"): if not f.startswith("_") and f.endswith(".py"):
submodules.append(f[:-3]) submodules.append(f[:-3])
return sorted(submodules) return sorted(submodules)
def get_bone_type_options(pbone, type_name): def get_bone_type_options(pbone, type_name):
options = {} options = {}
bone_name = pbone.name bone_name = pbone.name
@ -75,13 +80,14 @@ def get_bone_type_options(pbone, type_name):
return options return options
def validate_rig(context, obj): def validate_rig(context, obj):
''' '''
Makes no changes Makes no changes
only runs the metarig definitions and reports errors only runs the metarig definitions and reports errors
''' '''
type_found = False type_found = False
for pbone in obj.pose.bones: for pbone in obj.pose.bones:
bone_name = pbone.name bone_name = pbone.name
bone_type = pbone.get("type", "") bone_type = pbone.get("type", "")
@ -103,19 +109,19 @@ def validate_rig(context, obj):
get_bone_type_options(pbone, bone_type) get_bone_type_options(pbone, bone_type)
# missing, - check for duplicate root bone. # missing, - check for duplicate root bone.
if not type_found: if not type_found:
raise RigifyError("This rig has no 'type' properties defined on any pose bones, nothing to do") raise RigifyError("This rig has no 'type' properties defined on any pose bones, nothing to do")
def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
''' '''
Main function for generating Main function for generating
''' '''
from collections import OrderedDict from collections import OrderedDict
import rigify_utils import rigify_utils
reload(rigify_utils) reload(rigify_utils)
# Not needed but catches any errors before duplicating # Not needed but catches any errors before duplicating
validate_rig(context, obj_orig) validate_rig(context, obj_orig)
@ -124,8 +130,8 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
mode_orig = context.mode mode_orig = context.mode
rest_backup = obj_orig.data.pose_position rest_backup = obj_orig.data.pose_position
obj_orig.data.pose_position = 'REST' obj_orig.data.pose_position = 'REST'
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
scene = context.scene scene = context.scene
@ -147,7 +153,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
# original name mapping # original name mapping
base_names = {} base_names = {}
# add all new parentless children to this bone # add all new parentless children to this bone
root_bone = None root_bone = None
@ -168,7 +174,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
# value: [functions, ...] # value: [functions, ...]
# each function is from the module. eg leg.ik, arm.main # each function is from the module. eg leg.ik, arm.main
bone_typeinfos = {} bone_typeinfos = {}
# key: bone name # key: bone name
# value: [new_bone_name, ...] # value: [new_bone_name, ...]
# where each bone with a 'type' stores a list of bones that it created # where each bone with a 'type' stores a list of bones that it created
@ -182,12 +188,12 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
bone_type = pbone.get("type", "") bone_type = pbone.get("type", "")
if bone_type: if bone_type:
bone_type_list = [bt for bt in bone_type.replace(",", " ").split()] bone_type_list = [bt for bt in bone_type.replace(",", " ").split()]
# not essential but means running autorig again wont do anything # not essential but means running autorig again wont do anything
del pbone["type"] del pbone["type"]
else: else:
bone_type_list = [] bone_type_list = []
if bone_type_list == ["root"]: # special case! if bone_type_list == ["root"]: # special case!
if root_bone: if root_bone:
raise Exception("cant have more then 1 root bone, found '%s' and '%s' to have type==root" % (root_bone, bone_name)) raise Exception("cant have more then 1 root bone, found '%s' and '%s' to have type==root" % (root_bone, bone_name))
@ -197,7 +203,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
for bone_type in bone_type_list: for bone_type in bone_type_list:
type_name, submod, type_func = submodule_func_from_type(bone_type) type_name, submod, type_func = submodule_func_from_type(bone_type)
reload(submod) reload(submod)
bone_def_dict = bone_definitions.setdefault(bone_name, {}) bone_def_dict = bone_definitions.setdefault(bone_name, {})
# Only calculate bone definitions once # Only calculate bone definitions once
@ -226,7 +232,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
# Only blend results from the same submodule, eg. # Only blend results from the same submodule, eg.
# leg.ik and arm.fk could not be blended. # leg.ik and arm.fk could not be blended.
results = OrderedDict() results = OrderedDict()
bone_names_pre = set([bone.name for bone in arm.bones]) bone_names_pre = set([bone.name for bone in arm.bones])
for type_name, type_func in bone_typeinfos[bone_name]: for type_name, type_func in bone_typeinfos[bone_name]:
@ -255,21 +261,21 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
bone_names_post = set([bone.name for bone in arm.bones]) bone_names_post = set([bone.name for bone in arm.bones])
# Store which bones were created from this one # Store which bones were created from this one
bone_genesis[bone_name] = list(bone_names_post - bone_names_pre) bone_genesis[bone_name] = list(bone_names_post - bone_names_pre)
# need a reverse lookup on bone_genesis so as to know immediately # need a reverse lookup on bone_genesis so as to know immediately
# where a bone comes from # where a bone comes from
bone_genesis_reverse = {} bone_genesis_reverse = {}
for bone_name, bone_children in bone_genesis.items(): for bone_name, bone_children in bone_genesis.items():
for bone_child_name in bone_children: for bone_child_name in bone_children:
bone_genesis_reverse[bone_child_name] = bone_name bone_genesis_reverse[bone_child_name] = bone_name
if root_bone: if root_bone:
# assign all new parentless bones to this # assign all new parentless bones to this
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
root_ebone = arm.edit_bones[root_bone] root_ebone = arm.edit_bones[root_bone]
for ebone in arm.edit_bones: for ebone in arm.edit_bones:
@ -284,19 +290,19 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
root_ebone_tmp = arm.edit_bones[root_bone_override] root_ebone_tmp = arm.edit_bones[root_bone_override]
else: else:
root_ebone_tmp = root_ebone root_ebone_tmp = root_ebone
ebone.connected = False ebone.connected = False
ebone.parent = root_ebone_tmp ebone.parent = root_ebone_tmp
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
if META_DEF: if META_DEF:
# for pbone in obj_def.pose.bones: # for pbone in obj_def.pose.bones:
for bone_name, bone_name_new in base_names.items(): for bone_name, bone_name_new in base_names.items():
#pbone_from = bone_name #pbone_from = bone_name
pbone = obj_def.pose.bones[bone_name_new] pbone = obj_def.pose.bones[bone_name_new]
con = pbone.constraints.new('COPY_ROTATION') con = pbone.constraints.new('COPY_ROTATION')
con.target = obj con.target = obj
con.subtarget = bone_name con.subtarget = bone_name
@ -318,8 +324,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
obj_orig.data.pose_position = rest_backup obj_orig.data.pose_position = rest_backup
obj.data.pose_position = 'POSE' obj.data.pose_position = 'POSE'
context.user_preferences.edit.global_undo = global_undo context.user_preferences.edit.global_undo = global_undo
return obj return obj
@ -344,9 +349,9 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True):
continue continue
# XXX workaround!, problem with updating the pose matrix. # XXX workaround!, problem with updating the pose matrix.
if module_name=="delta": if module_name == "delta":
continue continue
type_name, submodule, func = submodule_func_from_type(module_name) type_name, submodule, func = submodule_func_from_type(module_name)
metarig_template = getattr(submodule, "metarig_template", None) metarig_template = getattr(submodule, "metarig_template", None)
@ -356,7 +361,7 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True):
metarig_template() metarig_template()
obj = context.active_object obj = context.active_object
obj.location = scene.cursor_location obj.location = scene.cursor_location
if GENERATE_FINAL: if GENERATE_FINAL:
obj_new = generate_rig(context, obj) obj_new = generate_rig(context, obj)
new_objects.append((obj, obj_new)) new_objects.append((obj, obj_new))
@ -378,7 +383,7 @@ def generate_test_all(context, GRAPH=False):
reload(graphviz_export) reload(graphviz_export)
new_objects = rigify.generate_test(context) new_objects = rigify.generate_test(context)
if GRAPH: if GRAPH:
base_name = os.path.splitext(bpy.data.filename)[0] base_name = os.path.splitext(bpy.data.filename)[0]
for obj, obj_new in new_objects: for obj, obj_new in new_objects:

View File

@ -96,14 +96,14 @@ def metarig_definition(obj, orig_bone_name):
def ik(obj, definitions, base_names, options): def ik(obj, definitions, base_names, options):
arm = obj.data arm = obj.data
mt = bone_class_instance(obj, METARIG_NAMES) mt = bone_class_instance(obj, METARIG_NAMES)
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
mt.update() mt.update()
ik = bone_class_instance(obj, ["pole", "pole_vis", "hand_vis"]) ik = bone_class_instance(obj, ["pole", "pole_vis", "hand_vis"])
ik_chain = mt.copy(to_fmt="MCH-%s_ik", base_names=base_names, exclude_attrs=["shoulder"]) ik_chain = mt.copy(to_fmt="MCH-%s_ik", base_names=base_names, exclude_attrs=["shoulder"])
# IK needs no parent_index # IK needs no parent_index
ik_chain.hand_e.connected = False ik_chain.hand_e.connected = False
ik_chain.hand_e.parent = None ik_chain.hand_e.parent = None
@ -112,14 +112,14 @@ def ik(obj, definitions, base_names, options):
ik_chain.arm_e.connected = False ik_chain.arm_e.connected = False
ik_chain.arm_e.parent = mt.shoulder_e ik_chain.arm_e.parent = mt.shoulder_e
# Add the bone used for the arms poll target # Add the bone used for the arms poll target
#ik.pole = add_pole_target_bone(obj, mt.forearm, get_base_name(base_names[mt.forearm]) + "_target" + get_side_name(mt.forearm), mode='ZAVERAGE') #ik.pole = add_pole_target_bone(obj, mt.forearm, get_base_name(base_names[mt.forearm]) + "_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
ik.pole = add_pole_target_bone(obj, mt.forearm, "elbow_target" + get_side_name(mt.forearm), mode='ZAVERAGE') ik.pole = add_pole_target_bone(obj, mt.forearm, "elbow_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
ik.update() ik.update()
ik.pole_e.local_location = False ik.pole_e.local_location = False
# option: elbow_parent # option: elbow_parent
elbow_parent_name = options.get("elbow_parent", "") elbow_parent_name = options.get("elbow_parent", "")
@ -130,17 +130,17 @@ def ik(obj, definitions, base_names, options):
# TODO, old/new parent mapping # TODO, old/new parent mapping
raise RigifyError("parent bone from property 'arm_biped_generic.elbow_parent' not found '%s'" % elbow_parent_name) raise RigifyError("parent bone from property 'arm_biped_generic.elbow_parent' not found '%s'" % elbow_parent_name)
ik.pole_e.parent = elbow_parent_e ik.pole_e.parent = elbow_parent_e
# update bones after this! # update bones after this!
ik.hand_vis = add_stretch_to(obj, mt.hand, ik_chain.hand, "VIS-%s_ik" % base_names[mt.hand]) ik.hand_vis = add_stretch_to(obj, mt.hand, ik_chain.hand, "VIS-%s_ik" % base_names[mt.hand])
ik.pole_vis = add_stretch_to(obj, mt.forearm, ik.pole, "VIS-%s_ik" % base_names[mt.forearm]) ik.pole_vis = add_stretch_to(obj, mt.forearm, ik.pole, "VIS-%s_ik" % base_names[mt.forearm])
ik.update() ik.update()
ik.hand_vis_e.restrict_select = True ik.hand_vis_e.restrict_select = True
ik.pole_vis_e.restrict_select = True ik.pole_vis_e.restrict_select = True
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
mt.update() mt.update()
ik.update() ik.update()
ik_chain.update() ik_chain.update()
@ -171,15 +171,15 @@ def ik(obj, definitions, base_names, options):
prop["soft_max"] = 1.0 prop["soft_max"] = 1.0
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
# don't blend the shoulder # don't blend the shoulder
return [None] + ik_chain.names() return [None] + ik_chain.names()
def fk(obj, definitions, base_names, options): def fk(obj, definitions, base_names, options):
arm = obj.data arm = obj.data
mt = bone_class_instance(obj, METARIG_NAMES) mt = bone_class_instance(obj, METARIG_NAMES)
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
mt.update() mt.update()
@ -197,19 +197,19 @@ def fk(obj, definitions, base_names, options):
ex.socket_e.connected = False ex.socket_e.connected = False
ex.socket_e.parent = mt.shoulder_e ex.socket_e.parent = mt.shoulder_e
ex.socket_e.length *= 0.5 ex.socket_e.length *= 0.5
# insert the 'DLT-hand', between the forearm and the hand # insert the 'DLT-hand', between the forearm and the hand
# copies forarm rotation # copies forarm rotation
ex.hand_delta_e = copy_bone_simple(arm, fk_chain.hand, "DLT-%s" % base_names[mt.hand], parent=True) ex.hand_delta_e = copy_bone_simple(arm, fk_chain.hand, "DLT-%s" % base_names[mt.hand], parent=True)
ex.hand_delta = ex.hand_delta_e.name ex.hand_delta = ex.hand_delta_e.name
ex.hand_delta_e.length *= 0.5 ex.hand_delta_e.length *= 0.5
ex.hand_delta_e.connected = False ex.hand_delta_e.connected = False
fk_chain.hand_e.connected = False fk_chain.hand_e.connected = False
fk_chain.hand_e.parent = ex.hand_delta_e fk_chain.hand_e.parent = ex.hand_delta_e
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
mt.update() mt.update()
ex.update() ex.update()
fk_chain.update() fk_chain.update()
@ -222,7 +222,7 @@ def fk(obj, definitions, base_names, options):
con = fk_chain.arm_p.constraints.new('COPY_LOCATION') con = fk_chain.arm_p.constraints.new('COPY_LOCATION')
con.target = obj con.target = obj
con.subtarget = ex.socket con.subtarget = ex.socket
fk_chain.hand_p.lock_location = True, True, True fk_chain.hand_p.lock_location = True, True, True
con = ex.hand_delta_p.constraints.new('COPY_ROTATION') con = ex.hand_delta_p.constraints.new('COPY_ROTATION')
con.target = obj con.target = obj
@ -262,13 +262,13 @@ def fk(obj, definitions, base_names, options):
mod.coefficients[1] = -1.0 mod.coefficients[1] = -1.0
hinge_setup() hinge_setup()
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
def main(obj, bone_definition, base_names, options): def main(obj, bone_definition, base_names, options):
bones_ik = ik(obj, bone_definition, base_names, options) bones_ik = ik(obj, bone_definition, base_names, options)
bones_fk = fk(obj, bone_definition, base_names, options) bones_fk = fk(obj, bone_definition, base_names, options)

View File

@ -24,7 +24,7 @@ from rna_prop_ui import rna_idprop_ui_prop_get
METARIG_NAMES = ("cpy",) METARIG_NAMES = ("cpy",)
# note, this example is just a bone with copy property.
def metarig_template(): def metarig_template():
# generated by rigify.write_meta_rig # generated by rigify.write_meta_rig
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
@ -40,6 +40,7 @@ def metarig_template():
pbone = obj.pose.bones['Bone'] pbone = obj.pose.bones['Bone']
pbone['type'] = 'copy' pbone['type'] = 'copy'
def metarig_definition(obj, orig_bone_name): def metarig_definition(obj, orig_bone_name):
return [orig_bone_name] return [orig_bone_name]
@ -51,14 +52,14 @@ def main(obj, bone_definition, base_names, options):
mt.update() mt.update()
cp = mt.copy(to_fmt="%s_cpy") cp = mt.copy(to_fmt="%s_cpy")
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
cp.update() cp.update()
mt.update() mt.update()
con = cp.cpy_p.constraints.new('COPY_ROTATION') con = cp.cpy_p.constraints.new('COPY_ROTATION')
con.target = obj con.target = obj
con.subtarget = mt.cpy con.subtarget = mt.cpy
con = cp.cpy_p.constraints.new('COPY_LOCATION') con = cp.cpy_p.constraints.new('COPY_LOCATION')
con.target = obj con.target = obj
con.subtarget = mt.cpy con.subtarget = mt.cpy

View File

@ -118,7 +118,6 @@ def main(obj, bone_definition, base_names, options):
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
# Move the child bone to the deltas location # Move the child bone to the deltas location
obj.animation_data_create() obj.animation_data_create()
delta_pbone = obj.pose.bones[delta_name] delta_pbone = obj.pose.bones[delta_name]

View File

@ -106,7 +106,7 @@ def metarig_definition(obj, orig_bone_name):
children = bone.children children = bone.children
# Now there must be 2 children, only one connected # Now there must be 2 children, only one connected
if len(children) != 2: if len(children) != 2:
raise RigifyError("expected the foot bone:'%s' to have 2 children" % bone.name ) raise RigifyError("expected the foot bone:'%s' to have 2 children" % bone.name)
if children[0].connected == children[1].connected: if children[0].connected == children[1].connected:
raise RigifyError("expected one bone to be connected") raise RigifyError("expected one bone to be connected")

View File

@ -154,8 +154,8 @@ def main(obj, bone_definition, base_names, options):
ex.neck_socket_e.head = mt.head_e.head ex.neck_socket_e.head = mt.head_e.head
ex.neck_socket_e.tail = mt.head_e.head - Vector(0.0, neck_chain_segment_length / 2.0, 0.0) ex.neck_socket_e.tail = mt.head_e.head - Vector(0.0, neck_chain_segment_length / 2.0, 0.0)
ex.neck_socket_e.roll = 0.0 ex.neck_socket_e.roll = 0.0
# copy of the head for controling # copy of the head for controling
ex.head_ctrl_e = copy_bone_simple(arm, mt.head, base_names[mt.head]) ex.head_ctrl_e = copy_bone_simple(arm, mt.head, base_names[mt.head])
ex.head_ctrl = ex.head_ctrl_e.name ex.head_ctrl = ex.head_ctrl_e.name
@ -229,7 +229,7 @@ def main(obj, bone_definition, base_names, options):
head_driver_path = ex.head_ctrl_p.path_to_id() head_driver_path = ex.head_ctrl_p.path_to_id()
target_names = [("b%.2d" % (i + 1)) for i in range(len(neck_chain))] target_names = [("b%.2d" % (i + 1)) for i in range(len(neck_chain))]
ex.head_ctrl_p["bend_tot"] = 0.0 ex.head_ctrl_p["bend_tot"] = 0.0
fcurve = ex.head_ctrl_p.driver_add('["bend_tot"]', 0) fcurve = ex.head_ctrl_p.driver_add('["bend_tot"]', 0)
driver = fcurve.driver driver = fcurve.driver
@ -242,7 +242,7 @@ def main(obj, bone_definition, base_names, options):
tar.id_type = 'OBJECT' tar.id_type = 'OBJECT'
tar.id = obj tar.id = obj
tar.data_path = head_driver_path + ('["bend_%.2d"]' % (i + 1)) tar.data_path = head_driver_path + ('["bend_%.2d"]' % (i + 1))
for i, attr in enumerate(ex_chain.attr_names): for i, attr in enumerate(ex_chain.attr_names):
neck_p = getattr(ex_chain, attr + "_p") neck_p = getattr(ex_chain, attr + "_p")
@ -272,9 +272,9 @@ def main(obj, bone_definition, base_names, options):
driver = fcurve.driver driver = fcurve.driver
driver.type = 'SCRIPTED' driver.type = 'SCRIPTED'
driver.expression = "bend/bend_tot" driver.expression = "bend/bend_tot"
fcurve.modifiers.remove(0) # grr dont need a modifier fcurve.modifiers.remove(0) # grr dont need a modifier
# add target # add target
tar = driver.targets.new() tar = driver.targets.new()
@ -282,14 +282,14 @@ def main(obj, bone_definition, base_names, options):
tar.id_type = 'OBJECT' tar.id_type = 'OBJECT'
tar.id = obj tar.id = obj
tar.data_path = head_driver_path + ('["bend_tot"]') tar.data_path = head_driver_path + ('["bend_tot"]')
tar = driver.targets.new() tar = driver.targets.new()
tar.name = "bend" tar.name = "bend"
tar.id_type = 'OBJECT' tar.id_type = 'OBJECT'
tar.id = obj tar.id = obj
tar.data_path = head_driver_path + ('["%s"]' % prop_name) tar.data_path = head_driver_path + ('["%s"]' % prop_name)
# finally constrain the original bone to this one # finally constrain the original bone to this one
orig_neck_p = getattr(mt_chain, attr + "_p") orig_neck_p = getattr(mt_chain, attr + "_p")
con = orig_neck_p.constraints.new('COPY_ROTATION') con = orig_neck_p.constraints.new('COPY_ROTATION')

View File

@ -25,6 +25,7 @@ from rna_prop_ui import rna_idprop_ui_prop_get
# not used, defined for completeness # not used, defined for completeness
METARIG_NAMES = tuple() METARIG_NAMES = tuple()
def metarig_template(): def metarig_template():
# generated by rigify.write_meta_rig # generated by rigify.write_meta_rig
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')

View File

@ -177,7 +177,7 @@ def main(obj, bone_definition, base_names, options):
df.ribcage_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % base_names[mt.ribcage]) df.ribcage_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % base_names[mt.ribcage])
df.ribcage = df.ribcage_e.name df.ribcage = df.ribcage_e.name
df.ribcage_e.translate(Vector(spine_chain_segment_length * 2.0, - df.ribcage_e.length / 2.0, 0.0)) df.ribcage_e.translate(Vector(spine_chain_segment_length * 2.0, - df.ribcage_e.length / 2.0, 0.0))
ex.ribcage_copy_e = copy_bone_simple(arm, mt.ribcage, base_names[mt.ribcage]) ex.ribcage_copy_e = copy_bone_simple(arm, mt.ribcage, base_names[mt.ribcage])
ex.ribcage_copy = ex.ribcage_copy_e.name ex.ribcage_copy = ex.ribcage_copy_e.name
ex.ribcage_copy_e.connected = False ex.ribcage_copy_e.connected = False
@ -294,7 +294,7 @@ def main(obj, bone_definition, base_names, options):
# df.ribcage_p / DEF-wgt_rib_cage # df.ribcage_p / DEF-wgt_rib_cage
df.ribcage_p.lock_location = True, True, True df.ribcage_p.lock_location = True, True, True
con = df.ribcage_p.constraints.new('COPY_ROTATION') con = df.ribcage_p.constraints.new('COPY_ROTATION')
con.target = obj con.target = obj
con.subtarget = ex.ribcage con.subtarget = ex.ribcage

View File

@ -32,6 +32,7 @@ from rna_prop_ui import rna_idprop_ui_prop_get
DELIMITER = '-._' DELIMITER = '-._'
EMPTY_LAYER = [False] * 32 EMPTY_LAYER = [False] * 32
def add_stretch_to(obj, from_name, to_name, name): def add_stretch_to(obj, from_name, to_name, name):
''' '''
Adds a bone that stretches from one to another Adds a bone that stretches from one to another
@ -71,7 +72,7 @@ def add_stretch_to(obj, from_name, to_name, name):
con.volume = 'NO_VOLUME' con.volume = 'NO_VOLUME'
bpy.ops.object.mode_set(mode=mode_orig) bpy.ops.object.mode_set(mode=mode_orig)
return stretch_name return stretch_name
@ -216,7 +217,7 @@ def add_pole_target_bone(obj, base_bone_name, name, mode='CROSS'):
parent_dir = parent_head - parent_tail parent_dir = parent_head - parent_tail
distance = (base_dir.length + parent_dir.length) distance = (base_dir.length + parent_dir.length)
if mode == 'CROSS': if mode == 'CROSS':
# direction from the angle of the joint # direction from the angle of the joint
offset = base_dir.copy().normalize() - parent_dir.copy().normalize() offset = base_dir.copy().normalize() - parent_dir.copy().normalize()
@ -244,7 +245,6 @@ def add_pole_target_bone(obj, base_bone_name, name, mode='CROSS'):
return poll_name return poll_name
def get_side_name(name): def get_side_name(name):
''' '''
Returns the last part of a string (typically a bone's name) indicating Returns the last part of a string (typically a bone's name) indicating
@ -256,6 +256,7 @@ def get_side_name(name):
else: else:
return "" return ""
def get_base_name(name): def get_base_name(name):
''' '''
Returns the part of a string (typically a bone's name) corresponding to it's Returns the part of a string (typically a bone's name) corresponding to it's
@ -327,16 +328,17 @@ def write_meta_rig(obj, func_name="metarig_template"):
return "\n".join(code) return "\n".join(code)
# *** bone class collection *** # *** bone class collection ***
def bone_class_instance(obj, slots, name="BoneContainer"): def bone_class_instance(obj, slots, name="BoneContainer"):
''' '''
bone collection utility class to help manage cases with bone collection utility class to help manage cases with
edit/pose/bone bones where switching modes can invalidate some of the members. edit/pose/bone bones where switching modes can invalidate some of the members.
there are also utility functions for manipulating all members. there are also utility functions for manipulating all members.
''' '''
if len(slots) != len(set(slots)): if len(slots) != len(set(slots)):
raise Exception("duplicate entries found %s" % attr_names) raise Exception("duplicate entries found %s" % attr_names)
@ -361,6 +363,7 @@ def bone_class_instance(obj, slots, name="BoneContainer"):
instance = auto_class_instance(slots, name, class_dict) instance = auto_class_instance(slots, name, class_dict)
return instance return instance
def auto_class(slots, name="ContainerClass", class_dict=None): def auto_class(slots, name="ContainerClass", class_dict=None):
if class_dict: if class_dict:
@ -413,10 +416,10 @@ def _bone_class_instance_copy(self, from_fmt="%s", to_fmt="%s", exclude_attrs=()
new_slot_ls = [] new_slot_ls = []
for attr in self.attr_names: for attr in self.attr_names:
if attr in exclude_attrs: if attr in exclude_attrs:
continue continue
bone_name_orig = getattr(self, attr) bone_name_orig = getattr(self, attr)
ebone = getattr(self, attr + "_e") ebone = getattr(self, attr + "_e")
# orig_names[attr] = bone_name_orig # orig_names[attr] = bone_name_orig

View File

@ -219,7 +219,6 @@ class WM_OT_properties_edit(bpy.types.Operator):
return ('RUNNING_MODAL',) return ('RUNNING_MODAL',)
class WM_OT_properties_add(bpy.types.Operator): class WM_OT_properties_add(bpy.types.Operator):
'''Internal use (edit a property path)''' '''Internal use (edit a property path)'''
bl_idname = "wm.properties_add" bl_idname = "wm.properties_add"

View File

@ -126,4 +126,3 @@ class Retopo(bpy.types.Operator):
bpy.ops.add(SelectPattern) bpy.ops.add(SelectPattern)
bpy.ops.add(SubdivisionSet) bpy.ops.add(SubdivisionSet)
bpy.ops.add(Retopo) bpy.ops.add(Retopo)

View File

@ -23,6 +23,7 @@ import os
from bpy.props import * from bpy.props import *
class MESH_OT_delete_edgeloop(bpy.types.Operator): class MESH_OT_delete_edgeloop(bpy.types.Operator):
'''Export a single object as a stanford PLY with normals, '''Export a single object as a stanford PLY with normals,
colours and texture coordinates.''' colours and texture coordinates.'''
@ -42,7 +43,8 @@ rna_path_prop = StringProperty(name="Context Attributes",
rna_reverse_prop = BoolProperty(name="Reverse", rna_reverse_prop = BoolProperty(name="Reverse",
description="Cycle backwards", default=False) description="Cycle backwards", default=False)
class NullPathMember:
class NullPath:
pass pass
@ -53,7 +55,7 @@ def context_path_validate(context, path):
except AttributeError: except AttributeError:
if "'NoneType'" in str(sys.exc_info()[1]): if "'NoneType'" in str(sys.exc_info()[1]):
# One of the items in the rna path is None, just ignore this # One of the items in the rna path is None, just ignore this
value = NullPathMember value = NullPath
else: else:
# We have a real error in the rna path, dont ignore that # We have a real error in the rna path, dont ignore that
raise raise
@ -62,7 +64,7 @@ def context_path_validate(context, path):
def execute_context_assign(self, context): def execute_context_assign(self, context):
if context_path_validate(context, self.properties.path) == NullPathMember: if context_path_validate(context, self.properties.path) == NullPath:
return ('PASS_THROUGH',) return ('PASS_THROUGH',)
exec("context.%s=self.properties.value" % self.properties.path) exec("context.%s=self.properties.value" % self.properties.path)
return ('FINISHED',) return ('FINISHED',)
@ -136,10 +138,12 @@ class WM_OT_context_toggle(bpy.types.Operator):
def execute(self, context): def execute(self, context):
if context_path_validate(context, self.properties.path) == NullPathMember: if context_path_validate(context, self.properties.path) == NullPath:
return ('PASS_THROUGH',) return ('PASS_THROUGH',)
exec("context.%s=not (context.%s)" % (self.properties.path, self.properties.path)) exec("context.%s=not (context.%s)" %
(self.properties.path, self.properties.path))
return ('FINISHED',) return ('FINISHED',)
@ -157,11 +161,13 @@ class WM_OT_context_toggle_enum(bpy.types.Operator):
def execute(self, context): def execute(self, context):
if context_path_validate(context, self.properties.path) == NullPathMember: if context_path_validate(context, self.properties.path) == NullPath:
return ('PASS_THROUGH',) return ('PASS_THROUGH',)
exec("context.%s = ['%s', '%s'][context.%s!='%s']" % \ exec("context.%s = ['%s', '%s'][context.%s!='%s']" % \
(self.properties.path, self.properties.value_1, self.properties.value_2, self.properties.path, self.properties.value_2)) (self.properties.path, self.properties.value_1,\
self.properties.value_2, self.properties.path,
self.properties.value_2))
return ('FINISHED',) return ('FINISHED',)
@ -177,7 +183,7 @@ class WM_OT_context_cycle_int(bpy.types.Operator):
def execute(self, context): def execute(self, context):
value = context_path_validate(context, self.properties.path) value = context_path_validate(context, self.properties.path)
if value == NullPathMember: if value == NullPath:
return ('PASS_THROUGH',) return ('PASS_THROUGH',)
self.properties.value = value self.properties.value = value
@ -209,7 +215,7 @@ class WM_OT_context_cycle_enum(bpy.types.Operator):
def execute(self, context): def execute(self, context):
value = context_path_validate(context, self.properties.path) value = context_path_validate(context, self.properties.path)
if value == NullPathMember: if value == NullPath:
return ('PASS_THROUGH',) return ('PASS_THROUGH',)
orig_value = value orig_value = value
@ -318,9 +324,12 @@ class WM_OT_doc_edit(bpy.types.Operator):
def execute(self, context): def execute(self, context):
class_name, class_prop = self.properties.doc_id.split('.') doc_id = self.properties.doc_id
doc_new = self.properties.doc_new
if not self.properties.doc_new: class_name, class_prop = doc_id.split('.')
if not doc_new:
return ('RUNNING_MODAL',) return ('RUNNING_MODAL',)
# check if this is an operator # check if this is an operator
@ -333,25 +342,25 @@ class WM_OT_doc_edit(bpy.types.Operator):
if op_class: if op_class:
rna = op_class.bl_rna rna = op_class.bl_rna
doc_orig = rna.description doc_orig = rna.description
if doc_orig == self.properties.doc_new: if doc_orig == doc_new:
return ('RUNNING_MODAL',) return ('RUNNING_MODAL',)
print("op - old:'%s' -> new:'%s'" % (doc_orig, self.properties.doc_new)) print("op - old:'%s' -> new:'%s'" % (doc_orig, doc_new))
upload["title"] = 'OPERATOR %s:%s' % (self.properties.doc_id, doc_orig) upload["title"] = 'OPERATOR %s:%s' % (doc_id, doc_orig)
upload["description"] = self.properties.doc_new upload["description"] = doc_new
self._send_xmlrpc(upload) self._send_xmlrpc(upload)
else: else:
rna = getattr(bpy.types, class_name).bl_rna rna = getattr(bpy.types, class_name).bl_rna
doc_orig = rna.properties[class_prop].description doc_orig = rna.properties[class_prop].description
if doc_orig == self.properties.doc_new: if doc_orig == doc_new:
return ('RUNNING_MODAL',) return ('RUNNING_MODAL',)
print("rna - old:'%s' -> new:'%s'" % (doc_orig, self.properties.doc_new)) print("rna - old:'%s' -> new:'%s'" % (doc_orig, doc_new))
upload["title"] = 'RNA %s:%s' % (self.properties.doc_id, doc_orig) upload["title"] = 'RNA %s:%s' % (doc_id, doc_orig)
upload["description"] = self.properties.doc_new upload["description"] = doc_new
self._send_xmlrpc(upload) self._send_xmlrpc(upload)

View File

@ -100,7 +100,7 @@ class SCENE_PT_keying_sets(SceneButtonsPanel):
col = row.column() col = row.column()
col.label(text="Keyframing Settings:") col.label(text="Keyframing Settings:")
col.prop(ks, "insertkey_needed", text="Needed") col.prop(ks, "insertkey_needed", text="Needed")
col.prop(ks, "insertkey_visual", text="Visual") col.prop(ks, "insertkey_visual", text="Visual")
col.prop(ks, "insertkey_xyz_to_rgb", text="XYZ to RGB") col.prop(ks, "insertkey_xyz_to_rgb", text="XYZ to RGB")

View File

@ -51,7 +51,7 @@ class INFO_HT_header(bpy.types.Header):
layout.separator() layout.separator()
else: else:
layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete") layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete")
layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete") layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete")
layout.separator() layout.separator()
@ -182,6 +182,7 @@ class INFO_MT_mesh_add(dynamic_menu.DynMenu):
layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid") layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey") layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
class INFO_MT_armature_add(dynamic_menu.DynMenu): class INFO_MT_armature_add(dynamic_menu.DynMenu):
bl_idname = "INFO_MT_armature_add" bl_idname = "INFO_MT_armature_add"
bl_label = "Armature" bl_label = "Armature"

View File

@ -134,7 +134,7 @@ class SEQUENCER_MT_select(bpy.types.Menu):
class SEQUENCER_MT_marker(bpy.types.Menu): class SEQUENCER_MT_marker(bpy.types.Menu):
bl_label = "Marker (TODO)" bl_label = "Marker"
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@ -384,7 +384,7 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel):
elif strip.type == 'TRANSFORM': elif strip.type == 'TRANSFORM':
self.draw_panel_transform(strip) self.draw_panel_transform(strip)
col = layout.column(align=True) col = layout.column(align=True)
if strip.type == 'SPEED': if strip.type == 'SPEED':
@ -393,11 +393,11 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel):
col.prop(strip, "use_effect_default_fade", "Default fade") col.prop(strip, "use_effect_default_fade", "Default fade")
if not strip.use_effect_default_fade: if not strip.use_effect_default_fade:
col.prop(strip, "effect_fader", text="Effect fader") col.prop(strip, "effect_fader", text="Effect fader")
def draw_panel_transform(self, strip): def draw_panel_transform(self, strip):
layout = self.layout layout = self.layout
col = layout.column() col = layout.column()
col.prop(strip, "interpolation") col.prop(strip, "interpolation")
col.prop(strip, "translation_unit") col.prop(strip, "translation_unit")
col = layout.column(align=True) col = layout.column(align=True)

View File

@ -111,9 +111,9 @@ class USERPREF_PT_interface(bpy.types.Panel):
column = split.column() column = split.column()
colsplit = column.split(percentage=0.85) colsplit = column.split(percentage=0.85)
col = colsplit.column() col = colsplit.column()
#Toolbox doesn't exist yet #Toolbox doesn't exist yet
#col.label(text="Toolbox:") #col.label(text="Toolbox:")
#col.prop(view, "use_column_layout") #col.prop(view, "use_column_layout")
@ -173,7 +173,7 @@ class USERPREF_PT_edit(bpy.types.Panel):
col.prop(edit, "enter_edit_mode") col.prop(edit, "enter_edit_mode")
col.label(text="Align To:") col.label(text="Align To:")
col.row().prop(edit, "object_align", expand=True) col.row().prop(edit, "object_align", expand=True)
col.separator() col.separator()
col.separator() col.separator()
col.separator() col.separator()
@ -299,11 +299,11 @@ class USERPREF_PT_system(bpy.types.Panel):
sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer") sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
sub.prop(system, "audio_sample_rate", text="Sample Rate") sub.prop(system, "audio_sample_rate", text="Sample Rate")
sub.prop(system, "audio_sample_format", text="Sample Format") sub.prop(system, "audio_sample_format", text="Sample Format")
col.separator() col.separator()
col.separator() col.separator()
col.separator() col.separator()
col.label(text="Weight Colors:") col.label(text="Weight Colors:")
col.prop(system, "use_weight_color_range", text="Use Custom Range") col.prop(system, "use_weight_color_range", text="Use Custom Range")
sub = col.column() sub = col.column()
@ -329,7 +329,7 @@ class USERPREF_PT_system(bpy.types.Panel):
col1 = colsplit.column() col1 = colsplit.column()
col1.label(text="Solid OpenGL lights:") col1.label(text="Solid OpenGL lights:")
col = col1.split() col = col1.split()
sub = col.column() sub = col.column()
@ -355,7 +355,7 @@ class USERPREF_PT_system(bpy.types.Panel):
subsub.prop(lamp2, "diffuse_color") subsub.prop(lamp2, "diffuse_color")
subsub.prop(lamp2, "specular_color") subsub.prop(lamp2, "specular_color")
subsub.prop(lamp2, "direction") subsub.prop(lamp2, "direction")
column = split.column() column = split.column()
colsplit = column.split(percentage=0.85) colsplit = column.split(percentage=0.85)
@ -453,7 +453,7 @@ class USERPREF_PT_theme(bpy.types.Panel):
subsub.active = ui.shaded subsub.active = ui.shaded
subsub.prop(ui, "shadetop") subsub.prop(ui, "shadetop")
subsub.prop(ui, "shadedown") subsub.prop(ui, "shadedown")
layout.separator() layout.separator()
ui = theme.user_interface.wcol_tool ui = theme.user_interface.wcol_tool
@ -1070,10 +1070,10 @@ class USERPREF_PT_file(bpy.types.Panel):
col = split.column() col = split.column()
col.label(text="File Paths:") col.label(text="File Paths:")
colsplit = col.split(percentage=0.95) colsplit = col.split(percentage=0.95)
col1 = colsplit.split(percentage=0.3) col1 = colsplit.split(percentage=0.3)
sub = col1.column() sub = col1.column()
sub.label(text="Fonts:") sub.label(text="Fonts:")
sub.label(text="Textures:") sub.label(text="Textures:")
@ -1084,7 +1084,7 @@ class USERPREF_PT_file(bpy.types.Panel):
sub.label(text="Sounds:") sub.label(text="Sounds:")
sub.label(text="Temp:") sub.label(text="Temp:")
sub.label(text="Animation Player:") sub.label(text="Animation Player:")
sub = col1.column() sub = col1.column()
sub.prop(paths, "fonts_directory", text="") sub.prop(paths, "fonts_directory", text="")
sub.prop(paths, "textures_directory", text="") sub.prop(paths, "textures_directory", text="")
@ -1105,7 +1105,7 @@ class USERPREF_PT_file(bpy.types.Panel):
col.prop(paths, "load_ui") col.prop(paths, "load_ui")
col.prop(paths, "filter_file_extensions") col.prop(paths, "filter_file_extensions")
col.prop(paths, "hide_dot_files_datablocks") col.prop(paths, "hide_dot_files_datablocks")
col.separator() col.separator()
col.separator() col.separator()
@ -1474,4 +1474,4 @@ bpy.ops.add(WM_OT_keyconfig_export)
bpy.ops.add(WM_OT_keymap_edit) bpy.ops.add(WM_OT_keymap_edit)
bpy.ops.add(WM_OT_keymap_restore) bpy.ops.add(WM_OT_keymap_restore)
bpy.ops.add(WM_OT_keyitem_add) bpy.ops.add(WM_OT_keyitem_add)
bpy.ops.add(WM_OT_keyitem_remove) bpy.ops.add(WM_OT_keyitem_remove)

93
release/test/pep8.py Normal file
View File

@ -0,0 +1,93 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import os
# depends on pep8, pyflakes, pylint
# for ubuntu/debian
#
# sudo apt-get install pylint pyflakes
#
# sudo apt-get install python-setuptools python-pip
# sudo pip install pep8
# how many lines to read into the file, pep8 comment
# should be directly after the licence header, ~20 in most cases
PEP8_SEEK_COMMENT = 40
SKIP_PREFIX = "./tools", "./config", "./scons", "./extern"
def file_list_py(path):
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith(".py"):
yield os.path.join(dirpath, filename)
def is_pep8(path):
f = open(path, 'r')
for i in range(PEP8_SEEK_COMMENT):
line = f.readline()
if line.startswith("# <pep8"):
if line.startswith("# <pep8 compliant>"):
return 1
elif line.startswith("# <pep8-80 compliant>"):
return 2
f.close()
return 0
def main():
files = []
files_skip = []
for f in file_list_py("."):
pep8_type = is_pep8(f)
if pep8_type:
# so we can batch them for each tool.
files.append((f, pep8_type))
else:
if not [None for prefix in SKIP_PREFIX if f.startswith(prefix)]:
files_skip.append(f)
print("\nSkipping...")
for f in files_skip:
print(" %s" % f)
# pyflakes
print("\n\n\n# running pep8...")
for f, pep8_type in files:
if pep8_type == 1:
# E501:80 line length
os.system("pep8 --repeat --ignore=E501 '%s'" % (f))
else:
os.system("pep8 --repeat '%s'" % (f))
print("\n\n\n# running pyflakes...")
for f, pep8_type in files:
os.system("pyflakes '%s'" % f)
print("\n\n\n# running pylint...")
for f, pep8_type in files:
# let pep8 complain about line length
os.system("pylint --reports=n --max-line-length=1000 '%s'" % f)
if __name__ == "__main__":
main()