forked from fblah/ShapeKeyTransferBlender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
developer_utils.py
42 lines (36 loc) · 1.37 KB
/
developer_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
import pkgutil
import importlib
def setup_addon_modules(path, package_name, reload):
"""
Imports and reloads all modules in this addon.
path -- __path__ from __init__.py
package_name -- __name__ from __init__.py
Individual modules can define a __reload_order_index__ property which
will be used to reload the modules in a specific order. The default is 0.
"""
def get_submodule_names(path = path[0], root = ""):
module_names = []
for importer, module_name, is_package in pkgutil.iter_modules([path]):
if is_package:
sub_path = os.path.join(path, module_name)
sub_root = root + module_name + "."
module_names.extend(get_submodule_names(sub_path, sub_root))
else:
module_names.append(root + module_name)
return module_names
def import_submodules(names):
modules = []
for name in names:
modules.append(importlib.import_module("." + name, package_name))
return modules
def reload_modules(modules):
modules.sort(key = lambda module: getattr(module, "__reload_order_index__", 0))
for module in modules:
importlib.reload(module)
names = get_submodule_names()
modules = import_submodules(names)
if reload:
reload_modules(modules)
return modules