[Bf-extensions-cvs] [3d89a38c] master: Rigify: finish clearing out warnings in functional code.

Alexander Gavrilov noreply at git.blender.org
Mon Nov 21 00:24:22 CET 2022


Commit: 3d89a38c195ababf2a87bc1951c032551507a6b0
Author: Alexander Gavrilov
Date:   Mon Nov 21 00:01:25 2022 +0200
Branches: master
https://developer.blender.org/rBA3d89a38c195ababf2a87bc1951c032551507a6b0

Rigify: finish clearing out warnings in functional code.

===================================================================

M	rigify/__init__.py
M	rigify/base_rig.py
M	rigify/feature_set_list.py
M	rigify/metarig_menu.py
M	rigify/operators/__init__.py
M	rigify/operators/action_layers.py
M	rigify/operators/copy_mirror_parameters.py
M	rigify/operators/generic_ui_list.py
M	rigify/operators/upgrade_face.py
M	rigify/rig_lists.py
M	rigify/rot_mode.py
M	rigify/ui.py
M	rigify/utils/misc.py
M	rigify/utils/rig.py

===================================================================

diff --git a/rigify/__init__.py b/rigify/__init__.py
index 9bb2eab4..66fe8f91 100644
--- a/rigify/__init__.py
+++ b/rigify/__init__.py
@@ -3,7 +3,7 @@
 bl_info = {
     "name": "Rigify",
     "version": (0, 6, 6),
-    "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello, Alexander Gavrilov",
+    "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello, Alexander Gavrilov",  # noqa
     "blender": (3, 0, 0),
     "description": "Automatic rigging from building-block components",
     "location": "Armature properties, Bone properties, View3d tools panel, Armature Add menu",
@@ -14,6 +14,7 @@ bl_info = {
 import importlib
 import sys
 import bpy
+import typing
 
 
 # The order in which core modules of the addon are loaded and reloaded.
@@ -56,6 +57,7 @@ def get_loaded_modules():
     prefix = __name__ + '.'
     return [name for name in sys.modules if name.startswith(prefix)]
 
+
 def reload_modules():
     fixed_modules = set(reload_list)
 
@@ -66,7 +68,8 @@ def reload_modules():
     for name in reload_list:
         importlib.reload(sys.modules[name])
 
-def compare_module_list(a, b):
+
+def compare_module_list(a: list[str], b: list[str]):
     # HACK: ignore the "utils" module when comparing module load orders,
     # because it is inconsistent for reasons unknown.
     # See rBAa918332cc3f821f5a70b1de53b65dd9ca596b093.
@@ -77,19 +80,22 @@ def compare_module_list(a, b):
     b_copy.remove(utils_module_name)
     return a_copy == b_copy
 
-def load_initial_modules():
-    load_list = [ __name__ + '.' + name for name in initial_load_order ]
 
-    for i, name in enumerate(load_list):
+def load_initial_modules() -> list[str]:
+    names = [__name__ + '.' + name for name in initial_load_order]
+
+    for i, name in enumerate(names):
         importlib.import_module(name)
 
         module_list = get_loaded_modules()
-        expected_list = load_list[0 : max(11, i+1)]
+        expected_list = names[0: max(11, i+1)]
 
         if not compare_module_list(module_list, expected_list):
-            print('!!! RIGIFY: initial load order mismatch after '+name+' - expected: \n', expected_list, '\nGot:\n', module_list)
+            print(f'!!! RIGIFY: initial load order mismatch after {name} - expected: \n',
+                  expected_list, '\nGot:\n', module_list)
+
+    return names
 
-    return load_list
 
 def load_rigs():
     rig_lists.get_internal_rigs()
@@ -101,18 +107,20 @@ if "reload_list" in locals():
 else:
     load_list = load_initial_modules()
 
-    from . import (base_rig, base_generate, rig_ui_template, feature_set_list, rig_lists, generate, ui, metarig_menu)
+    from . import (utils, base_rig, base_generate, rig_ui_template, feature_set_list, rig_lists,
+                   generate, ui, metarig_menu, operators)
 
     reload_list = reload_list_init = get_loaded_modules()
 
     if not compare_module_list(reload_list, load_list):
-        print('!!! RIGIFY: initial load order mismatch - expected: \n', load_list, '\nGot:\n', reload_list)
+        print('!!! RIGIFY: initial load order mismatch - expected: \n',
+              load_list, '\nGot:\n', reload_list)
 
 load_rigs()
 
 
-from bpy.types import AddonPreferences
-from bpy.props import (
+from bpy.types import AddonPreferences  # noqa: E402
+from bpy.props import (                 # noqa: E402
     BoolProperty,
     IntProperty,
     EnumProperty,
@@ -132,24 +140,26 @@ class RigifyFeatureSets(bpy.types.PropertyGroup):
     name: bpy.props.StringProperty()
     module_name: bpy.props.StringProperty()
 
-    def toggle_featureset(self, context):
+    def toggle_feature_set(self, context):
         feature_set_list.call_register_function(self.module_name, self.enabled)
-        context.preferences.addons[__package__].preferences.update_external_rigs()
+        RigifyPreferences.get_instance(context).update_external_rigs()
 
     enabled: bpy.props.BoolProperty(
-        name = "Enabled",
-        description = "Whether this feature-set is registered or not",
-        update = toggle_featureset,
-        default = True
+        name="Enabled",
+        description="Whether this feature-set is registered or not",
+        update=toggle_feature_set,
+        default=True
     )
 
 
+# noinspection PyPep8Naming, SpellCheckingInspection
 class RIGIFY_UL_FeatureSets(bpy.types.UIList):
+    # noinspection PyMethodOverriding
     def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
-        rigify_prefs = data
-        feature_sets = rigify_prefs.rigify_feature_sets
-        active_set = feature_sets[rigify_prefs.active_feature_set_index]
-        feature_set_entry = item
+        # rigify_prefs: RigifyPreferences = data
+        # feature_sets = rigify_prefs.rigify_feature_sets
+        # active_set: RigifyFeatureSets = feature_sets[rigify_prefs.active_feature_set_index]
+        feature_set_entry: RigifyFeatureSets = item
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             row = layout.row()
             row.prop(feature_set_entry, 'name', text="", emboss=False)
@@ -160,16 +170,23 @@ class RIGIFY_UL_FeatureSets(bpy.types.UIList):
         elif self.layout_type in {'GRID'}:
             pass
 
+
 class RigifyPreferences(AddonPreferences):
     # this must match the addon name, use '__package__'
     # when defining this in a submodule of a python package.
     bl_idname = __name__
 
-    def register_feature_sets(self, register):
+    @staticmethod
+    def get_instance(context: bpy.types.Context = None) -> 'RigifyPreferences':
+        prefs = (context or bpy.context).preferences.addons[__package__].preferences
+        assert isinstance(prefs, RigifyPreferences)
+        return prefs
+
+    def register_feature_sets(self, do_register: bool):
         """Call register or unregister of external feature sets"""
         self.refresh_installed_feature_sets()
         for set_name in feature_set_list.get_enabled_modules_names():
-            feature_set_list.call_register_function(set_name, register)
+            feature_set_list.call_register_function(set_name, do_register)
 
     def refresh_installed_feature_sets(self):
         """Synchronize preferences entries with what's actually in the file system."""
@@ -180,7 +197,8 @@ class RigifyPreferences(AddonPreferences):
         # If there is a feature set preferences entry with no corresponding
         # installed module, user must've manually removed it from the filesystem,
         # so let's remove such entries.
-        to_delete = [ i for i, fs in enumerate(feature_set_prefs) if fs.module_name not in module_names ]
+        to_delete = [i for i, fs in enumerate(feature_set_prefs)
+                     if fs.module_name not in module_names]
         for i in reversed(to_delete):
             feature_set_prefs.remove(i)
 
@@ -216,8 +234,8 @@ class RigifyPreferences(AddonPreferences):
     rigify_feature_sets: bpy.props.CollectionProperty(type=RigifyFeatureSets)
     active_feature_set_index: IntProperty()
 
-    def draw(self, context):
-        layout = self.layout
+    def draw(self, context: bpy.types.Context):
+        layout: bpy.types.UILayout = self.layout
 
         layout.label(text="Feature Sets:")
 
@@ -231,7 +249,7 @@ class RigifyPreferences(AddonPreferences):
             self, 'active_feature_set_index'
         )
 
-        # Clamp active index to ensure it's in bounds.
+        # Clamp active index to ensure it is in bounds.
         self.active_feature_set_index = max(0, min(self.active_feature_set_index, len(self.rigify_feature_sets)-1))
 
         if len(self.rigify_feature_sets) > 0:
@@ -241,10 +259,10 @@ class RigifyPreferences(AddonPreferences):
                 draw_feature_set_prefs(layout, context, active_fs)
 
 
-def draw_feature_set_prefs(layout, context, featureset: RigifyFeatureSets):
-    info = feature_set_list.get_info_dict(featureset.module_name)
+def draw_feature_set_prefs(layout: bpy.types.UILayout, _context, feature_set: RigifyFeatureSets):
+    info = feature_set_list.get_info_dict(feature_set.module_name)
 
-    description = featureset.name
+    description = feature_set.name
     if 'description' in info:
         description = info['description']
 
@@ -255,7 +273,7 @@ def draw_feature_set_prefs(layout, context, featureset: RigifyFeatureSets):
     split.label(text="Description:")
     split.label(text=description)
 
-    mod = feature_set_list.get_module_safe(featureset.module_name)
+    mod = feature_set_list.get_module_safe(feature_set.module_name)
     if mod:
         split = col.row().split(factor=split_factor)
         split.label(text="File:")
@@ -322,7 +340,6 @@ class RigifyColorSet(bpy.types.PropertyGroup):
 
 
 class RigifySelectionColors(bpy.types.PropertyGroup):
-
     select: FloatVectorProperty(
         name="object_color",
         subtype='COLOR',
@@ -343,10 +360,12 @@ class RigifySelectionColors(bpy.types.PropertyGroup):
 class RigifyParameters(bpy.types.PropertyGroup):
     name: StringProperty()
 
+
 # Parameter update callback
 
 in_update = False
 
+
 def update_callback(prop_name):
     from .utils.rig import get_rigify_type
 
@@ -369,11 +388,12 @@ def update_callback(prop_name):
 
     return callback
 
+
 # Remember the initial property set
 RIGIFY_PARAMETERS_BASE_DIR = set(dir(RigifyParameters))
-
 RIGIFY_PARAMETER_TABLE = {'name': ('DEFAULT', StringProperty())}
 
+
 def clear_rigify_parameters():
     for name in list(dir(RigifyParameters)):
         if name not in RIGIFY_PARAMETERS_BASE_DIR:
@@ -390,6 +410,7 @@ def format_property_spec(spec):
 
 
 class RigifyParameterValidator(object):
+    # noinspection GrazieInspection
     """
     A wrapper around RigifyParameters that verifies properties
     defined from rigs for incompatible redefinitions using a table.
@@ -416,8 +437,9 @@ class RigifyParameterValidator(object):
         if hasattr(RigifyParameterValidator, name):
             return object.__setattr__(self, name, val_original)
 
-        if not isinstance(val_original, bpy.props._PropertyDeferred):
-            print("!!! RIGIFY RIG %s: INVALID DEFINITION FOR RIG PARAMETER %s: %r\n" % (self.__rig_name, name, val_original))
+        if not isinstance(val_original, bpy.props._PropertyDeferred):  # noqa
+        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list