From 488e1da935d55330be55eb30b4605b993dd65dbd Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Sun, 10 Jul 2011 22:57:27 +0000
Subject: [PATCH] cleanup - remove/comment unused variables - remove unused
 imports - fixed some bugs using incorrect variables

---
 add_mesh_BoltFactory/Boltfactory.py           |  2 +-
 add_mesh_BoltFactory/createMesh.py            | 65 +++++++------------
 add_mesh_BoltFactory/preset_utils.py          |  4 +-
 .../add_mesh_extra_objects.py                 |  2 -
 add_mesh_extra_objects/add_mesh_gears.py      |  6 +-
 add_mesh_extra_objects/add_mesh_gemstones.py  |  4 +-
 .../add_mesh_twisted_torus.py                 |  3 -
 io_anim_bvh/export_bvh.py                     |  9 +--
 io_anim_bvh/import_bvh.py                     |  2 -
 io_coat3D/coat.py                             |  7 +-
 io_coat3D/tex.py                              | 51 ++++++++-------
 io_convert_image_to_mesh_img/import_img.py    | 12 +---
 io_curve_svg/__init__.py                      |  2 +-
 io_curve_svg/import_svg.py                    |  4 +-
 io_mesh_ply/import_ply.py                     |  6 +-
 io_mesh_raw/import_raw.py                     |  4 --
 io_scene_3ds/export_3ds.py                    |  6 --
 io_scene_3ds/import_3ds.py                    |  5 +-
 io_scene_fbx/__init__.py                      |  1 -
 io_scene_fbx/export_fbx.py                    | 14 ++--
 io_scene_m3/__init__.py                       |  2 +-
 io_scene_m3/import_m3.py                      |  1 -
 io_scene_map/__init__.py                      |  8 +--
 io_scene_map/export_map.py                    |  3 +-
 io_scene_obj/__init__.py                      |  1 -
 io_scene_obj/export_obj.py                    |  5 --
 io_scene_obj/import_obj.py                    |  5 +-
 io_scene_x3d/__init__.py                      |  1 -
 io_scene_x3d/export_x3d.py                    |  2 +-
 io_scene_x3d/import_x3d.py                    |  3 +-
 io_shape_mdd/export_mdd.py                    |  3 -
 io_shape_mdd/import_mdd.py                    |  5 +-
 light_field_tools/__init__.py                 |  1 -
 light_field_tools/light_field_tools.py        |  2 +-
 modules/ui_utils.py                           |  4 +-
 netrender/client.py                           | 10 +--
 netrender/master.py                           |  6 +-
 netrender/master_html.py                      |  1 -
 netrender/model.py                            |  4 --
 netrender/operators.py                        | 11 ++--
 netrender/repath.py                           |  1 -
 netrender/slave.py                            |  6 +-
 netrender/thumbnail.py                        |  3 +-
 netrender/ui.py                               | 12 ++--
 netrender/utils.py                            |  5 +-
 netrender/versioning.py                       | 20 +++++-
 object_fracture/fracture_ops.py               |  2 -
 render_povray/render.py                       |  9 ++-
 render_povray/ui.py                           | 13 ++--
 rigify/__init__.py                            |  1 -
 rigify/generate.py                            |  6 +-
 rigify/metarig_menu.py                        |  2 -
 rigify/rigs/basic/copy.py                     |  6 +-
 rigify/rigs/basic/copy_chain.py               |  2 +-
 rigify/rigs/biped/arm/__init__.py             |  1 -
 rigify/rigs/biped/arm/deform.py               |  6 +-
 rigify/rigs/biped/arm/fk.py                   |  7 +-
 rigify/rigs/biped/arm/ik.py                   |  3 +-
 rigify/rigs/biped/leg/__init__.py             |  1 -
 rigify/rigs/biped/leg/deform.py               |  6 +-
 rigify/rigs/biped/leg/fk.py                   |  7 +-
 rigify/rigs/biped/leg/ik.py                   |  3 +-
 rigify/rigs/finger.py                         |  3 +-
 rigify/rigs/misc/delta.py                     |  2 +-
 rigify/rigs/neck_short.py                     |  9 ++-
 rigify/rigs/palm.py                           |  4 +-
 rigify/rigs/spine.py                          |  2 +-
 rigify/ui.py                                  |  8 +--
 rigify/utils.py                               |  3 +-
 space_view3d_math_vis/__init__.py             |  1 -
 space_view3d_math_vis/utils.py                |  2 -
 system_blend_info.py                          |  4 +-
 system_demo_mode/__init__.py                  |  3 -
 73 files changed, 172 insertions(+), 278 deletions(-)

diff --git a/add_mesh_BoltFactory/Boltfactory.py b/add_mesh_BoltFactory/Boltfactory.py
index 97a489b03..c5fa403ff 100644
--- a/add_mesh_BoltFactory/Boltfactory.py
+++ b/add_mesh_BoltFactory/Boltfactory.py
@@ -227,7 +227,7 @@ class add_mesh_bolt(bpy.types.Operator):
         if self.bf_Model_Type == 'bf_Model_Bolt':
             col.prop(self, 'bf_Bit_Type')
             if self.bf_Bit_Type == 'bf_Bit_None':
-                DoNothing = 1;
+                pass
             elif self.bf_Bit_Type == 'bf_Bit_Allen':
                  col.prop(self, 'bf_Allen_Bit_Depth')
                  col.prop(self, 'bf_Allen_Bit_Flat_Distance')
diff --git a/add_mesh_BoltFactory/createMesh.py b/add_mesh_BoltFactory/createMesh.py
index 1ff82229e..bceb4ebd8 100644
--- a/add_mesh_BoltFactory/createMesh.py
+++ b/add_mesh_BoltFactory/createMesh.py
@@ -16,8 +16,6 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-
-import os  #remove this
 import bpy
 
 try: 
@@ -30,7 +28,6 @@ except:
 
 
 from math import *
-from bpy.props import IntProperty, FloatProperty ,EnumProperty
 from itertools import * 
 
 NARROW_UI = 180
@@ -278,7 +275,7 @@ def Fill_Ring_Face(OFFSET,NUM,FACE_DOWN = 0):
     Ret =[]
     Face = [1,2,0]
     TempFace = [0,0,0]
-    A = 0
+    # A = 0  # UNUSED
     B = 1
     C = 2
     if NUM < 3:
@@ -475,7 +472,7 @@ def Create_Phillips_Bit(FLAT_DIA,FLAT_WIDTH,HEIGHT):
         verts.append([x,y,0])
     
         
-    FaceStart_Inside = len(verts)
+    # FaceStart_Inside = len(verts)  # UNUSED
     verts.append([0,FLAT_RADIUS,0]) #10
     verts.append([Flat_Half,FLAT_RADIUS,0]) #11
     verts.append([Flat_Half,Flat_Half,0])     #12
@@ -518,14 +515,7 @@ def Create_Pan_Head(HOLE_DIA,HEAD_DIA,SHANK_DIA,HEIGHT,RAD1,RAD2,FACE_OFFSET):
     verts = []
     faces = []
     Row = 0
-    BEVEL = HEIGHT * 0.01
-    #Dome_Rad =  HEAD_RADIUS * (1.0/1.75)
-    
-    Dome_Rad = HEAD_RADIUS * 1.12
-    RAD_Offset = HEAD_RADIUS * 0.96
-    OtherRad = HEAD_RADIUS * 0.16
-    OtherRad_X_Offset = HEAD_RADIUS * 0.84
-    OtherRad_Z_Offset = HEAD_RADIUS * 0.504
+
     XRad = HEAD_RADIUS * 1.976
     ZRad = HEAD_RADIUS * 1.768
     EndRad = HEAD_RADIUS * 0.284
@@ -579,7 +569,7 @@ def Create_Pan_Head(HOLE_DIA,HEAD_DIA,SHANK_DIA,HEIGHT,RAD1,RAD2,FACE_OFFSET):
     
     faces.extend(Build_Face_List_Quads(FaceStart,Row-1,DIV))
 
-    Global_Head_Height = HEIGHT ;
+    # Global_Head_Height = HEIGHT  # UNUSED
 
     
     return Move_Verts_Up_Z(sVerts,Start_Height),faces,HEIGHT
@@ -595,7 +585,7 @@ def Create_Dome_Head(HOLE_DIA,HEAD_DIA,SHANK_DIA,HEIGHT,RAD1,RAD2,FACE_OFFSET):
     verts = []
     faces = []
     Row = 0
-    BEVEL = HEIGHT * 0.01
+    # BEVEL = HEIGHT * 0.01  # UNUSED
     #Dome_Rad =  HEAD_RADIUS * (1.0/1.75)
     
     Dome_Rad =  HEAD_RADIUS * 1.12
@@ -662,9 +652,6 @@ def Create_CounterSink_Head(HOLE_DIA,HEAD_DIA,SHANK_DIA,HEIGHT,RAD1):
     verts = []
     faces = []
     Row = 0
-    BEVEL = HEIGHT * 0.01
-
-
 
 #    HEAD_RADIUS = (HEIGHT/tan(radians(60))) + SHANK_RADIUS
     HEIGHT = tan(radians(60)) * (HEAD_RADIUS - SHANK_RADIUS)
