From b8b1189bc46d9d0a534a404e939b14fc31f38bc5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 25 Jan 2024 12:44:08 +1100 Subject: [PATCH] Cleanup: assign a variable for the extension module with a trailing "." This is used in enough places to simplify checks. --- scripts/modules/addon_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/modules/addon_utils.py b/scripts/modules/addon_utils.py index a9bde2ef4b0..dd4fd823812 100644 --- a/scripts/modules/addon_utils.py +++ b/scripts/modules/addon_utils.py @@ -380,8 +380,8 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non print("Add-on not loaded: \"%s\", cause: %s" % (module_name, str(ex))) # Issue with an add-on from an extension repository, report a useful message. - elif module_name.startswith(ex.name + ".") and module_name.startswith(_ext_base_pkg_idname + "."): - repo_id = module_name[len(_ext_base_pkg_idname) + 1:].rpartition(".")[0] + elif module_name.startswith(ex.name + ".") and module_name.startswith(_ext_base_pkg_idname_with_dot): + repo_id = module_name[len(_ext_base_pkg_idname_with_dot):].rpartition(".")[0] repo = next( (repo for repo in _preferences.filepaths.extension_repos if repo.module == repo_id), None, @@ -632,6 +632,7 @@ class _ext_global: # The name (in `sys.modules`) keep this short because it's stored as part of add-on modules name. _ext_base_pkg_idname = "bl_ext" +_ext_base_pkg_idname_with_dot = _ext_base_pkg_idname + "." def _extension_preferences_idmap(): @@ -692,12 +693,11 @@ def _initialize_extension_repos_post_addons_prepare( # All preferences info. # Map: `repo_id -> {submodule_id -> addon, ...}`. addon_userdef_info = {} - module_prefix = _ext_base_pkg_idname + "." for addon in _preferences.addons: module = addon.module - if not module.startswith(module_prefix): + if not module.startswith(_ext_base_pkg_idname_with_dot): continue - module_id, submodule_id = module[len(module_prefix):].partition(".")[0::2] + module_id, submodule_id = module[len(_ext_base_pkg_idname_with_dot):].partition(".")[0::2] try: addon_userdef_info[module_id][submodule_id] = addon except KeyError: