1 # SPDX-License-Identifier: GPL-2.0-or-later
7 from .utils
.rig
import RIG_DIR
9 from . import feature_set_list
12 def get_rigs(base_dir
, base_path
, *, path
=[], feature_set
=feature_set_list
.DEFAULT_NAME
):
13 """ Recursively searches for rig types, and returns a list.
15 :param base_path: base dir where rigs are stored
17 :param path: rig path inside the base dir
24 dir_path
= os
.path
.join(base_dir
, *path
)
27 files
= os
.listdir(dir_path
)
28 except FileNotFoundError
:
34 is_dir
= os
.path
.isdir(os
.path
.join(dir_path
, f
)) # Whether the file is a directory
37 if f
[0] in [".", "_"]:
39 if f
.count(".") >= 2 or (is_dir
and "." in f
):
40 print("Warning: %r, filename contains a '.', skipping" % os
.path
.join(*base_path
, *path
, f
))
45 sub_rigs
, sub_impls
= get_rigs(base_dir
, base_path
, path
=[*path
, f
], feature_set
=feature_set
)
47 impl_rigs
.update(sub_impls
)
48 elif f
.endswith(".py"):
49 # Check straight-up python files
50 subpath
= [*path
, f
[:-3]]
51 key
= '.'.join(subpath
)
52 # Don't reload rig modules - it breaks isinstance
53 rig_module
= importlib
.import_module('.'.join(base_path
+ subpath
))
54 if hasattr(rig_module
, "Rig"):
55 rigs
[key
] = {"module": rig_module
,
56 "feature_set": feature_set
}
57 if hasattr(rig_module
, 'IMPLEMENTATION') and rig_module
.IMPLEMENTATION
:
58 impl_rigs
[key
] = rig_module
60 return rigs
, impl_rigs
65 implementation_rigs
= {}
67 def get_rig_class(name
):
69 return rigs
[name
]["module"].Rig
70 except (KeyError, AttributeError):
73 def get_internal_rigs():
74 global rigs
, implementation_rigs
76 BASE_RIGIFY_DIR
= os
.path
.dirname(__file__
)
77 BASE_RIGIFY_PATH
= __name__
.split('.')[:-1]
79 rigs
, implementation_rigs
= get_rigs(os
.path
.join(BASE_RIGIFY_DIR
, RIG_DIR
), [*BASE_RIGIFY_PATH
, RIG_DIR
])
81 def get_external_rigs(set_list
):
82 # Clear and fill rigify rigs and implementation rigs public variables
83 for rig
in list(rigs
.keys()):
84 if rigs
[rig
]["feature_set"] != feature_set_list
.DEFAULT_NAME
:
86 if rig
in implementation_rigs
:
87 implementation_rigs
.pop(rig
)
90 for feature_set
in set_list
:
92 base_dir
, base_path
= feature_set_list
.get_dir_path(feature_set
, RIG_DIR
)
94 external_rigs
, external_impl_rigs
= get_rigs(base_dir
, base_path
, feature_set
=feature_set
)
96 print("Rigify Error: Could not load feature set '%s' rigs: exception occurred.\n" % (feature_set
))
101 rigs
.update(external_rigs
)
102 implementation_rigs
.update(external_impl_rigs
)