diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-28 22:57:36 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-29 10:37:28 +0300 |
commit | 011f7afde41efc6fa16084e0f406f5287dc3c481 (patch) | |
tree | 3151da38ff4fffcd11483186af24cbcc400be4a1 /rigify/utils/rig.py | |
parent | 68bb42ef065c5c95a21493ebd5469b8a21af75ae (diff) |
Rigify: refactor feature sets to avoid modifying global path.
Instead of adding the feature set installation directory
to the global path, and thus inserting the modules into
the top level namespace, add an empty rigify.feature_sets
package and use __path__ to redirect the module loader
to read its sub-modules from the feature set directory.
Now feature set modules are effectively installed into
that package and loaded as 'rigify.feature_sets.foo'.
As an aside, clean up loading code to avoid weird path
manipulations, add more safety checks when installing sets,
and add a way for sets to expose a user-friendly name.
Diffstat (limited to 'rigify/utils/rig.py')
-rw-r--r-- | rigify/utils/rig.py | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index 9aeb9e0f..414ea133 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -27,7 +27,6 @@ RIG_DIR = "rigs" # Name of the directory where rig types are kept METARIG_DIR = "metarigs" # Name of the directory where metarigs are kept TEMPLATE_DIR = "ui_templates" # Name of the directory where ui templates are kept -MODULE_NAME = "rigify" # Windows/Mac blender is weird, so __package__ doesn't work outdated_types = {"pitchipoy.limbs.super_limb": "limbs.super_limb", "pitchipoy.limbs.super_arm": "limbs.super_limb", @@ -81,36 +80,13 @@ def upgradeMetarigTypes(metarig, revert=False): # Misc #============================================= -def get_rig_type(rig_type, base_path=''): - return get_resource(rig_type, base_path=base_path) - -def get_resource(resource_name, base_path=''): - """ Fetches a rig module by name, and returns it. - """ - - if '.' in resource_name: - module_subpath = str.join(os.sep, resource_name.split('.')) - package = resource_name.split('.')[0] - for sub in resource_name.split('.')[1:]: - package = '.'.join([package, sub]) - submod = importlib.import_module(package) - else: - module_subpath = resource_name - - spec = importlib.util.spec_from_file_location(resource_name, os.path.join(base_path, module_subpath + '.py')) - submod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(submod) - return submod - - -def get_metarig_module(metarig_name, path=METARIG_DIR): +def get_resource(resource_name): """ Fetches a rig module by name, and returns it. """ - name = ".%s.%s" % (path, metarig_name) - submod = importlib.import_module(name, package=MODULE_NAME) - importlib.reload(submod) - return submod + module = importlib.import_module(resource_name) + importlib.reload(module) + return module def connected_children_names(obj, bone_name): |