2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2011-07-31 03:15:37 +00:00
|
|
|
# <pep8-80 compliant>
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
__all__ = (
|
2011-02-25 16:06:14 +00:00
|
|
|
"paths",
|
|
|
|
"modules",
|
|
|
|
"check",
|
|
|
|
"enable",
|
|
|
|
"disable",
|
2017-03-24 05:20:26 +11:00
|
|
|
"disable_all",
|
2011-02-25 16:06:14 +00:00
|
|
|
"reset_all",
|
|
|
|
"module_bl_info",
|
2016-07-29 21:22:27 +10:00
|
|
|
)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2011-02-22 22:24:50 +00:00
|
|
|
import bpy as _bpy
|
2018-12-21 12:47:44 +11:00
|
|
|
_preferences = _bpy.context.preferences
|
2012-12-19 07:27:23 +00:00
|
|
|
|
2011-08-07 04:55:58 +00:00
|
|
|
error_encoding = False
|
2017-02-27 03:54:12 +11:00
|
|
|
# (name, file, path)
|
|
|
|
error_duplicates = []
|
2011-09-23 13:47:29 +00:00
|
|
|
addons_fake_modules = {}
|
2011-09-23 13:29:28 +00:00
|
|
|
|
2013-11-20 03:38:18 +11:00
|
|
|
|
2015-01-23 16:20:37 +11:00
|
|
|
# called only once at startup, avoids calling 'reset_all', correct but slower.
|
|
|
|
def _initialize():
|
|
|
|
path_list = paths()
|
|
|
|
for path in path_list:
|
2019-08-15 15:53:11 +10:00
|
|
|
_bpy.utils._sys_path_ensure_append(path)
|
2018-12-21 12:47:44 +11:00
|
|
|
for addon in _preferences.addons:
|
2015-01-23 16:20:37 +11:00
|
|
|
enable(addon.module)
|
|
|
|
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
def paths():
|
2011-02-25 16:06:14 +00:00
|
|
|
# RELEASE SCRIPTS: official scripts distributed in Blender releases
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
addon_paths = _bpy.utils.script_paths(subdir="addons")
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2011-02-25 16:06:14 +00:00
|
|
|
# CONTRIB SCRIPTS: good for testing but not official scripts yet
|
|
|
|
# if folder addons_contrib/ exists, scripts in there will be loaded too
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
addon_paths += _bpy.utils.script_paths(subdir="addons_contrib")
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2012-01-18 06:55:51 +00:00
|
|
|
return addon_paths
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def modules_refresh(*, module_cache=addons_fake_modules):
|
2011-08-07 04:55:58 +00:00
|
|
|
global error_encoding
|
2011-02-25 16:06:14 +00:00
|
|
|
import os
|
|
|
|
|
2011-08-07 04:55:58 +00:00
|
|
|
error_encoding = False
|
2017-02-27 03:54:12 +11:00
|
|
|
error_duplicates.clear()
|
2011-07-18 05:41:46 +00:00
|
|
|
|
2011-02-25 16:06:14 +00:00
|
|
|
path_list = paths()
|
|
|
|
|
|
|
|
# fake module importing
|
2011-11-17 20:11:20 +00:00
|
|
|
def fake_module(mod_name, mod_path, speedy=True, force_support=None):
|
2011-08-07 04:55:58 +00:00
|
|
|
global error_encoding
|
|
|
|
|
2012-03-31 00:59:17 +00:00
|
|
|
if _bpy.app.debug_python:
|
2011-02-25 16:06:14 +00:00
|
|
|
print("fake_module", mod_path, mod_name)
|
|
|
|
import ast
|
|
|
|
ModuleType = type(ast)
|
2015-06-08 12:08:43 +02:00
|
|
|
try:
|
|
|
|
file_mod = open(mod_path, "r", encoding='UTF-8')
|
2018-02-01 13:58:44 +11:00
|
|
|
except OSError as ex:
|
2018-07-14 09:30:59 +02:00
|
|
|
print("Error opening file:", mod_path, ex)
|
2015-06-08 12:08:43 +02:00
|
|
|
return None
|
|
|
|
|
2015-06-08 21:21:54 +10:00
|
|
|
with file_mod:
|
|
|
|
if speedy:
|
|
|
|
lines = []
|
|
|
|
line_iter = iter(file_mod)
|
|
|
|
l = ""
|
|
|
|
while not l.startswith("bl_info"):
|
|
|
|
try:
|
|
|
|
l = line_iter.readline()
|
2018-02-01 13:58:44 +11:00
|
|
|
except UnicodeDecodeError as ex:
|
2015-06-08 21:21:54 +10:00
|
|
|
if not error_encoding:
|
|
|
|
error_encoding = True
|
2018-02-01 13:58:44 +11:00
|
|
|
print("Error reading file as UTF-8:", mod_path, ex)
|
2015-06-08 21:21:54 +10:00
|
|
|
return None
|
|
|
|
|
|
|
|
if len(l) == 0:
|
|
|
|
break
|
|
|
|
while l.rstrip():
|
|
|
|
lines.append(l)
|
|
|
|
try:
|
|
|
|
l = line_iter.readline()
|
2018-02-01 13:58:44 +11:00
|
|
|
except UnicodeDecodeError as ex:
|
2015-06-08 21:21:54 +10:00
|
|
|
if not error_encoding:
|
|
|
|
error_encoding = True
|
2018-02-01 13:58:44 +11:00
|
|
|
print("Error reading file as UTF-8:", mod_path, ex)
|
2015-06-08 21:21:54 +10:00
|
|
|
return None
|
|
|
|
|
|
|
|
data = "".join(lines)
|
|
|
|
|
|
|
|
else:
|
|
|
|
data = file_mod.read()
|
|
|
|
del file_mod
|
2011-02-25 16:06:14 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
ast_data = ast.parse(data, filename=mod_path)
|
|
|
|
except:
|
2018-07-14 09:30:59 +02:00
|
|
|
print("Syntax error 'ast.parse' can't read:", repr(mod_path))
|
2011-02-25 16:06:14 +00:00
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
ast_data = None
|
|
|
|
|
|
|
|
body_info = None
|
|
|
|
|
|
|
|
if ast_data:
|
|
|
|
for body in ast_data.body:
|
|
|
|
if body.__class__ == ast.Assign:
|
|
|
|
if len(body.targets) == 1:
|
|
|
|
if getattr(body.targets[0], "id", "") == "bl_info":
|
|
|
|
body_info = body
|
|
|
|
break
|
|
|
|
|
|
|
|
if body_info:
|
2011-03-27 20:52:50 +00:00
|
|
|
try:
|
|
|
|
mod = ModuleType(mod_name)
|
|
|
|
mod.bl_info = ast.literal_eval(body.value)
|
|
|
|
mod.__file__ = mod_path
|
|
|
|
mod.__time__ = os.path.getmtime(mod_path)
|
|
|
|
except:
|
2020-09-10 16:39:52 +10:00
|
|
|
print("AST error parsing bl_info for:", repr(mod_path))
|
2011-03-27 20:52:50 +00:00
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
2020-09-10 16:39:52 +10:00
|
|
|
return None
|
2011-04-01 02:41:15 +00:00
|
|
|
|
2011-11-17 20:11:20 +00:00
|
|
|
if force_support is not None:
|
|
|
|
mod.bl_info["support"] = force_support
|
|
|
|
|
2011-02-25 16:06:14 +00:00
|
|
|
return mod
|
|
|
|
else:
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
|
|
|
"fake_module: addon missing 'bl_info' "
|
|
|
|
"gives bad performance!:",
|
|
|
|
repr(mod_path),
|
|
|
|
)
|
2011-02-25 16:06:14 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
modules_stale = set(module_cache.keys())
|
|
|
|
|
|
|
|
for path in path_list:
|
2011-11-17 20:11:20 +00:00
|
|
|
|
|
|
|
# force all contrib addons to be 'TESTING'
|
2015-01-21 12:56:03 +11:00
|
|
|
if path.endswith(("addons_contrib", )):
|
2011-11-21 14:19:34 +00:00
|
|
|
force_support = 'TESTING'
|
|
|
|
else:
|
|
|
|
force_support = None
|
2011-11-17 20:11:20 +00:00
|
|
|
|
2011-02-25 16:06:14 +00:00
|
|
|
for mod_name, mod_path in _bpy.path.module_names(path):
|
2015-01-23 16:37:00 +11:00
|
|
|
modules_stale.discard(mod_name)
|
2011-02-25 16:06:14 +00:00
|
|
|
mod = module_cache.get(mod_name)
|
|
|
|
if mod:
|
2011-07-18 05:41:46 +00:00
|
|
|
if mod.__file__ != mod_path:
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
|
|
|
"multiple addons with the same name:\n"
|
2020-06-26 12:30:03 +10:00
|
|
|
" %r\n"
|
|
|
|
" %r" % (mod.__file__, mod_path)
|
2018-07-14 09:30:59 +02:00
|
|
|
)
|
2017-02-27 03:54:12 +11:00
|
|
|
error_duplicates.append((mod.bl_info["name"], mod.__file__, mod_path))
|
2011-07-18 05:41:46 +00:00
|
|
|
|
|
|
|
elif mod.__time__ != os.path.getmtime(mod_path):
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
|
|
|
"reloading addon:",
|
|
|
|
mod_name,
|
|
|
|
mod.__time__,
|
|
|
|
os.path.getmtime(mod_path),
|
|
|
|
repr(mod_path),
|
|
|
|
)
|
2011-02-25 16:06:14 +00:00
|
|
|
del module_cache[mod_name]
|
|
|
|
mod = None
|
|
|
|
|
|
|
|
if mod is None:
|
2018-02-01 13:58:44 +11:00
|
|
|
mod = fake_module(
|
|
|
|
mod_name,
|
|
|
|
mod_path,
|
|
|
|
force_support=force_support,
|
|
|
|
)
|
2011-02-25 16:06:14 +00:00
|
|
|
if mod:
|
|
|
|
module_cache[mod_name] = mod
|
|
|
|
|
2011-10-17 06:58:07 +00:00
|
|
|
# just in case we get stale modules, not likely
|
2011-02-25 16:06:14 +00:00
|
|
|
for mod_stale in modules_stale:
|
|
|
|
del module_cache[mod_stale]
|
|
|
|
del modules_stale
|
|
|
|
|
2013-08-28 06:36:54 +00:00
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def modules(*, module_cache=addons_fake_modules, refresh=True):
|
2015-01-23 16:20:37 +11:00
|
|
|
if refresh or ((module_cache is addons_fake_modules) and modules._is_first):
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
modules_refresh(module_cache=module_cache)
|
2015-01-23 16:20:37 +11:00
|
|
|
modules._is_first = False
|
2013-08-28 06:36:54 +00:00
|
|
|
|
2011-02-25 16:06:14 +00:00
|
|
|
mod_list = list(module_cache.values())
|
2018-02-01 13:58:44 +11:00
|
|
|
mod_list.sort(
|
|
|
|
key=lambda mod: (
|
2019-03-27 15:12:25 +01:00
|
|
|
mod.bl_info.get("category", ""),
|
|
|
|
mod.bl_info.get("name", ""),
|
2018-02-01 13:58:44 +11:00
|
|
|
)
|
|
|
|
)
|
2011-02-25 16:06:14 +00:00
|
|
|
return mod_list
|
2018-07-03 06:27:53 +02:00
|
|
|
|
|
|
|
|
2015-01-23 16:20:37 +11:00
|
|
|
modules._is_first = True
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check(module_name):
|
|
|
|
"""
|
|
|
|
Returns the loaded state of the addon.
|
|
|
|
|
|
|
|
:arg module_name: The name of the addon and module.
|
|
|
|
:type module_name: string
|
|
|
|
:return: (loaded_default, loaded_state)
|
|
|
|
:rtype: tuple of booleans
|
|
|
|
"""
|
|
|
|
import sys
|
2018-12-21 12:47:44 +11:00
|
|
|
loaded_default = module_name in _preferences.addons
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
mod = sys.modules.get(module_name)
|
2018-02-01 13:58:44 +11:00
|
|
|
loaded_state = (
|
|
|
|
(mod is not None) and
|
|
|
|
getattr(mod, "__addon_enabled__", Ellipsis)
|
|
|
|
)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
if loaded_state is Ellipsis:
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
2020-06-26 12:30:03 +10:00
|
|
|
"Warning: addon-module", module_name, "found module "
|
2018-07-14 09:30:59 +02:00
|
|
|
"but without '__addon_enabled__' field, "
|
|
|
|
"possible name collision from file:",
|
|
|
|
repr(getattr(mod, "__file__", "<unknown>")),
|
|
|
|
)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
loaded_state = False
|
|
|
|
|
2012-04-28 09:00:09 +00:00
|
|
|
if mod and getattr(mod, "__addon_persistent__", False):
|
|
|
|
loaded_default = True
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
return loaded_default, loaded_state
|
|
|
|
|
2013-05-27 16:12:06 +00:00
|
|
|
# utility functions
|
|
|
|
|
|
|
|
|
|
|
|
def _addon_ensure(module_name):
|
2018-12-21 12:47:44 +11:00
|
|
|
addons = _preferences.addons
|
2014-04-25 05:31:20 +10:00
|
|
|
addon = addons.get(module_name)
|
2013-05-27 16:12:06 +00:00
|
|
|
if not addon:
|
2014-04-25 05:31:20 +10:00
|
|
|
addon = addons.new()
|
2013-05-27 16:12:06 +00:00
|
|
|
addon.module = module_name
|
|
|
|
|
|
|
|
|
|
|
|
def _addon_remove(module_name):
|
2018-12-21 12:47:44 +11:00
|
|
|
addons = _preferences.addons
|
2013-05-27 16:12:06 +00:00
|
|
|
|
|
|
|
while module_name in addons:
|
|
|
|
addon = addons.get(module_name)
|
|
|
|
if addon:
|
|
|
|
addons.remove(addon)
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2015-11-16 09:41:42 +11:00
|
|
|
def enable(module_name, *, default_set=False, persistent=False, handle_error=None):
|
2011-02-21 07:07:44 +00:00
|
|
|
"""
|
|
|
|
Enables an addon by name.
|
|
|
|
|
2016-01-07 23:33:51 +11:00
|
|
|
:arg module_name: the name of the addon and module.
|
2011-02-21 07:07:44 +00:00
|
|
|
:type module_name: string
|
2016-01-07 23:33:51 +11:00
|
|
|
:arg default_set: Set the user-preference.
|
|
|
|
:type default_set: bool
|
|
|
|
:arg persistent: Ensure the addon is enabled for the entire session (after loading new files).
|
|
|
|
:type persistent: bool
|
|
|
|
:arg handle_error: Called in the case of an error, taking an exception argument.
|
|
|
|
:type handle_error: function
|
2011-10-17 06:58:07 +00:00
|
|
|
:return: the loaded module or None on failure.
|
2011-02-21 07:07:44 +00:00
|
|
|
:rtype: module
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2012-12-20 03:56:22 +00:00
|
|
|
from bpy_restrict_state import RestrictBlend
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2013-06-19 05:17:31 +00:00
|
|
|
if handle_error is None:
|
2019-05-09 13:11:36 +10:00
|
|
|
def handle_error(_ex):
|
2013-06-19 05:17:31 +00:00
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
# reload if the mtime changes
|
|
|
|
mod = sys.modules.get(module_name)
|
2011-11-26 17:41:56 +00:00
|
|
|
# chances of the file _not_ existing are low, but it could be removed
|
|
|
|
if mod and os.path.exists(mod.__file__):
|
2015-06-14 22:19:26 +10:00
|
|
|
|
|
|
|
if getattr(mod, "__addon_enabled__", False):
|
|
|
|
# This is an unlikely situation,
|
|
|
|
# re-register if the module is enabled.
|
|
|
|
# Note: the UI doesn't allow this to happen,
|
|
|
|
# in most cases the caller should 'check()' first.
|
|
|
|
try:
|
|
|
|
mod.unregister()
|
2016-01-07 23:33:51 +11:00
|
|
|
except Exception as ex:
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
|
|
|
"Exception in module unregister():",
|
|
|
|
repr(getattr(mod, "__file__", module_name)),
|
|
|
|
)
|
2016-01-07 23:33:51 +11:00
|
|
|
handle_error(ex)
|
2015-06-14 22:19:26 +10:00
|
|
|
return None
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
mod.__addon_enabled__ = False
|
|
|
|
mtime_orig = getattr(mod, "__time__", 0)
|
|
|
|
mtime_new = os.path.getmtime(mod.__file__)
|
|
|
|
if mtime_orig != mtime_new:
|
2015-01-23 12:37:58 +11:00
|
|
|
import importlib
|
2018-07-14 09:30:59 +02:00
|
|
|
print("module changed on disk:", repr(mod.__file__), "reloading...")
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
try:
|
2015-01-23 12:37:58 +11:00
|
|
|
importlib.reload(mod)
|
2016-01-07 23:33:51 +11:00
|
|
|
except Exception as ex:
|
|
|
|
handle_error(ex)
|
2011-02-21 07:07:44 +00:00
|
|
|
del sys.modules[module_name]
|
|
|
|
return None
|
|
|
|
mod.__addon_enabled__ = False
|
|
|
|
|
2013-05-27 16:12:06 +00:00
|
|
|
# add the addon first it may want to initialize its own preferences.
|
|
|
|
# must remove on fail through.
|
|
|
|
if default_set:
|
|
|
|
_addon_ensure(module_name)
|
|
|
|
|
2011-07-31 03:15:37 +00:00
|
|
|
# Split registering up into 3 steps so we can undo
|
|
|
|
# if it fails par way through.
|
2011-11-26 17:41:56 +00:00
|
|
|
|
2019-06-21 09:50:23 +10:00
|
|
|
# Disable the context: using the context at all
|
|
|
|
# while loading an addon is really bad, don't do it!
|
2012-12-20 03:56:22 +00:00
|
|
|
with RestrictBlend():
|
2012-12-19 07:27:23 +00:00
|
|
|
|
2012-12-20 03:56:22 +00:00
|
|
|
# 1) try import
|
|
|
|
try:
|
|
|
|
mod = __import__(module_name)
|
2021-03-26 10:46:26 +01:00
|
|
|
if mod.__file__ is None:
|
|
|
|
# This can happen when the addon has been removed but there are
|
|
|
|
# residual `.pyc` files left behind.
|
|
|
|
raise ImportError(name=module_name)
|
2012-12-20 03:56:22 +00:00
|
|
|
mod.__time__ = os.path.getmtime(mod.__file__)
|
|
|
|
mod.__addon_enabled__ = False
|
2015-02-12 23:42:51 +11:00
|
|
|
except Exception as ex:
|
2018-09-03 16:49:08 +02:00
|
|
|
# if the addon doesn't exist, don't print full traceback
|
2015-02-12 23:42:51 +11:00
|
|
|
if type(ex) is ImportError and ex.name == module_name:
|
2021-06-20 22:57:58 +02:00
|
|
|
print("addon not loaded:", repr(module_name))
|
|
|
|
print("cause:", str(ex))
|
2015-02-12 23:42:51 +11:00
|
|
|
else:
|
2016-01-07 23:33:51 +11:00
|
|
|
handle_error(ex)
|
2015-02-12 23:42:51 +11:00
|
|
|
|
2015-01-23 21:09:31 +11:00
|
|
|
if default_set:
|
|
|
|
_addon_remove(module_name)
|
2012-12-20 03:56:22 +00:00
|
|
|
return None
|
|
|
|
|
2019-06-21 09:50:23 +10:00
|
|
|
# 1.1) Fail when add-on is too old.
|
2018-07-03 07:58:10 +02:00
|
|
|
# This is a temporary 2.8x migration check, so we can manage addons that are supported.
|
2018-07-06 10:59:29 +02:00
|
|
|
|
2019-03-18 10:36:50 +01:00
|
|
|
if mod.bl_info.get("blender", (0, 0, 0)) < (2, 80, 0):
|
|
|
|
if _bpy.app.debug:
|
2020-07-16 23:50:33 +10:00
|
|
|
print("Warning: Add-on '%s' was not upgraded for 2.80, ignoring" % module_name)
|
2018-07-03 07:58:10 +02:00
|
|
|
return None
|
|
|
|
|
2019-06-21 09:50:23 +10:00
|
|
|
# 2) Try register collected modules.
|
|
|
|
# Removed register_module, addons need to handle their own registration now.
|
2012-12-20 03:56:22 +00:00
|
|
|
|
2020-02-03 12:49:09 +01:00
|
|
|
from _bpy import _bl_owner_id_get, _bl_owner_id_set
|
|
|
|
owner_id_prev = _bl_owner_id_get()
|
|
|
|
_bl_owner_id_set(module_name)
|
2018-03-01 01:26:02 +11:00
|
|
|
|
2019-06-21 09:50:23 +10:00
|
|
|
# 3) Try run the modules register function.
|
2012-12-20 03:56:22 +00:00
|
|
|
try:
|
|
|
|
mod.register()
|
2016-01-07 23:33:51 +11:00
|
|
|
except Exception as ex:
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
|
|
|
"Exception in module register():",
|
|
|
|
getattr(mod, "__file__", module_name),
|
|
|
|
)
|
2016-01-07 23:33:51 +11:00
|
|
|
handle_error(ex)
|
2012-12-20 03:56:22 +00:00
|
|
|
del sys.modules[module_name]
|
2015-01-23 21:09:31 +11:00
|
|
|
if default_set:
|
|
|
|
_addon_remove(module_name)
|
2012-12-20 03:56:22 +00:00
|
|
|
return None
|
2018-03-01 01:26:02 +11:00
|
|
|
finally:
|
2020-02-03 12:49:09 +01:00
|
|
|
_bl_owner_id_set(owner_id_prev)
|
2012-12-19 07:27:23 +00:00
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
# * OK loaded successfully! *
|
|
|
|
mod.__addon_enabled__ = True
|
2012-04-28 09:00:09 +00:00
|
|
|
mod.__addon_persistent__ = persistent
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2012-03-31 00:59:17 +00:00
|
|
|
if _bpy.app.debug_python:
|
2011-02-21 07:07:44 +00:00
|
|
|
print("\taddon_utils.enable", mod.__name__)
|
|
|
|
|
|
|
|
return mod
|
|
|
|
|
|
|
|
|
2015-11-16 09:41:42 +11:00
|
|
|
def disable(module_name, *, default_set=False, handle_error=None):
|
2011-02-21 07:07:44 +00:00
|
|
|
"""
|
|
|
|
Disables an addon by name.
|
|
|
|
|
|
|
|
:arg module_name: The name of the addon and module.
|
|
|
|
:type module_name: string
|
2016-01-07 23:33:51 +11:00
|
|
|
:arg default_set: Set the user-preference.
|
|
|
|
:type default_set: bool
|
|
|
|
:arg handle_error: Called in the case of an error, taking an exception argument.
|
|
|
|
:type handle_error: function
|
2011-02-21 07:07:44 +00:00
|
|
|
"""
|
|
|
|
import sys
|
2013-06-19 05:17:31 +00:00
|
|
|
|
|
|
|
if handle_error is None:
|
2019-05-09 13:11:36 +10:00
|
|
|
def handle_error(_ex):
|
2013-06-19 05:17:31 +00:00
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
mod = sys.modules.get(module_name)
|
|
|
|
|
2011-10-17 06:58:07 +00:00
|
|
|
# possible this addon is from a previous session and didn't load a
|
2011-07-31 03:15:37 +00:00
|
|
|
# module this time. So even if the module is not found, still disable
|
|
|
|
# the addon in the user prefs.
|
2012-10-10 11:37:38 +00:00
|
|
|
if mod and getattr(mod, "__addon_enabled__", False) is not False:
|
2011-02-21 07:07:44 +00:00
|
|
|
mod.__addon_enabled__ = False
|
2012-04-28 09:00:09 +00:00
|
|
|
mod.__addon_persistent = False
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
mod.unregister()
|
2016-01-07 23:33:51 +11:00
|
|
|
except Exception as ex:
|
2018-07-14 09:30:59 +02:00
|
|
|
mod_path = getattr(mod, "__file__", module_name)
|
|
|
|
print("Exception in module unregister():", repr(mod_path))
|
|
|
|
del mod_path
|
2016-01-07 23:33:51 +11:00
|
|
|
handle_error(ex)
|
2011-02-21 07:07:44 +00:00
|
|
|
else:
|
2018-07-14 09:30:59 +02:00
|
|
|
print(
|
2020-06-26 12:30:03 +10:00
|
|
|
"addon_utils.disable: %s not %s" % (
|
|
|
|
module_name,
|
|
|
|
"disabled" if mod is None else "loaded")
|
2018-07-14 09:30:59 +02:00
|
|
|
)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2013-04-07 15:09:06 +00:00
|
|
|
# could be in more than once, unlikely but better do this just in case.
|
2011-02-21 07:07:44 +00:00
|
|
|
if default_set:
|
2013-05-27 16:12:06 +00:00
|
|
|
_addon_remove(module_name)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
2012-03-31 00:59:17 +00:00
|
|
|
if _bpy.app.debug_python:
|
2011-02-21 07:07:44 +00:00
|
|
|
print("\taddon_utils.disable", module_name)
|
|
|
|
|
|
|
|
|
2015-11-16 09:41:42 +11:00
|
|
|
def reset_all(*, reload_scripts=False):
|
2011-02-21 07:07:44 +00:00
|
|
|
"""
|
|
|
|
Sets the addon state based on the user preferences.
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
|
2013-08-28 06:36:54 +00:00
|
|
|
# initializes addons_fake_modules
|
|
|
|
modules_refresh()
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
# RELEASE SCRIPTS: official scripts distributed in Blender releases
|
|
|
|
paths_list = paths()
|
|
|
|
|
|
|
|
for path in paths_list:
|
2019-08-18 02:31:26 +10:00
|
|
|
_bpy.utils._sys_path_ensure_append(path)
|
2019-03-17 21:13:25 +11:00
|
|
|
for mod_name, _mod_path in _bpy.path.module_names(path):
|
2011-02-21 07:07:44 +00:00
|
|
|
is_enabled, is_loaded = check(mod_name)
|
|
|
|
|
|
|
|
# first check if reload is needed before changing state.
|
|
|
|
if reload_scripts:
|
2015-01-23 12:37:58 +11:00
|
|
|
import importlib
|
2011-02-21 07:07:44 +00:00
|
|
|
mod = sys.modules.get(mod_name)
|
|
|
|
if mod:
|
2015-01-23 12:37:58 +11:00
|
|
|
importlib.reload(mod)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
if is_enabled == is_loaded:
|
|
|
|
pass
|
|
|
|
elif is_enabled:
|
|
|
|
enable(mod_name)
|
|
|
|
elif is_loaded:
|
|
|
|
print("\taddon_utils.reset_all unloading", mod_name)
|
2011-02-22 22:24:50 +00:00
|
|
|
disable(mod_name)
|
2011-02-21 07:07:44 +00:00
|
|
|
|
|
|
|
|
2017-03-24 05:20:26 +11:00
|
|
|
def disable_all():
|
|
|
|
import sys
|
2018-10-19 17:49:16 +11:00
|
|
|
# Collect modules to disable first because dict can be modified as we disable.
|
|
|
|
addon_modules = [
|
|
|
|
item for item in sys.modules.items()
|
|
|
|
if getattr(item[1], "__addon_enabled__", False)
|
|
|
|
]
|
2020-08-17 12:33:07 +10:00
|
|
|
# Check the enabled state again since it's possible the disable call
|
|
|
|
# of one add-on disables others.
|
2018-10-19 17:49:16 +11:00
|
|
|
for mod_name, mod in addon_modules:
|
2017-03-24 05:20:26 +11:00
|
|
|
if getattr(mod, "__addon_enabled__", False):
|
|
|
|
disable(mod_name)
|
|
|
|
|
|
|
|
|
2020-03-04 23:24:13 -05:00
|
|
|
def _blender_manual_url_prefix():
|
|
|
|
if _bpy.app.version_cycle in {"rc", "release"}:
|
|
|
|
manual_version = "%d.%d" % _bpy.app.version[:2]
|
|
|
|
else:
|
|
|
|
manual_version = "dev"
|
|
|
|
|
2020-06-26 12:30:03 +10:00
|
|
|
return "https://docs.blender.org/manual/en/" + manual_version
|
2020-03-04 23:24:13 -05:00
|
|
|
|
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def module_bl_info(mod, *, info_basis=None):
|
2015-05-31 15:56:22 +10:00
|
|
|
if info_basis is None:
|
|
|
|
info_basis = {
|
|
|
|
"name": "",
|
|
|
|
"author": "",
|
|
|
|
"version": (),
|
|
|
|
"blender": (),
|
|
|
|
"location": "",
|
|
|
|
"description": "",
|
2020-03-05 11:40:05 +11:00
|
|
|
"doc_url": "",
|
2015-05-31 15:56:22 +10:00
|
|
|
"support": 'COMMUNITY',
|
|
|
|
"category": "",
|
|
|
|
"warning": "",
|
|
|
|
"show_expanded": False,
|
2016-07-29 21:22:27 +10:00
|
|
|
}
|
2011-07-31 03:15:37 +00:00
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
addon_info = getattr(mod, "bl_info", {})
|
|
|
|
|
|
|
|
# avoid re-initializing
|
|
|
|
if "_init" in addon_info:
|
|
|
|
return addon_info
|
|
|
|
|
|
|
|
if not addon_info:
|
|
|
|
mod.bl_info = addon_info
|
|
|
|
|
|
|
|
for key, value in info_basis.items():
|
|
|
|
addon_info.setdefault(key, value)
|
|
|
|
|
|
|
|
if not addon_info["name"]:
|
|
|
|
addon_info["name"] = mod.__name__
|
|
|
|
|
2020-03-04 23:24:13 -05:00
|
|
|
doc_url = addon_info["doc_url"]
|
|
|
|
if doc_url:
|
|
|
|
doc_url_prefix = "{BLENDER_MANUAL_URL}"
|
|
|
|
if doc_url_prefix in doc_url:
|
|
|
|
addon_info["doc_url"] = doc_url.replace(
|
|
|
|
doc_url_prefix,
|
|
|
|
_blender_manual_url_prefix(),
|
|
|
|
)
|
|
|
|
|
2011-02-21 07:07:44 +00:00
|
|
|
addon_info["_init"] = None
|
|
|
|
return addon_info
|