Cleanup: replace %-formatting with str.format in scripts/modules/

The "bl_i18n_utils" module has been excluded I'm not sure how best
to run it with reasonable code coverage.
This commit is contained in:
Campbell Barton
2024-04-27 16:06:51 +10:00
parent 8eb0abcc69
commit 5088b0154d
30 changed files with 343 additions and 277 deletions

View File

@@ -72,7 +72,7 @@ def _paths_with_extension_repos():
dirpath = repo.directory
if not os.path.isdir(dirpath):
continue
addon_paths.append((dirpath, "%s.%s" % (_ext_base_pkg_idname, repo.module)))
addon_paths.append((dirpath, "{:s}.{:s}".format(_ext_base_pkg_idname, repo.module)))
return addon_paths
@@ -187,8 +187,8 @@ def modules_refresh(*, module_cache=addons_fake_modules):
if mod.__file__ != mod_path:
print(
"multiple addons with the same name:\n"
" %r\n"
" %r" % (mod.__file__, mod_path)
" {!r}\n"
" {!r}".format(mod.__file__, mod_path)
)
error_duplicates.append((mod.bl_info["name"], mod.__file__, mod_path))
@@ -394,7 +394,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
# Include a message otherwise the "cause:" for failing to load the module is left blank.
# Include the `__path__` when available so there is a reference to the location that failed to load.
raise ImportError(
"module loaded with no associated file, __path__=%r, aborting!" % (
"module loaded with no associated file, __path__={!r}, aborting!".format(
getattr(mod, "__path__", None)
),
name=module_name
@@ -407,7 +407,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
# Account for `ImportError` & `ModuleNotFoundError`.
if isinstance(ex, ImportError):
if ex.name == module_name:
ex.msg = "Add-on not loaded: \"%s\", cause: %s" % (module_name, str(ex))
ex.msg = "Add-on not loaded: \"{:s}\", cause: {:s}".format(module_name, str(ex))
# Issue with an add-on from an extension repository, report a useful message.
elif is_extension and module_name.startswith(ex.name + "."):
@@ -418,17 +418,19 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
)
if repo is None:
ex.msg = (
"Add-on not loaded: \"%s\", cause: extension repository \"%s\" doesn't exist" %
(module_name, repo_id)
"Add-on not loaded: \"{:s}\", cause: extension repository \"{:s}\" doesn't exist".format(
module_name, repo_id,
)
)
elif not repo.enabled:
ex.msg = (
"Add-on not loaded: \"%s\", cause: extension repository \"%s\" is disabled" %
(module_name, repo_id)
"Add-on not loaded: \"{:s}\", cause: extension repository \"{:s}\" is disabled".format(
module_name, repo_id,
)
)
else:
# The repository exists and is enabled, it should have imported.
ex.msg = "Add-on not loaded: \"%s\", cause: %s" % (module_name, str(ex))
ex.msg = "Add-on not loaded: \"{:s}\", cause: {:s}".format(module_name, str(ex))
handle_error(ex)
@@ -448,8 +450,9 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
# Once `bl_info` is fully deprecated this should be changed to always print a warning.
if _bpy.app.debug_python:
print(
"Add-on \"%s\" has a \"bl_info\" which will be ignored in favor of \"%s\"" %
(module_name, _ext_manifest_filename_toml)
"Add-on \"{:s}\" has a \"bl_info\" which will be ignored in favor of \"{:s}\"".format(
module_name, _ext_manifest_filename_toml,
)
)
# Always remove as this is not expected to exist and will be lazily initialized.
del mod.bl_info
@@ -520,9 +523,10 @@ def disable(module_name, *, default_set=False, handle_error=None):
handle_error(ex)
else:
print(
"addon_utils.disable: %s not %s" % (
"addon_utils.disable: {:s} not {:s}".format(
module_name,
"loaded" if mod is None else "enabled")
"loaded" if mod is None else "enabled",
)
)
# could be in more than once, unlikely but better do this just in case.
@@ -593,7 +597,10 @@ def disable_all():
def _blender_manual_url_prefix():
return "https://docs.blender.org/manual/%s/%d.%d" % (_bpy.utils.manual_language_code(), *_bpy.app.version[:2])
return "https://docs.blender.org/manual/{:s}/{:d}.{:d}".format(
_bpy.utils.manual_language_code(),
*_bpy.app.version[:2],
)
def _bl_info_basis():
@@ -868,7 +875,7 @@ def _initialize_extension_repos_post_addons_prepare(
repo_runtime = addon_runtime_info.get(module_id, {})
for submodule_id, addon in repo_userdef.items():
module_name_next = "%s.%s.%s" % (_ext_base_pkg_idname, module_id, submodule_id)
module_name_next = "{:s}.{:s}.{:s}".format(_ext_base_pkg_idname, module_id, submodule_id)
# Only default & persistent add-ons are kept for re-activation.
default_set = True
persistent = True
@@ -880,8 +887,8 @@ def _initialize_extension_repos_post_addons_prepare(
for submodule_id, mod in repo_runtime.items():
if not getattr(mod, "__addon_enabled__", False):
continue
module_name_prev = "%s.%s.%s" % (_ext_base_pkg_idname, module_id_prev, submodule_id)
module_name_next = "%s.%s.%s" % (_ext_base_pkg_idname, module_id_next, submodule_id)
module_name_prev = "{:s}.{:s}.{:s}".format(_ext_base_pkg_idname, module_id_prev, submodule_id)
module_name_next = "{:s}.{:s}.{:s}".format(_ext_base_pkg_idname, module_id_next, submodule_id)
disable(module_name_prev, default_set=False)
addon = repo_userdef.get(submodule_id)
default_set = addon is not None
@@ -897,7 +904,7 @@ def _initialize_extension_repos_post_addons_prepare(
continue
# Either there is no run-time data or the module wasn't enabled.
# Rename the add-on without enabling it so the next time it's enabled it's preferences are kept.
module_name_next = "%s.%s.%s" % (_ext_base_pkg_idname, module_id_next, submodule_id)
module_name_next = "{:s}.{:s}.{:s}".format(_ext_base_pkg_idname, module_id_next, submodule_id)
addon.module = module_name_next
if submodules_del:
@@ -914,7 +921,7 @@ def _initialize_extension_repos_post_addons_prepare(
default_set = False
for submodule_id, mod in repo_runtime.items():
module_name_prev = "%s.%s.%s" % (_ext_base_pkg_idname, module_id, submodule_id)
module_name_prev = "{:s}.{:s}.{:s}".format(_ext_base_pkg_idname, module_id, submodule_id)
disable(module_name_prev, default_set=default_set)
del repo
del repo_module_map
@@ -923,7 +930,7 @@ def _initialize_extension_repos_post_addons_prepare(
for module_id_prev in submodules_del_disabled:
repo_userdef = addon_userdef_info.get(module_id_prev, {})
for submodule_id in repo_userdef.keys():
module_name_prev = "%s.%s.%s" % (_ext_base_pkg_idname, module_id_prev, submodule_id)
module_name_prev = "{:s}.{:s}.{:s}".format(_ext_base_pkg_idname, module_id_prev, submodule_id)
disable(module_name_prev, default_set=True)
return addons_to_enable