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

@@ -123,8 +123,7 @@ def _test_import(module_name, loaded_modules):
if module_name in loaded_modules:
return None
if "." in module_name:
print("Ignoring '%s', can't import files containing "
"multiple periods" % module_name)
print("Ignoring '{:s}', can't import files containing multiple periods".format(module_name))
return None
if use_time:
@@ -139,7 +138,7 @@ def _test_import(module_name, loaded_modules):
return None
if use_time:
print("time %s %.4f" % (module_name, time.time() - t))
print("time {:s} {:.4f}".format(module_name, time.time() - t))
loaded_modules.add(mod.__name__) # should match mod.__name__ too
return mod
@@ -235,9 +234,10 @@ def load_scripts(*, reload_scripts=False, refresh_scripts=False, extensions=True
import traceback
traceback.print_exc()
else:
print("\nWarning! %r has no register function, "
"this is now a requirement for registerable scripts" %
mod.__file__)
print(
"\nWarning! {!r} has no register function, "
"this is now a requirement for registerable scripts".format(mod.__file__)
)
def unregister_module_call(mod):
unregister = getattr(mod, "unregister", None)
@@ -324,20 +324,17 @@ def load_scripts(*, reload_scripts=False, refresh_scripts=False, extensions=True
_bpy.context.window_manager.tag_script_reload()
import gc
print("gc.collect() -> %d" % gc.collect())
print("gc.collect() -> {:d}".format(gc.collect()))
if use_time:
print("Python Script Load Time %.4f" % (time.time() - t_main))
print("Python Script Load Time {:.4f}".format(time.time() - t_main))
if use_class_register_check:
for cls in _bpy.types.bpy_struct.__subclasses__():
if getattr(cls, "is_registered", False):
for subcls in cls.__subclasses__():
if not subcls.is_registered:
print(
"Warning, unregistered class: %s(%s)" %
(subcls.__name__, cls.__name__)
)
print("Warning, unregistered class: {:s}({:s})".format(subcls.__name__, cls.__name__))
def load_scripts_extensions(*, reload_scripts=False):
@@ -500,7 +497,7 @@ def preset_paths(subdir):
for path in script_paths(subdir="presets", check_all=True):
directory = _os.path.join(path, subdir)
if not directory.startswith(path):
raise Exception("invalid subdir given %r" % subdir)
raise Exception("invalid subdir given {!r}".format(subdir))
elif _os.path.isdir(directory):
dirs.append(directory)
@@ -595,13 +592,14 @@ def smpte_from_frame(frame, *, fps=None, fps_base=None):
frame = abs(frame)
return (
"%s%02d:%02d:%02d:%02d" % (
"{:s}{:02d}:{:02d}:{:02d}:{:02d}".format(
sign,
int(frame / (3600 * fps)), # HH
int((frame / (60 * fps)) % 60), # MM
int((frame / fps) % 60), # SS
int(frame % fps), # FF
))
)
)
def time_from_frame(frame, *, fps=None, fps_base=None):
@@ -728,7 +726,7 @@ def keyconfig_set(filepath, *, report=None):
# Get name, exception for default keymap to keep backwards compatibility.
if kc_new is None:
if report is not None:
report({'ERROR'}, "Failed to load keymap %r" % filepath)
report({'ERROR'}, "Failed to load keymap {!r}".format(filepath))
return False
else:
keyconfigs.active = kc_new
@@ -764,7 +762,7 @@ def user_resource(resource_type, *, path="", create=False):
traceback.print_exc()
target_path = ""
elif not _os.path.isdir(target_path):
print("Path %r found but isn't a directory!" % target_path)
print("Path {!r} found but isn't a directory!".format(target_path))
target_path = ""
return target_path
@@ -856,7 +854,7 @@ def register_tool(tool_cls, *, after=None, separator=False, group=False):
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
if cls is None:
raise Exception("Space type %r has no toolbar" % space_type)
raise Exception("Space type {!r} has no toolbar".format(space_type))
tools = cls._tools[context_mode]
# First sanity check
@@ -866,9 +864,9 @@ def register_tool(tool_cls, *, after=None, separator=False, group=False):
if item is not None
}
if not issubclass(tool_cls, WorkSpaceTool):
raise Exception("Expected WorkSpaceTool subclass, not %r" % type(tool_cls))
raise Exception("Expected WorkSpaceTool subclass, not {!r}".format(type(tool_cls)))
if tool_cls.bl_idname in tools_id:
raise Exception("Tool %r already exists!" % tool_cls.bl_idname)
raise Exception("Tool {!r} already exists!".format(tool_cls.bl_idname))
del tools_id, WorkSpaceTool
# Convert the class into a ToolDef.
@@ -968,7 +966,7 @@ def unregister_tool(tool_cls):
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
if cls is None:
raise Exception("Space type %r has no toolbar" % space_type)
raise Exception("Space type {!r} has no toolbar".format(space_type))
tools = cls._tools[context_mode]
tool_def = tool_cls._bl_tool
@@ -1020,7 +1018,7 @@ def unregister_tool(tool_cls):
break
if not changed:
raise Exception("Unable to remove %r" % tool_cls)
raise Exception("Unable to remove {!r}".format(tool_cls))
del tool_cls._bl_tool
keymap_data = tool_def.keymap
@@ -1033,7 +1031,7 @@ def unregister_tool(tool_cls):
continue
km = kc.keymaps.get(keymap_data[0])
if km is None:
print("Warning keymap %r not found in %r!" % (keymap_data[0], kc.name))
print("Warning keymap {!r} not found in {!r}!".format(keymap_data[0], kc.name))
else:
kc.keymaps.remove(km)
@@ -1069,7 +1067,7 @@ def manual_map():
try:
prefix, url_manual_mapping = cb()
except:
print("Error calling %r" % cb)
print("Error calling {!r}".format(cb))
import traceback
traceback.print_exc()
continue
@@ -1145,7 +1143,7 @@ def make_rna_paths(struct_name, prop_name, enum_name):
if prop_name:
src = src_rna = ".".join((struct_name, prop_name))
if enum_name:
src = src_enum = "%s:'%s'" % (src_rna, enum_name)
src = src_enum = "{:s}:'{:s}'".format(src_rna, enum_name)
else:
src = src_rna = struct_name
return src, src_rna, src_enum