@@ -987,7 +974,7 @@ def Thread_Start3(verts,INNER_RADIUS,OUTTER_RADIUS,PITCH,DIV,CREST_PERCENT,ROOT_
     
     Ret_Row = 0;
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     Height_Start = Height_Offset - PITCH
     Height_Step = float(PITCH)/float(DIV)
     Deg_Step = 360.0 /float(DIV)
@@ -1111,7 +1098,7 @@ def Create_Thread_Start_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERC
     INNER_RADIUS = INNER_DIA/2
     OUTTER_RADIUS = OUTTER_DIA/2
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     Deg_Step = 360.0 /float(DIV)
     Height_Step = float(PITCH)/float(DIV)
 
@@ -1245,7 +1232,7 @@ def Create_Thread_Verts(INNER_DIA,OUTTER_DIA,PITCH,HEIGHT,CREST_PERCENT,ROOT_PER
     INNER_RADIUS = INNER_DIA/2
     OUTTER_RADIUS = OUTTER_DIA/2
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     Deg_Step = 360.0 /float(DIV)
     Height_Step = float(PITCH)/float(DIV)
 
@@ -1263,9 +1250,7 @@ def Create_Thread_Verts(INNER_DIA,OUTTER_DIA,PITCH,HEIGHT,CREST_PERCENT,ROOT_PER
     Height_Offset = Z_LOCATION
     
     Lowest_Z_Vert = 0;
-    FaceStart = len(verts)
-    
-    
+
     for j in range(Num):
         
         for i in range(DIV+1):
@@ -1317,7 +1302,7 @@ def Create_Thread_End_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCEN
     INNER_RADIUS = INNER_DIA/2
     OUTTER_RADIUS = OUTTER_DIA/2
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     Deg_Step = 360.0 /float(DIV)
     Height_Step = float(PITCH)/float(DIV)
 
@@ -1325,7 +1310,7 @@ def Create_Thread_End_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCEN
     Root_Height = float(PITCH) * float(ROOT_PERCENT)/float(100)
     Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height))/2.0
        
-    Col = 0
+    # Col = 0  # UNUSED
     Row = 0
     
     Height_Offset = Z_LOCATION 
@@ -1336,7 +1321,7 @@ def Create_Thread_End_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCEN
     
     Lowest_Z_Vert = 0;
     
-    FaceStart = len(verts)
+    # FaceStart = len(verts)  # UNUSED
     for j in range(4):
         
         for i in range(DIV+1):
@@ -1409,7 +1394,7 @@ def Create_External_Thread(SHANK_DIA,SHANK_LENGTH,INNER_DIA,OUTTER_DIA,PITCH,LEN
     DIV = 36
     
     Total_Row = 0
-    Thread_Len = 0;
+    # Thread_Len = 0  # UNUSED
     
     Face_Start = len(verts)
     Offset = 0.0;
@@ -1612,7 +1597,7 @@ def add_Nylon_Head(OUTSIDE_RADIUS,Z_LOCATION = 0):
     
     FaceStart = len(verts)
 
-    Start_Height = 0 - 3
+    # Start_Height = 0 - 3  # UNUSED
     Height_Offset = Z_LOCATION
     Lowest_Z_Vert = 0
     
@@ -1660,14 +1645,14 @@ def add_Nylon_Part(OUTSIDE_RADIUS,Z_LOCATION = 0):
 
     INNER_HOLE = OUTSIDE_RADIUS - (OUTSIDE_RADIUS * (1.5/4.75))
     EDGE_THICKNESS = (OUTSIDE_RADIUS * (0.4/4.75))
-    RAD1 = (OUTSIDE_RADIUS * (0.5/4.75))
+    # RAD1 = (OUTSIDE_RADIUS * (0.5/4.75))  # UNUSED
     OVER_ALL_HEIGTH = (OUTSIDE_RADIUS * (2.0/4.75))
     PART_THICKNESS = OVER_ALL_HEIGTH - EDGE_THICKNESS
     PART_INNER_HOLE = (OUTSIDE_RADIUS * (2.5/4.75))
     
     FaceStart = len(verts)
 
-    Start_Height = 0 - 3
+    # Start_Height = 0 - 3  # UNUSED
     Height_Offset = Z_LOCATION
     Lowest_Z_Vert = 0
     
@@ -1720,7 +1705,7 @@ def Create_Internal_Thread_Start_Verts(verts,INNER_RADIUS,OUTTER_RADIUS,PITCH,DI
     Height_Offset = Height_Offset + PITCH  #Move the offset up so that the verts start at 
                                            #at the correct place  (Height_Start)
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     Height_Start = Height_Offset - PITCH 
     Height_Step = float(PITCH)/float(DIV)
     Deg_Step = 360.0 /float(DIV)
@@ -1792,7 +1777,7 @@ def Create_Internal_Thread_End_Verts(verts,INNER_RADIUS,OUTTER_RADIUS,PITCH,DIV,
     
     Ret_Row = 0;
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     #Height_End = Height_Offset - PITCH - PITCH - PITCH- PITCH - PITCH- PITCH
     Height_End = Height_Offset - PITCH 
     #Height_End = -2.1
@@ -1884,13 +1869,13 @@ def Create_Internal_Thread(INNER_DIA,OUTTER_DIA,PITCH,HEIGHT,CREST_PERCENT,ROOT_
     INNER_RADIUS = INNER_DIA/2
     OUTTER_RADIUS = OUTTER_DIA/2
     
-    Half_Pitch = float(PITCH)/2
+    # Half_Pitch = float(PITCH)/2  # UNUSED
     Deg_Step = 360.0 /float(DIV)
     Height_Step = float(PITCH)/float(DIV)
             
     Num = int(round((HEIGHT- PITCH)/PITCH))  # less one pitch for the start and end that is 1/2 pitch high    
     
-    Col = 0
+    # Col = 0  # UNUSED
     Row = 0
     
     
@@ -2165,19 +2150,19 @@ def Create_New_Mesh(props, context, align_matrix):
 
     verts = []
     faces = []
-    sMeshName =''
+    # sMeshName =''  # UNUSED
     sObjName =''
         
     if props.bf_Model_Type == 'bf_Model_Bolt':
         #print('Create Bolt')
         verts, faces = Bolt_Mesh(props, context)
-        sMeshName = 'Bolt'
+        # sMeshName = 'Bolt'  # UNUSED
         sObjName = 'Bolt'
     
     if props.bf_Model_Type == 'bf_Model_Nut':
         #print('Create Nut')
         verts, faces = Nut_Mesh(props, context)
-        sMeshName = 'Nut'
+        # sMeshName = 'Nut'  # UNUSED
         sObjName = 'Nut'
 
     
@@ -2188,8 +2173,6 @@ def Create_New_Mesh(props, context, align_matrix):
     obj = create_mesh_object(context, verts, [], faces,sObjName,
             props.edit, align_matrix)
 
-
-    #print("Created_Object")
-    return
+    return obj
     
 
diff --git a/add_mesh_BoltFactory/preset_utils.py b/add_mesh_BoltFactory/preset_utils.py
index 4d31accfe..093d9f82b 100644
--- a/add_mesh_BoltFactory/preset_utils.py
+++ b/add_mesh_BoltFactory/preset_utils.py
@@ -16,9 +16,7 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-
-import bpy
-import os, sys
+import os
 
 
 def getPresets():
diff --git a/add_mesh_extra_objects/add_mesh_extra_objects.py b/add_mesh_extra_objects/add_mesh_extra_objects.py
index c5caa1203..83ce4fa71 100644
--- a/add_mesh_extra_objects/add_mesh_extra_objects.py
+++ b/add_mesh_extra_objects/add_mesh_extra_objects.py
@@ -26,8 +26,6 @@ from bpy.props import *
 #                       new mesh (as used in from_pydata).
 # name ... Name of the new mesh (& object).
 def create_mesh_object(context, verts, edges, faces, name):
-    scene = context.scene
-    obj_act = scene.objects.active
 
     # Create new mesh
     mesh = bpy.data.meshes.new(name)
diff --git a/add_mesh_extra_objects/add_mesh_gears.py b/add_mesh_extra_objects/add_mesh_gears.py
index a04e6bebe..a8f7aac64 100644
--- a/add_mesh_extra_objects/add_mesh_gears.py
+++ b/add_mesh_extra_objects/add_mesh_gears.py
@@ -66,7 +66,6 @@ add_mesh_torus() (distributed with Blender).
 """
 
 import bpy
-import mathutils
 from math import *
 from bpy.props import *
 
@@ -75,9 +74,6 @@ from bpy.props import *
 #                       new mesh (as used in from_pydata).
 # name ... Name of the new mesh (& object).
 def create_mesh_object(context, verts, edges, faces, name):
-    scene = context.scene
-    obj_act = scene.objects.active
-
     # Create new mesh
     mesh = bpy.data.meshes.new(name)
 
@@ -250,7 +246,7 @@ def add_tooth(a, t, d, radius, Ad, De, base, p_angle, rack=0, crown=0.0):
 def add_spoke(a, t, d, radius, De, base, s, w, l, gap=0, width=19):
     Rd = radius - De
     Rb = Rd - base
-    Rl = Rb
+    # Rl = Rb  # UNUSED
 
     verts = []
     edgefaces = []
diff --git a/add_mesh_extra_objects/add_mesh_gemstones.py b/add_mesh_extra_objects/add_mesh_gemstones.py
index d4158b689..a9491bd74 100644
--- a/add_mesh_extra_objects/add_mesh_gemstones.py
+++ b/add_mesh_extra_objects/add_mesh_gemstones.py
@@ -41,8 +41,6 @@ from bpy.props import *
 #                       new mesh (as used in from_pydata).
 # name ... Name of the new mesh (& object).
 def create_mesh_object(context, verts, edges, faces, name):
-    scene = context.scene
-    obj_act = scene.objects.active
 
     # Create new mesh
     mesh = bpy.data.meshes.new(name)
@@ -213,7 +211,7 @@ def add_diamond(segments, girdle_radius, table_radius,
     for index in range(segments):
         quat = Quaternion(z_axis, (index / segments) * PI_2)
 
-        angle = PI_2 * index / segments
+        # angle = PI_2 * index / segments  # UNUSED
 
         # Row for flat side
         verts_flat.append(len(verts))
diff --git a/add_mesh_extra_objects/add_mesh_twisted_torus.py b/add_mesh_extra_objects/add_mesh_twisted_torus.py
index 6eb8cc245..bfed46700 100644
--- a/add_mesh_extra_objects/add_mesh_twisted_torus.py
+++ b/add_mesh_extra_objects/add_mesh_twisted_torus.py
@@ -46,7 +46,6 @@ Usage:
 import bpy
 from bpy.props import *
 
-import mathutils
 from mathutils import *
 from math import cos, sin, pi
 
@@ -56,8 +55,6 @@ from math import cos, sin, pi
 #                       new mesh (as used in from_pydata).
 # name ... Name of the new mesh (& object).
 def create_mesh_object(context, verts, edges, faces, name):
-    scene = context.scene
-    obj_act = scene.objects.active
 
     # Create new mesh
     mesh = bpy.data.meshes.new(name)
diff --git a/io_anim_bvh/export_bvh.py b/io_anim_bvh/export_bvh.py
index 851eb1cc4..3b70033b5 100644
--- a/io_anim_bvh/export_bvh.py
+++ b/io_anim_bvh/export_bvh.py
@@ -37,7 +37,7 @@ def write_armature(context,
             rot_order_str = "XYZ"
         return rot_order_str
 
-    from mathutils import Matrix, Vector, Euler
+    from mathutils import Matrix, Euler
     from math import degrees
 
     file = open(filepath, "w", encoding="utf8", newline="\n")
@@ -180,7 +180,7 @@ def write_armature(context,
 
             self.pose_mat = self.pose_bone.matrix
 
-            mat = self.rest_bone.matrix
+            # mat = self.rest_bone.matrix  # UNUSED
             self.rest_arm_mat = self.rest_bone.matrix_local
             self.rest_local_mat = self.rest_bone.matrix
 
@@ -274,8 +274,3 @@ def save(operator, context, filepath="",
            )
 
     return {'FINISHED'}
-
-
-if __name__ == "__main__":
-    scene = bpy.context.scene
-    _read(bpy.data.filepath.rstrip(".blend") + ".bvh", bpy.context.object, scene.frame_start, scene.frame_end, 1.0)
diff --git a/io_anim_bvh/import_bvh.py b/io_anim_bvh/import_bvh.py
index 4f1d19ff6..b44608533 100644
--- a/io_anim_bvh/import_bvh.py
+++ b/io_anim_bvh/import_bvh.py
@@ -20,11 +20,9 @@
 
 # Script copyright (C) Campbell Barton
 
-import math
 from math import radians
 
 import bpy
-import mathutils
 from mathutils import Vector, Euler, Matrix
 
 
diff --git a/io_coat3D/coat.py b/io_coat3D/coat.py
index 954502f3e..4d967ce14 100644
--- a/io_coat3D/coat.py
+++ b/io_coat3D/coat.py
@@ -1,4 +1,3 @@
-
 # ***** BEGIN GPL LICENSE BLOCK *****
 #
 #
@@ -22,8 +21,6 @@ import bpy
 from bpy.props import *
 from io_coat3D import tex
 import os
-import linecache
-import math
 
 
 bpy.coat3D = dict()
@@ -151,7 +148,6 @@ class SCENE_PT_Settings(ObjectButtonsPanel,bpy.types.Panel):
 
     def draw(self, context):
         layout = self.layout
-        scene = context.scene
         coat3D = bpy.context.scene.coat3D
         
         row = layout.row()
@@ -374,8 +370,7 @@ class SCENE_OT_import(bpy.types.Operator):
                                                                 
 
                 if(coat3D.importmod):
-                    mod_list = []
-                    for mod_index in objekti.modifiers:
+                    for mod_index in objekti.modifiers[:]:
                         objekti.modifiers.remove(mod_index)
                         
                 
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index d4156e5dc..748d1aa06 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -1,6 +1,24 @@
+# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+
 import bpy
 import os
-import filecmp
 
 def objname(path):
 
@@ -40,15 +58,15 @@ def gettex(mat_list, objekti, scene,export):
     else:
         vray = False
     
-    take_color = 0;
-    take_spec = 0;
-    take_normal = 0;
-    take_disp = 0;
+    take_color = 0
+    take_spec = 0
+    take_normal = 0
+    take_disp = 0
     
-    bring_color = 1;
-    bring_spec = 1;
-    bring_normal = 1;
-    bring_disp = 1;
+    bring_color = 1
+    bring_spec = 1
+    bring_normal = 1
+    bring_disp = 1
 
     texcoat = {}
     texcoat['color'] = []
@@ -257,23 +275,16 @@ def gettex(mat_list, objekti, scene,export):
 
     if(bring_spec == 1 and texcoat['specular']):
         name_tex ='Specular_'
-        num = []
 
         index = find_index(objekti)
         
-
-        tex = bpy.ops.Texture
         objekti.active_material.texture_slots.create(index)
-        total_mat = len(objekti.active_material.texture_slots.items())
         useold = ''
         
         for seekco in bpy.data.textures:
             if((seekco.name[:9] == 'Specular_') and (seekco.users_material == ())):
                 useold = seekco
 
-        
-
-
         if(useold == ''):
 
             indexx = 0
@@ -321,24 +332,18 @@ def gettex(mat_list, objekti, scene,export):
 
     if(bring_disp == 1 and texcoat['disp']):
         name_tex ='Displacement_'
-        num = []
 
         index = find_index(objekti)
         
 
-        tex = bpy.ops.Texture
         objekti.active_material.texture_slots.create(index)
-        total_mat = len(objekti.active_material.texture_slots.items())
         useold = ''
         
         for seekco in bpy.data.textures:
             if((seekco.name[:13] == 'Displacement_') and (seekco.users_material == ())):
                 useold = seekco
 
-        
-
-
-        if(useold == ''):
+        if useold == "":
 
             indexx = 0
             tuli = False
diff --git a/io_convert_image_to_mesh_img/import_img.py b/io_convert_image_to_mesh_img/import_img.py
index 1735d1c3a..34d0123f8 100644
--- a/io_convert_image_to_mesh_img/import_img.py
+++ b/io_convert_image_to_mesh_img/import_img.py
@@ -23,7 +23,7 @@ This script can import a HiRISE DTM .IMG file.
 import bpy
 from bpy.props import *
 
-from struct import pack, unpack, unpack_from
+from struct import pack, unpack
 import os
 import queue, threading
 
@@ -169,8 +169,6 @@ class hirise_dtm_helper(object):
       ''' uses the parsed PDS Label to get the VALID_MINIMUM and VALID_MAXIMUM parameters
           from the first object named "IMAGE" -- is hackish
       '''
-      lines = None
-      line_samples = None
       for obj in label:
         if obj[0] == "IMAGE":
           return self.getValidMinMax(obj[1])
@@ -179,15 +177,12 @@ class hirise_dtm_helper(object):
         if obj[0] == "VALID_MAXIMUM":
           vmax = float(obj[1])
 
-      return ( vmin, vmax )
+      return vmin, vmax
 
     def getMissingConstant(self, label):
       ''' uses the parsed PDS Label to get the MISSING_CONSTANT parameter
           from the first object named "IMAGE" -- is hackish
       '''
-
-      lines = None
-      line_samples = None
       for obj in label:
         if obj[0] == "IMAGE":
           return self.getMissingConstant(obj[1])
@@ -257,7 +252,7 @@ class hirise_dtm_helper(object):
             del tmp_list[0:2]
           yield ret_list
           ret_list = []
-        last_line = line
+        # last_line = line  # UNUSED
         line_count += 1
 
     @threaded_generator
@@ -538,7 +533,6 @@ class hirise_dtm_helper(object):
       scale_y = self.scale() * img_props.pixel_scale()[1]
 
       line_count = 0
-      current_line = []
       # seed the last line (or previous line) with a line
       last_line = next(image_iter)
       point_offset = 0
diff --git a/io_curve_svg/__init__.py b/io_curve_svg/__init__.py
index dc68490b1..82982e76f 100644
--- a/io_curve_svg/__init__.py
+++ b/io_curve_svg/__init__.py
@@ -43,7 +43,7 @@ if "bpy" in locals():
 
 import bpy
 from bpy.props import StringProperty
-from bpy_extras.io_utils import ImportHelper, ExportHelper
+from bpy_extras.io_utils import ImportHelper
 
 
 class ImportSVG(bpy.types.Operator, ImportHelper):
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 231986e52..d8ae1a8d6 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -887,7 +887,7 @@ class SVGPathParser:
         Elliptical arc CurveTo path command
         """
 
-        c = code.lower()
+        # c = code.lower()  # UNUSED
         cur = self._data.cur()
 
         while cur is not None and not cur.isalpha():
@@ -1244,7 +1244,7 @@ class SVGGeometryUSE(SVGGeometry):
         Create real geometries
         """
 
-        geometries = []
+        # geometries = []  # UNUSED
         ref = self._node.getAttribute('xlink:href')
         geom = self._context['defines'].get(ref)
 
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index 3d0f29704..6d4326e47 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -209,8 +209,8 @@ import bpy
 
 def load_ply(filepath):
     import time
-    from bpy_extras.io_utils import unpack_list, unpack_face_list
-    from bpy_extras.image_utils import load_image
+    from bpy_extras.io_utils import unpack_face_list
+    # from bpy_extras.image_utils import load_image  # UNUSED
 
     t = time.time()
     obj_spec, obj = read(filepath)
@@ -225,7 +225,7 @@ def load_ply(filepath):
 
     for el in obj_spec.specs:
         if el.name == b'vertex':
-            vindices = vindices_x, vindices_y, vindices_z = el.index(b'x'), el.index(b'y'), el.index(b'z')
+            vindices_x, vindices_y, vindices_z = el.index(b'x'), el.index(b'y'), el.index(b'z')
             # noindices = (el.index('nx'), el.index('ny'), el.index('nz'))
             # if -1 in noindices: noindices = None
             uvindices = (el.index(b's'), el.index(b't'))
diff --git a/io_mesh_raw/import_raw.py b/io_mesh_raw/import_raw.py
index deda75e26..870f880b3 100644
--- a/io_mesh_raw/import_raw.py
+++ b/io_mesh_raw/import_raw.py
@@ -43,10 +43,6 @@ tolerance.
 
 import bpy
 
-# move those to a utility modul
-from bpy_extras.io_utils import unpack_face_list, unpack_list
-
-
 def readMesh(filename, objName):
     file = open(filename, "rb")
 
diff --git a/io_scene_3ds/export_3ds.py b/io_scene_3ds/export_3ds.py
index b9f5d982a..8264c18d5 100644
--- a/io_scene_3ds/export_3ds.py
+++ b/io_scene_3ds/export_3ds.py
@@ -235,9 +235,6 @@ class _3ds_point_uv(object):
     def __init__(self, point):
         self.uv = point
 
-    def __cmp__(self, other):
-        return cmp(self.uv, other.uv)
-
     def get_size(self):
         return 2 * SZ_FLOAT
 
@@ -360,9 +357,6 @@ class _3ds_chunk(object):
         self.variables = []
         self.subchunks = []
 
-    def set_ID(id):
-        self.ID = _3ds_short(id)
-
     def add_variable(self, name, var):
         '''Add a named variable.
 
diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py
index 803b8e53e..9dfda2aa5 100644
--- a/io_scene_3ds/import_3ds.py
+++ b/io_scene_3ds/import_3ds.py
@@ -198,7 +198,6 @@ def read_string(file):
 
 def process_next_object_chunk(file, previous_chunk):
     new_chunk = chunk()
-    temp_chunk = chunk()
 
     while (previous_chunk.bytes_read < previous_chunk.length):
         #read the next chunk
@@ -208,7 +207,7 @@ def process_next_object_chunk(file, previous_chunk):
 def skip_to_end(file, skip_chunk):
     buffer_size = skip_chunk.length - skip_chunk.bytes_read
     binary_format = "%ic" % buffer_size
-    temp_data = file.read(struct.calcsize(binary_format))
+    file.read(struct.calcsize(binary_format))
     skip_chunk.bytes_read += buffer_size
 
 
@@ -256,14 +255,12 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
 # 	TEXMODE = Mesh.FaceModes['TEX']
 
     # Localspace variable names, faster.
-    STRUCT_SIZE_1CHAR = struct.calcsize('c')
     STRUCT_SIZE_2FLOAT = struct.calcsize('2f')
     STRUCT_SIZE_3FLOAT = struct.calcsize('3f')
     STRUCT_SIZE_4FLOAT = struct.calcsize('4f')
     STRUCT_SIZE_UNSIGNED_SHORT = struct.calcsize('H')
     STRUCT_SIZE_4UNSIGNED_SHORT = struct.calcsize('4H')
     STRUCT_SIZE_4x3MAT = struct.calcsize('ffffffffffff')
-    _STRUCT_SIZE_4x3MAT = struct.calcsize('fffffffffffff')
     # STRUCT_SIZE_4x3MAT = calcsize('ffffffffffff')
     # print STRUCT_SIZE_4x3MAT, ' STRUCT_SIZE_4x3MAT'
     # only init once
diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index 5da1956ef..a805f7134 100644
--- a/io_scene_fbx/__init__.py
+++ b/io_scene_fbx/__init__.py
@@ -133,7 +133,6 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
         return self.batch_mode == 'OFF'
 
     def execute(self, context):
-        import math
         from mathutils import Matrix
         if not self.filepath:
             raise Exception("filepath not set")
diff --git a/io_scene_fbx/export_fbx.py b/io_scene_fbx/export_fbx.py
index 965941d9d..83c0fab28 100644
--- a/io_scene_fbx/export_fbx.py
+++ b/io_scene_fbx/export_fbx.py
@@ -29,7 +29,6 @@ http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx
 import os
 import time
 import math  # math.pi
-import shutil  # for file copying
 
 import bpy
 from mathutils import Vector, Matrix
@@ -937,7 +936,7 @@ def save_single(operator, scene, filepath="",
             do_light = not (light.use_only_shadow or (not light.use_diffuse and not light.use_specular))
             do_shadow = (light.shadow_method in ('RAY_SHADOW', 'BUFFER_SHADOW'))
 
-        scale = abs(global_matrix.to_scale()[0])  # scale is always uniform in this case
+        # scale = abs(global_matrix.to_scale()[0])  # scale is always uniform in this case  #  UNUSED
 
         file.write('\n\t\t\tProperty: "LightType", "enum", "",%i' % light_type)
         file.write('\n\t\t\tProperty: "CastLightOnObject", "bool", "",1')
@@ -1492,7 +1491,6 @@ def save_single(operator, scene, filepath="",
         uvlayers = []
         if do_uvs:
             uvlayers = me.uv_textures
-            uvlayer_orig = me.uv_textures.active
             for uvindex, uvlayer in enumerate(me.uv_textures):
                 file.write('\n\t\tLayerElementUV: %i {' % uvindex)
                 file.write('\n\t\t\tVersion: 101')
@@ -1611,8 +1609,6 @@ def save_single(operator, scene, filepath="",
                 for j, mat_tex_pair in enumerate(my_mesh.blenMaterials):
                     material_mapping_local[mat_tex_pair] = j
 
-                len_material_mapping_local = len(material_mapping_local)
-
                 mats = my_mesh.blenMaterialList
 
                 if me.uv_textures.active:
@@ -1768,7 +1764,7 @@ def save_single(operator, scene, filepath="",
     materials = {}  # (mat, image) keys, should be a set()
     textures = {}  # should be a set()
 
-    tmp_ob_type = ob_type = None  # incase no objects are exported, so as not to raise an error
+    tmp_ob_type = None  # incase no objects are exported, so as not to raise an error
 
 ## XXX
 
@@ -2396,7 +2392,7 @@ Connections:  {''')
     start = scene.frame_start
     end = scene.frame_end
     if end < start:
-        start, end = end, st
+        start, end = end, start
 
     # comment the following line, otherwise we dont get the pose
     # if start==end: ANIM_ENABLE = False
@@ -2693,10 +2689,10 @@ Takes:  {''')
         mist_intense = m.intensity
         mist_start = m.start
         mist_end = m.depth
-        mist_height = m.height
+        # mist_height = m.height  # UNUSED
         world_hor = world.horizon_color
     else:
-        has_mist = mist_intense = mist_start = mist_end = mist_height = 0
+        has_mist = mist_intense = mist_start = mist_end = 0
         world_hor = 0, 0, 0
 
     file.write('\n;Version 5 settings')
diff --git a/io_scene_m3/__init__.py b/io_scene_m3/__init__.py
index 78c2498d2..d3501c87c 100644
--- a/io_scene_m3/__init__.py
+++ b/io_scene_m3/__init__.py
@@ -47,7 +47,7 @@ import time
 import datetime
 import bpy
 from bpy.props import StringProperty, BoolProperty
-from bpy_extras.io_utils import ImportHelper, ExportHelper
+from bpy_extras.io_utils import ImportHelper
 
 
 class ImportM3(bpy.types.Operator, ImportHelper):
diff --git a/io_scene_m3/import_m3.py b/io_scene_m3/import_m3.py
index 402128da2..7a7678e89 100644
--- a/io_scene_m3/import_m3.py
+++ b/io_scene_m3/import_m3.py
@@ -52,7 +52,6 @@ Notes:<br>
 """
 
 import bpy
-import mathutils
 import struct
 import os.path
 from bpy.props import *
diff --git a/io_scene_map/__init__.py b/io_scene_map/__init__.py
index 8db02a7f6..d32959988 100644
--- a/io_scene_map/__init__.py
+++ b/io_scene_map/__init__.py
@@ -40,8 +40,8 @@ if "bpy" in locals():
 
 
 import bpy
-from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
-from bpy_extras.io_utils import ExportHelper, axis_conversion
+from bpy.props import StringProperty
+from bpy_extras.io_utils import ExportHelper
 
 
 class ExportMAP(bpy.types.Operator, ExportHelper):
@@ -54,8 +54,8 @@ class ExportMAP(bpy.types.Operator, ExportHelper):
     filter_glob = StringProperty(default="*.map", options={'HIDDEN'})
 
     def execute(self, context):
-        import math
-        from mathutils import Matrix
+        # import math
+        # from mathutils import Matrix
         if not self.filepath:
             raise Exception("filepath not set")
 
diff --git a/io_scene_map/export_map.py b/io_scene_map/export_map.py
index 512e93c7a..0ed01c8da 100644
--- a/io_scene_map/export_map.py
+++ b/io_scene_map/export_map.py
@@ -51,7 +51,6 @@ def write_cube2brush(file, faces):
     these faces can be from 1 mesh, 1 cube within a mesh of larger cubes
     Faces could even come from different meshes or be contrived.
     '''
-    import os
     # comment only
     # file.write('// brush "%s", "%s"\n' % (ob.name, ob.data.name))
     file.write('// brush from cube\n{\n')
@@ -284,7 +283,7 @@ def export_map(context, filepath):
         return
     """
     import time
-    from mathutils import Vector, Matrix
+    from mathutils import Matrix
     from bpy_extras import mesh_utils
 
     t = time.time()
diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index 660a38fca..694c618da 100644
--- a/io_scene_obj/__init__.py
+++ b/io_scene_obj/__init__.py
@@ -104,7 +104,6 @@ class ImportOBJ(bpy.types.Operator, ImportHelper):
     def execute(self, context):
         # print("Selected: " + context.active_object.name)
         from . import import_obj
-        from mathutils import Matrix
 
         if self.split_mode == 'OFF':
             self.use_split_objects = False
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index 594a4167b..a65709072 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -20,7 +20,6 @@
 
 import os
 import time
-import shutil
 
 import bpy
 import mathutils
@@ -239,9 +238,6 @@ def write_file(filepath, objects, scene,
     if EXPORT_GLOBAL_MATRIX is None:
         EXPORT_GLOBAL_MATRIX = mathutils.Matrix()
 
-    # XXX
-    import math
-
     def veckey3d(v):
         return round(v.x, 6), round(v.y, 6), round(v.z, 6)
 
@@ -273,7 +269,6 @@ def write_file(filepath, objects, scene,
             return '(null)'
 
     print('OBJ Export path: %r' % filepath)
-    temp_mesh_name = '~tmp-mesh'
 
     time1 = time.clock()
 #   time1 = sys.time()
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 697c65086..239e92ad4 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -957,7 +957,7 @@ def load(operator, context, filepath,
             else:
                 context_multi_line = b''
 
-            isline = line.startswith(b'l')
+            # isline = line.startswith(b'l')  # UNUSED
 
             for v in line_split:
                 vert_loc_index = int(v) - 1
@@ -1143,6 +1143,3 @@ def load(operator, context, filepath,
 # replaced BPyImage.comprehensiveImageLoad with a simplified version that only checks additional directory specified, but doesn't search dirs recursively (obj_image_load)
 # bitmask won't work? - 132
 # uses bpy.sys.time()
-
-if __name__ == "__main__":
-    register()
diff --git a/io_scene_x3d/__init__.py b/io_scene_x3d/__init__.py
index c176d95c2..c49a86a88 100644
--- a/io_scene_x3d/__init__.py
+++ b/io_scene_x3d/__init__.py
@@ -130,7 +130,6 @@ class ExportX3D(bpy.types.Operator, ExportHelper):
 
     def execute(self, context):
         from . import export_x3d
-        from mathutils import Matrix
 
         keywords = self.as_keywords(ignore=("axis_forward", "axis_up", "check_existing", "filter_glob"))
         global_matrix = axis_conversion(to_forward=self.axis_forward, to_up=self.axis_up).to_4x4()
diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py
index c88210727..823b8ff46 100644
--- a/io_scene_x3d/export_x3d.py
+++ b/io_scene_x3d/export_x3d.py
@@ -1263,7 +1263,7 @@ def export(file,
         ident = '\t\t'
 
         if use_selection:
-            objects = [obj for obj in scene.objects if obj.is_visible(scene) and o.select]
+            objects = [obj for obj in scene.objects if obj.is_visible(scene) and obj.select]
         else:
             objects = [obj for obj in scene.objects if obj.is_visible(scene)]
 
diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py
index 28c0abac5..1ee0e9f5b 100644
--- a/io_scene_x3d/import_x3d.py
+++ b/io_scene_x3d/import_x3d.py
@@ -601,7 +601,6 @@ class vrmlNode(object):
 
         # See if this is a proto name
         if AS_CHILD:
-            child_array = None
             for child in self_real.children:
                 if child.id and len(child.id) == 1 and child.id[0] == field:
                     return child
@@ -1881,7 +1880,7 @@ def importMesh_IndexedLineSet(geom, ancestry):
     for line in lines:
         if not line:
             continue
-        co = points[line[0]]
+        # co = points[line[0]]  # UNUSED
         nu = bpycurve.splines.new('POLY')
         nu.points.add(len(line) - 1)  # the new nu has 1 point to begin with
         for il, pt in zip(line, nu.points):
diff --git a/io_shape_mdd/export_mdd.py b/io_shape_mdd/export_mdd.py
index 85163280d..2a8980cd1 100644
--- a/io_shape_mdd/export_mdd.py
+++ b/io_shape_mdd/export_mdd.py
@@ -49,9 +49,6 @@ def check_vertcount(mesh, vertcount):
     '''
     if len(mesh.vertices) != vertcount:
         raise Exception('Error, number of verts has changed during animation, cannot export')
-        f.close()
-        zero_file(filepath)
-        return
 
 
 def save(operator, context, filepath="", frame_start=1, frame_end=300, fps=25):
diff --git a/io_shape_mdd/import_mdd.py b/io_shape_mdd/import_mdd.py
index 0fdc78cb1..332b75907 100644
--- a/io_shape_mdd/import_mdd.py
+++ b/io_shape_mdd/import_mdd.py
@@ -52,9 +52,7 @@ def load(operator, context, filepath, frame_start=0, frame_step=1):
     print('\tpoints:%d frames:%d' % (points, frames))
 
     # If target object doesn't have Basis shape key, create it.
-    try:
-        num_keys = len(obj.data.shape_keys.keys)
-    except:
+    if not obj.data.shape_keys:
         basis = obj.shape_key_add()
         basis.name = "Basis"
         obj.data.update()
@@ -66,7 +64,6 @@ def load(operator, context, filepath, frame_start=0, frame_step=1):
         # Insert new shape key
         new_shapekey = obj.shape_key_add()
         new_shapekey.name = ("frame_%.4d" % fr)
-        new_shapekey_name = new_shapekey.name
 
         obj.active_shape_key_index = len(obj.data.shape_keys.keys) - 1
         index = len(obj.data.shape_keys.keys) - 1
diff --git a/light_field_tools/__init__.py b/light_field_tools/__init__.py
index 862c399bb..1ca55a592 100644
--- a/light_field_tools/__init__.py
+++ b/light_field_tools/__init__.py
@@ -116,4 +116,3 @@ def unregister():
 
 if __name__ == "__main__":
     register()
-
diff --git a/light_field_tools/light_field_tools.py b/light_field_tools/light_field_tools.py
index dcf44c954..3c2636e7a 100644
--- a/light_field_tools/light_field_tools.py
+++ b/light_field_tools/light_field_tools.py
@@ -403,7 +403,7 @@ class VIEW3D_OT_lightfield_tools(bpy.types.Panel):
         scene = context.scene
 
         layout = self.layout
-        row = layout.row()
+        layout.row()  # XXX, is this needed?
         col = layout.column()
 
         col.prop(scene.lightfield, "row_length")
diff --git a/modules/ui_utils.py b/modules/ui_utils.py
index 1bbb9ef21..15a71a6e7 100644
--- a/modules/ui_utils.py
+++ b/modules/ui_utils.py
@@ -30,7 +30,7 @@ class GUI:
     def drawIconButton(cls, enabled, layout, iconName, operator, frame=True):
         col = layout.column()
         col.enabled = enabled
-        bt = col.operator(operator,
+        col.operator(operator,
             text='',
             icon=iconName,
             emboss=frame)
@@ -39,7 +39,7 @@ class GUI:
     def drawTextButton(cls, enabled, layout, text, operator, frame=True):
         col = layout.column()
         col.enabled = enabled
-        bt = col.operator(operator,
+        col.operator(operator,
             text=text,
             emboss=frame)
 
diff --git a/netrender/client.py b/netrender/client.py
index 651b4660b..265048846 100644
--- a/netrender/client.py
+++ b/netrender/client.py
@@ -17,9 +17,9 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import sys, os, re
-import http, http.client, http.server, urllib
-import subprocess, shutil, time, hashlib
+import os, re
+import http, http.client, http.server
+import time
 import json
 
 import netrender
@@ -96,8 +96,8 @@ def fillCommonJobSettings(job, job_name, netsettings):
     job.name = job_name
     job.category = netsettings.job_category
 
-    for slave in netrender.blacklist:
-        job.blacklist.append(slave.id)
+    for bad_slave in netrender.blacklist:
+        job.blacklist.append(bad_slave.id)
 
     job.chunks = netsettings.chunks
     job.priority = netsettings.priority
diff --git a/netrender/master.py b/netrender/master.py
index 280a4019a..0e406bc0f 100644
--- a/netrender/master.py
+++ b/netrender/master.py
@@ -17,8 +17,8 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import sys, os
-import http, http.client, http.server, urllib, socket, socketserver, threading
-import subprocess, shutil, time, hashlib
+import http, http.client, http.server, socket, socketserver
+import shutil, time, hashlib
 import pickle
 import select # for select.error
 import json
@@ -648,7 +648,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
         # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
         elif self.path == "/slave":
             length = int(self.headers['content-length'])
-            job_frame_string = self.headers['job-frame']
+            # job_frame_string = self.headers['job-frame']  # UNUSED
 
             self.server.stats("", "New slave connected")
 
diff --git a/netrender/master_html.py b/netrender/master_html.py
index da9751841..7d46dd2a7 100644
--- a/netrender/master_html.py
+++ b/netrender/master_html.py
@@ -17,7 +17,6 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import os
-import re
 import shutil
 from netrender.utils import *
 import netrender.model
diff --git a/netrender/model.py b/netrender/model.py
index 5fc0bc2a0..cab619f27 100644
--- a/netrender/model.py
+++ b/netrender/model.py
@@ -16,10 +16,6 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-import sys, os
-import http, http.client, http.server, urllib
-import subprocess, shutil, time, hashlib
-
 import netrender.versioning as versioning
 from netrender.utils import *
 
diff --git a/netrender/operators.py b/netrender/operators.py
index 563da1c5a..718582fbd 100644
--- a/netrender/operators.py
+++ b/netrender/operators.py
@@ -17,8 +17,8 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import sys, os
-import http, http.client, http.server, urllib, socket
+import os
+import http, http.client, http.server
 import webbrowser
 import json
 
@@ -39,13 +39,13 @@ class RENDER_OT_netslave_bake(bpy.types.Operator):
 
     def execute(self, context):
         scene = context.scene
-        netsettings = scene.network_render
+        # netsettings = scene.network_render  # UNUSED
 
         filename = bpy.data.filepath
         path, name = os.path.split(filename)
         root, ext = os.path.splitext(name)
-        default_path = path + os.sep + "blendcache_" + root + os.sep # need an API call for that
-        relative_path = os.sep + os.sep + "blendcache_" + root + os.sep
+        # default_path = path + os.sep + "blendcache_" + root + os.sep # need an API call for that, UNUSED
+        relative_path = "//blendcache_" + root + os.sep
 
         # Force all point cache next to the blend file
         for object in bpy.data.objects:
@@ -410,7 +410,6 @@ class netclientdownload(bpy.types.Operator):
 
     def execute(self, context):
         netsettings = context.scene.network_render
-        rd = context.scene.render
 
         conn = clientConnection(netsettings.server_address, netsettings.server_port, self.report)
 
diff --git a/netrender/repath.py b/netrender/repath.py
index 3ac9636b6..746925549 100644
--- a/netrender/repath.py
+++ b/netrender/repath.py
@@ -22,7 +22,6 @@ import subprocess
 import bpy
 
 from netrender.utils import *
-import netrender.model
 
 BLENDER_PATH = sys.argv[0]
 
diff --git a/netrender/slave.py b/netrender/slave.py
index 7f72530ea..6fef4f4e4 100644
--- a/netrender/slave.py
+++ b/netrender/slave.py
@@ -17,7 +17,7 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import sys, os, platform, shutil
-import http, http.client, http.server, urllib
+import http, http.client, http.server
 import subprocess, time
 import json
 
@@ -121,7 +121,7 @@ def breakable_timeout(timeout):
             break
 
 def render_slave(engine, netsettings, threads):
-    timeout = 1
+    # timeout = 1  # UNUSED
     
     bisleep = BreakableIncrementedSleep(INCREMENT_TIMEOUT, 1, MAX_TIMEOUT, engine.test_break)
 
@@ -140,7 +140,7 @@ def render_slave(engine, netsettings, threads):
     conn = clientConnection(netsettings.server_address, netsettings.server_port)
     
     if not conn:
-        timeout = 1
+        # timeout = 1  # UNUSED
         print("Connection failed, will try connecting again at most %i times" % MAX_CONNECT_TRY)
         bisleep.reset()
         
diff --git a/netrender/thumbnail.py b/netrender/thumbnail.py
index 2ead6e827..11fe0ec95 100644
--- a/netrender/thumbnail.py
+++ b/netrender/thumbnail.py
@@ -23,7 +23,7 @@ import bpy
 
 def generate(filename, external=True):
     if external:
-        process = subprocess.Popen([sys.argv[0], "-b", "-noaudio", "-P", __file__, "--", filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+        process = subprocess.Popen([sys.argv[0],"-b", "-noaudio", "-P", __file__, "--", filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         while process.poll() is None:
             process.stdout.read(1024) # empty buffer to be sure
         process.stdout.read()
@@ -72,7 +72,6 @@ def _internal(filename):
     return None
 
 if __name__ == "__main__":
-    import bpy
     try:
         start = sys.argv.index("--") + 1
     except ValueError:
diff --git a/netrender/ui.py b/netrender/ui.py
index 6993173d3..068d77b3e 100644
--- a/netrender/ui.py
+++ b/netrender/ui.py
@@ -17,16 +17,15 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import sys, os
-import http, http.client, http.server, urllib
-import subprocess, shutil, time, hashlib
+import os
+import time
 
 import netrender
-import netrender.slave as slave
-import netrender.master as master
 
 from netrender.utils import *
 
+from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, IntProperty, CollectionProperty
+
 VERSION = b"0.3"
 
 PATH_PREFIX = "/tmp/"
@@ -361,7 +360,6 @@ class RENDER_PT_network_output(NeedValidAddress, NetRenderButtonsPanel, bpy.type
 class NetRenderSlave(bpy.types.PropertyGroup):
     @classmethod
     def register(NetRenderSlave):
-        from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, IntProperty, CollectionProperty
 
         NetRenderSlave.name = StringProperty(
                         name="Name of the slave",
@@ -372,7 +370,6 @@ class NetRenderSlave(bpy.types.PropertyGroup):
 class NetRenderJob(bpy.types.PropertyGroup):
     @classmethod
     def register(NetRenderJob):
-        from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, IntProperty, CollectionProperty
 
         NetRenderJob.name = StringProperty(
                         name="Name of the job",
@@ -383,7 +380,6 @@ class NetRenderJob(bpy.types.PropertyGroup):
 class NetRenderSettings(bpy.types.PropertyGroup):
     @classmethod
     def register(NetRenderSettings):
-        from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, IntProperty, CollectionProperty
 
         def address_update_callback(self, context):
             netsettings = context.scene.network_render
diff --git a/netrender/utils.py b/netrender/utils.py
index b0c8eb0b2..d615685af 100644
--- a/netrender/utils.py
+++ b/netrender/utils.py
@@ -17,9 +17,8 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import sys, os
-import re
-import http, http.client, http.server, urllib, socket
-import subprocess, shutil, time, hashlib, zlib
+import http, http.client, http.server, socket
+import subprocess, time, hashlib
 
 import netrender, netrender.model
 
diff --git a/netrender/versioning.py b/netrender/versioning.py
index d4892e3ed..31bb2f8b8 100644
--- a/netrender/versioning.py
+++ b/netrender/versioning.py
@@ -1,4 +1,22 @@
-import sys, os
+# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import os
 import re
 import subprocess
 
diff --git a/object_fracture/fracture_ops.py b/object_fracture/fracture_ops.py
index c7a842793..69fd49daf 100644
--- a/object_fracture/fracture_ops.py
+++ b/object_fracture/fracture_ops.py
@@ -20,7 +20,6 @@ import bpy
 from bpy.props import *
 import os
 import random
-import mathutils
 from mathutils import *
 
 
@@ -116,7 +115,6 @@ def getsizefrommesh(ob):
 
 def getIslands(shard):
     sm = shard.data
-    islands = []
     vgroups = []
     fgroups = []
 
diff --git a/render_povray/render.py b/render_povray/render.py
index beeb9d673..f651a6fb6 100644
--- a/render_povray/render.py
+++ b/render_povray/render.py
@@ -123,7 +123,6 @@ def findInSubDir(filename, subdirectory=""):
 def path_image(image):
     import os
     fn = bpy.path.abspath(image)
-    fn_strip = os.path.basename(fn)
     if not os.path.isfile(fn):
         fn = findInSubDir(os.path.basename(fn), os.path.dirname(bpy.data.filepath))
     fn = os.path.realpath(fn)
@@ -1066,23 +1065,23 @@ def write_pov(filename, scene=None, info_callback=None):
                         if image_filename:
                             if t.use_map_color_diffuse:
                                 texturesDif = image_filename
-                                colvalue = t.default_value
+                                # colvalue = t.default_value  # UNUSED
                                 t_dif = t
                                 if t_dif.texture.pov.tex_gamma_enable:
                                     imgGamma = (" gamma %.3g " % t_dif.texture.pov.tex_gamma_value)
                             if t.use_map_specular or t.use_map_raymir:
                                 texturesSpec = image_filename
-                                colvalue = t.default_value
+                                # colvalue = t.default_value  # UNUSED
                                 t_spec = t
                             if t.use_map_normal:
                                 texturesNorm = image_filename
-                                colvalue = t.normal_factor * 10.0
+                                # colvalue = t.normal_factor * 10.0  # UNUSED
                                 #textNormName=t.texture.image.name + ".normal"
                                 #was the above used? --MR
                                 t_nor = t
                             if t.use_map_alpha:
                                 texturesAlpha = image_filename
-                                colvalue = t.alpha_factor * 10.0
+                                # colvalue = t.alpha_factor * 10.0  # UNUSED
                                 #textDispName=t.texture.image.name + ".displ"
                                 #was the above used? --MR
                                 t_alpha = t
diff --git a/render_povray/ui.py b/render_povray/ui.py
index 336424bd3..185249ade 100644
--- a/render_povray/ui.py
+++ b/render_povray/ui.py
@@ -169,7 +169,6 @@ class RENDER_PT_povray_export_settings(RenderButtonsPanel, bpy.types.Panel):
         layout = self.layout
 
         scene = context.scene
-        rd = scene.render
 
         layout.active = scene.pov.max_trace_level
         split = layout.split()
@@ -217,7 +216,6 @@ class RENDER_PT_povray_render_settings(RenderButtonsPanel, bpy.types.Panel):
         layout = self.layout
 
         scene = context.scene
-        rd = scene.render
 
         layout.active = scene.pov.max_trace_level
 
@@ -254,7 +252,6 @@ class RENDER_PT_povray_antialias(RenderButtonsPanel, bpy.types.Panel):
         layout = self.layout
 
         scene = context.scene
-        rd = scene.render
 
         layout.active = scene.pov.antialias_enable
 
@@ -290,7 +287,6 @@ class RENDER_PT_povray_radiosity(RenderButtonsPanel, bpy.types.Panel):
         layout = self.layout
 
         scene = context.scene
-        rd = scene.render
 
         layout.active = scene.pov.radio_enable
 
@@ -342,7 +338,6 @@ class RENDER_PT_povray_media(RenderButtonsPanel, bpy.types.Panel):
         layout = self.layout
 
         scene = context.scene
-        rd = scene.render
 
         layout.active = scene.pov.media_enable
 
@@ -420,10 +415,10 @@ class MATERIAL_PT_povray_fade_color(MaterialButtonsPanel, bpy.types.Panel):
         self.layout.prop(mat.pov, "interior_fade_color", text="")
 
     def draw(self, context):
-        layout = self.layout
-
-        mat = context.material
-        #layout.active = mat.pov.interior_fade_color
+        # layout = self.layout
+        # mat = context.material
+        # layout.active = mat.pov.interior_fade_color
+        pass
 
 
 class MATERIAL_PT_povray_conserve_energy(MaterialButtonsPanel, bpy.types.Panel):
diff --git a/rigify/__init__.py b/rigify/__init__.py
index 1de834aad..c7b02d6c1 100644
--- a/rigify/__init__.py
+++ b/rigify/__init__.py
@@ -41,7 +41,6 @@ else:
     from . import generate, ui, utils, metarig_menu
 
 import bpy
-import bpy_types
 import os
 
 
diff --git a/rigify/generate.py b/rigify/generate.py
index 153162bce..0d2e2443e 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -60,7 +60,7 @@ def generate_rig(context, metarig):
     rig_id = random_id(16)
 
     # Initial configuration
-    mode_orig = context.mode
+    # mode_orig = context.mode  # UNUSED
     rest_backup = metarig.data.pose_position
     metarig.data.pose_position = 'REST'
 
@@ -350,7 +350,7 @@ def generate_rig(context, metarig):
 
     # Ensure the collection of layer names exists
     for i in range(1 + len(metarig.data.rigify_layers), 29):
-        layer = metarig.data.rigify_layers.add()
+        metarig.data.rigify_layers.add()
 
     # Create list of layer name/row pairs
     layer_layout = []
@@ -401,7 +401,7 @@ def get_bone_rigs(obj, bone_name, halt_on_missing=False):
         try:
             rig = get_rig_type(rig_type).Rig(obj, bone_name, params)
         except ImportError:
-            message = "Rig Type Missing: python module for type '%s' not found (bone: %s)" % (t, bone_name)
+            message = "Rig Type Missing: python module for type '%s' not found (bone: %s)" % (rig_type, bone_name)
             if halt_on_missing:
                 raise MetarigError(message)
             else:
diff --git a/rigify/metarig_menu.py b/rigify/metarig_menu.py
index 56b82370a..fefb4bd61 100644
--- a/rigify/metarig_menu.py
+++ b/rigify/metarig_menu.py
@@ -17,9 +17,7 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import mathutils
 from rigify.metarigs import human
-from math import cos, sin, pi
 
 
 class AddHuman(bpy.types.Operator):
diff --git a/rigify/rigs/basic/copy.py b/rigify/rigs/basic/copy.py
index 22beedf12..d430113b5 100644
--- a/rigify/rigs/basic/copy.py
+++ b/rigify/rigs/basic/copy.py
@@ -17,7 +17,6 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-from rigify.utils import MetarigError
 from rigify.utils import copy_bone
 from rigify.utils import strip_org, make_deformer_name
 from rigify.utils import create_bone_widget
@@ -57,8 +56,9 @@ class Rig:
 
         # Get edit bones
         eb = self.obj.data.edit_bones
-        if self.make_control:
-            bone_e = eb[bone]
+        # UNUSED
+        # if self.make_control:
+        #     bone_e = eb[bone]
         if self.make_deform:
             def_bone_e = eb[def_bone]
 
diff --git a/rigify/rigs/basic/copy_chain.py b/rigify/rigs/basic/copy_chain.py
index 4910ef827..b1dbcd838 100644
--- a/rigify/rigs/basic/copy_chain.py
+++ b/rigify/rigs/basic/copy_chain.py
@@ -40,7 +40,7 @@ class Rig:
         self.make_deforms = params.make_deforms
 
         if len(self.org_bones) <= 1:
-            raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone)))
+            raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone_name)))
 
     def generate(self):
         """ Generate the rig.
diff --git a/rigify/rigs/biped/arm/__init__.py b/rigify/rigs/biped/arm/__init__.py
index 93e757f4e..74677af0c 100644
--- a/rigify/rigs/biped/arm/__init__.py
+++ b/rigify/rigs/biped/arm/__init__.py
@@ -19,7 +19,6 @@
 import bpy
 import imp
 from . import fk, ik, deform
-from rigify.utils import MetarigError, get_layers
 
 imp.reload(fk)
 imp.reload(ik)
diff --git a/rigify/rigs/biped/arm/deform.py b/rigify/rigs/biped/arm/deform.py
index 2a7b31091..0e6713591 100644
--- a/rigify/rigs/biped/arm/deform.py
+++ b/rigify/rigs/biped/arm/deform.py
@@ -17,10 +17,10 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-from math import acos, degrees
+from math import acos
 from mathutils import Vector, Matrix
 from rigify.utils import MetarigError
-from rigify.utils import copy_bone, flip_bone, put_bone
+from rigify.utils import copy_bone, put_bone
 from rigify.utils import connected_children_names
 from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
 
@@ -197,7 +197,7 @@ class Rig:
             uarm1_p = pb[uarm1]
         if self.use_forearm_twist:
             farm2_p = pb[farm2]
-        hand_p = pb[hand]
+        # hand_p = pb[hand]  # UNUSED
 
         # Upper arm constraints
         if self.use_upper_arm_twist:
diff --git a/rigify/rigs/biped/arm/fk.py b/rigify/rigs/biped/arm/fk.py
index 2c634b866..214d76820 100644
--- a/rigify/rigs/biped/arm/fk.py
+++ b/rigify/rigs/biped/arm/fk.py
@@ -17,11 +17,10 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-import math
 from rigify.utils import MetarigError
-from rigify.utils import copy_bone, flip_bone, put_bone
+from rigify.utils import copy_bone
 from rigify.utils import connected_children_names
-from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
+from rigify.utils import strip_org, make_mechanism_name
 from rigify.utils import get_layers
 from rigify.utils import create_widget, create_limb_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
@@ -124,7 +123,7 @@ class Rig:
             hinge_p = pb[hinge]
 
         if self.org_parent != None:
-            socket1_p = pb[socket1]
+            # socket1_p = pb[socket1]  # UNUSED
             socket2_p = pb[socket2]
 
         # Set the elbow to only bend on the x-axis.
diff --git a/rigify/rigs/biped/arm/ik.py b/rigify/rigs/biped/arm/ik.py
index 0ecf70e75..fb784b7d7 100644
--- a/rigify/rigs/biped/arm/ik.py
+++ b/rigify/rigs/biped/arm/ik.py
@@ -23,7 +23,6 @@ from rigify.utils import MetarigError
 from rigify.utils import copy_bone
 from rigify.utils import connected_children_names
 from rigify.utils import strip_org, make_mechanism_name, insert_before_lr
-from rigify.utils import get_layers
 from rigify.utils import create_widget, create_line_widget, create_sphere_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
 
@@ -169,7 +168,7 @@ class Rig:
         bpy.ops.object.mode_set(mode='OBJECT')
         pb = self.obj.pose.bones
 
-        uarm_p = pb[uarm]
+        # uarm_p = pb[uarm]  # UNUSED
         farm_p = pb[farm]
         hand_p = pb[hand]
         pole_p = pb[pole]
diff --git a/rigify/rigs/biped/leg/__init__.py b/rigify/rigs/biped/leg/__init__.py
index 8f9286c71..21c5fa2b1 100644
--- a/rigify/rigs/biped/leg/__init__.py
+++ b/rigify/rigs/biped/leg/__init__.py
@@ -19,7 +19,6 @@
 import bpy
 import imp
 from . import fk, ik, deform
-from rigify.utils import MetarigError, get_layers
 
 imp.reload(fk)
 imp.reload(ik)
diff --git a/rigify/rigs/biped/leg/deform.py b/rigify/rigs/biped/leg/deform.py
index bb6b6f398..d0f98e4a3 100644
--- a/rigify/rigs/biped/leg/deform.py
+++ b/rigify/rigs/biped/leg/deform.py
@@ -17,10 +17,10 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-from math import acos, degrees
+from math import acos
 from mathutils import Vector, Matrix
 from rigify.utils import MetarigError
-from rigify.utils import copy_bone, flip_bone, put_bone
+from rigify.utils import copy_bone, put_bone
 from rigify.utils import connected_children_names, has_connected_children
 from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
 
@@ -231,7 +231,7 @@ class Rig:
             thigh1_p = pb[thigh1]
         if self.use_shin_twist:
             shin2_p = pb[shin2]
-        foot_p = pb[foot]
+        # foot_p = pb[foot]  # UNUSED
 
         # Thigh constraints
         if self.use_thigh_twist:
diff --git a/rigify/rigs/biped/leg/fk.py b/rigify/rigs/biped/leg/fk.py
index f2ce6653d..0e51b501c 100644
--- a/rigify/rigs/biped/leg/fk.py
+++ b/rigify/rigs/biped/leg/fk.py
@@ -17,12 +17,11 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-import math
 from mathutils import Vector
 from rigify.utils import MetarigError
-from rigify.utils import copy_bone, flip_bone, put_bone
+from rigify.utils import copy_bone
 from rigify.utils import connected_children_names, has_connected_children
-from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
+from rigify.utils import strip_org, make_mechanism_name
 from rigify.utils import get_layers
 from rigify.utils import create_widget, create_limb_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
@@ -162,7 +161,7 @@ class Rig:
             hinge_p = pb[hinge]
 
         if self.org_parent != None:
-            socket1_p = pb[socket1]
+            # socket1_p = pb[socket1]  # UNUSED
             socket2_p = pb[socket2]
 
         # Set the knee to only bend on the x-axis.
diff --git a/rigify/rigs/biped/leg/ik.py b/rigify/rigs/biped/leg/ik.py
index 54869b8e4..806de4174 100644
--- a/rigify/rigs/biped/leg/ik.py
+++ b/rigify/rigs/biped/leg/ik.py
@@ -23,7 +23,6 @@ from rigify.utils import MetarigError
 from rigify.utils import copy_bone, flip_bone, put_bone
 from rigify.utils import connected_children_names, has_connected_children
 from rigify.utils import strip_org, make_mechanism_name, insert_before_lr
-from rigify.utils import get_layers
 from rigify.utils import create_widget, create_line_widget, create_sphere_widget, create_circle_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
 
@@ -322,7 +321,7 @@ class Rig:
         bpy.ops.object.mode_set(mode='OBJECT')
         pb = self.obj.pose.bones
 
-        thigh_p = pb[thigh]
+        # thigh_p = pb[thigh]  # UNUSED
         shin_p = pb[shin]
         foot_p = pb[foot]
         pole_p = pb[pole]
diff --git a/rigify/rigs/finger.py b/rigify/rigs/finger.py
index 0bcea44bb..c33fdfd90 100644
--- a/rigify/rigs/finger.py
+++ b/rigify/rigs/finger.py
@@ -22,8 +22,7 @@ from rigify.utils import MetarigError
 from rigify.utils import copy_bone
 from rigify.utils import connected_children_names
 from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
-from rigify.utils import get_layers
-from rigify.utils import create_widget, create_line_widget, create_limb_widget
+from rigify.utils import create_widget, create_limb_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
 import re
 
diff --git a/rigify/rigs/misc/delta.py b/rigify/rigs/misc/delta.py
index dc8edd415..12bd69cec 100644
--- a/rigify/rigs/misc/delta.py
+++ b/rigify/rigs/misc/delta.py
@@ -59,7 +59,7 @@ class Rig:
 
         org_delta = self.org_bones["delta"]
         org_delta_e = eb[self.org_bones["delta"]]
-        org_child = self.org_bones["child"]
+        # org_child = self.org_bones["child"]  # UNUSED
         org_child_e = eb[self.org_bones["child"]]
 
         # Calculate the matrix for achieving the delta
diff --git a/rigify/rigs/neck_short.py b/rigify/rigs/neck_short.py
index 58191e6a9..b5ffc4535 100644
--- a/rigify/rigs/neck_short.py
+++ b/rigify/rigs/neck_short.py
@@ -17,9 +17,8 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-from mathutils import Vector
 from rigify.utils import MetarigError
-from rigify.utils import copy_bone, new_bone, flip_bone, put_bone
+from rigify.utils import copy_bone, new_bone, put_bone
 from rigify.utils import connected_children_names
 from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
 from rigify.utils import obj_to_bone, create_circle_widget
@@ -54,7 +53,7 @@ class Rig:
         self.params = params
 
         if len(self.org_bones) <= 1:
-            raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone)))
+            raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone_name)))
 
         self.isolate = False
         if self.obj.data.bones[bone_name].parent:
@@ -176,10 +175,10 @@ class Rig:
         pb = self.obj.pose.bones
         neck_ctrl_p = pb[neck_ctrl]
         neck_follow_p = pb[neck_follow]
-        neck_child_p = pb[neck_child]
+        # neck_child_p = pb[neck_child]  # UNUSED
         head_ctrl_p = pb[head_ctrl]
         if self.isolate:
-            head_socket1_p = pb[head_socket1]
+            # head_socket1_p = pb[head_socket1]  # UNUSED
             head_socket2_p = pb[head_socket2]
 
         # Custom bone appearance
diff --git a/rigify/rigs/palm.py b/rigify/rigs/palm.py
index d1a3cf615..6ad72f4e1 100644
--- a/rigify/rigs/palm.py
+++ b/rigify/rigs/palm.py
@@ -17,10 +17,10 @@
 #======================= END GPL LICENSE BLOCK ========================
 
 import bpy
-from math import sin, cos, pi
+from math import cos, pi
 from rigify.utils import MetarigError
 from rigify.utils import copy_bone
-from rigify.utils import strip_org, deformer, mch
+from rigify.utils import strip_org, deformer
 from rigify.utils import create_widget
 import re
 
diff --git a/rigify/rigs/spine.py b/rigify/rigs/spine.py
index 86d9ba6cd..740cfa7ea 100644
--- a/rigify/rigs/spine.py
+++ b/rigify/rigs/spine.py
@@ -75,7 +75,7 @@ class Rig:
         self.pivot_rest = min(self.pivot_rest, 1.0-(1.0/len(self.org_bones)))
 
         if len(self.org_bones) <= 1:
-            raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone)))
+            raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone_name)))
 
     def gen_deform(self):
         """ Generate the deformation rig.
diff --git a/rigify/ui.py b/rigify/ui.py
index 3a2e89e3d..7551ce86d 100644
--- a/rigify/ui.py
+++ b/rigify/ui.py
@@ -21,7 +21,6 @@ from bpy.props import *
 import rigify
 from rigify.utils import get_rig_type
 from rigify import generate
-from rna_prop_ui import rna_idprop_ui_prop_get
 
 
 class DATA_PT_rigify_buttons(bpy.types.Panel):
@@ -58,7 +57,7 @@ class DATA_PT_rigify_buttons(bpy.types.Panel):
                 id_store.rigify_types.remove(0)
 
             for r in rigify.rig_list:
-                collection = r.split('.')[0]
+                # collection = r.split('.')[0]  # UNUSED
                 if collection_name == "All":
                     a = id_store.rigify_types.add()
                     a.name = r
@@ -95,13 +94,12 @@ class DATA_PT_rigify_layer_names(bpy.types.Panel):
         return True
 
     def draw(self, context):
-        C = context
         layout = self.layout
         obj = context.object
 
         # Ensure that the layers exist
         for i in range(1 + len(obj.data.rigify_layers), 29):
-            layer = obj.data.rigify_layers.add()
+            obj.data.rigify_layers.add()
 
         # UI
         for i in range(28):
@@ -151,7 +149,7 @@ class BONE_PT_rigify_buttons(bpy.types.Panel):
             id_store.rigify_types.remove(0)
 
         for r in rigify.rig_list:
-            collection = r.split('.')[0]
+            # collection = r.split('.')[0]  # UNUSED
             if collection_name == "All":
                 a = id_store.rigify_types.add()
                 a.name = r
diff --git a/rigify/utils.py b/rigify/utils.py
index 311ef24dc..d9135271f 100644
--- a/rigify/utils.py
+++ b/rigify/utils.py
@@ -21,7 +21,6 @@ import imp
 import random
 import time
 from mathutils import Vector
-from math import ceil, floor
 from rna_prop_ui import rna_idprop_ui_prop_get
 
 RIG_DIR = "rigs"  # Name of the directory where rig types are kept
@@ -386,7 +385,7 @@ def copy_attributes(a, b):
         and key != "bl_rna":
             try:
                 setattr(b, key, getattr(a, key))
-            except AttributeError as e:
+            except AttributeError:
                 pass
 
 
diff --git a/space_view3d_math_vis/__init__.py b/space_view3d_math_vis/__init__.py
index a79f1eee3..10ba8d4b2 100644
--- a/space_view3d_math_vis/__init__.py
+++ b/space_view3d_math_vis/__init__.py
@@ -50,7 +50,6 @@ class VIEW3D_PT_math_vis(bpy.types.Panel):
 
     def draw(self, context):
         layout = self.layout
-        view = context.space_data
 
         col = layout.column(align=True)
 
diff --git a/space_view3d_math_vis/utils.py b/space_view3d_math_vis/utils.py
index b0a7757db..08a2427f1 100644
--- a/space_view3d_math_vis/utils.py
+++ b/space_view3d_math_vis/utils.py
@@ -16,8 +16,6 @@
 #
 #======================= END GPL LICENSE BLOCK ========================
 
-import sys
-
 def console_namespace():
     import console_python
     get_consoles = console_python.get_console
diff --git a/system_blend_info.py b/system_blend_info.py
index 6ba16738a..ad96887c5 100644
--- a/system_blend_info.py
+++ b/system_blend_info.py
@@ -66,10 +66,8 @@ class OBJECT_PT_blendinfo(bpy.types.Panel):
     bl_context = "scene"
 
     def draw(self, context):
-        amount = 2
         ob_cols = []
         db_cols = []
-        etc_cols = []
 
         objects = bpy.data.objects
 
@@ -129,7 +127,7 @@ class OBJECT_PT_blendinfo(bpy.types.Panel):
         row.label(text=quantity_string(num, "Empty", "Empties"),
             icon='EMPTY_DATA')
 
-        l_row_sep = layout.separator()
+        layout.separator()
         
         # DATABLOCKS
 
diff --git a/system_demo_mode/__init__.py b/system_demo_mode/__init__.py
index 902ed37b0..2d0f8149b 100644
--- a/system_demo_mode/__init__.py
+++ b/system_demo_mode/__init__.py
@@ -41,7 +41,6 @@ if "bpy" in locals():
 
 import bpy
 from bpy.props import StringProperty, BoolProperty, IntProperty, FloatProperty, EnumProperty
-from bpy_extras.io_utils import ImportHelper
 
 
 class DemoModeSetup(bpy.types.Operator):
@@ -83,8 +82,6 @@ class DemoModeSetup(bpy.types.Operator):
         from . import config
 
         keywords = self.as_keywords(ignore=("filepath", "random_order", "run"))
-
-        from . import config
         cfg_str, dirpath = config.as_string(self.filepath, self.random_order, **keywords)
         text = bpy.data.texts.get("demo.py")
         if text:
-- 
GitLab