[Bf-blender-cvs] [43973410f3c] master: Cleanup: use f-string for addon_utils

Campbell Barton noreply at git.blender.org
Sat Jul 14 09:31:43 CEST 2018


Commit: 43973410f3c0a6ab17be3a7899c64fee1787c61e
Author: Campbell Barton
Date:   Sat Jul 14 09:30:59 2018 +0200
Branches: master
https://developer.blender.org/rB43973410f3c0a6ab17be3a7899c64fee1787c61e

Cleanup: use f-string for addon_utils

===================================================================

M	release/scripts/modules/addon_utils.py

===================================================================

diff --git a/release/scripts/modules/addon_utils.py b/release/scripts/modules/addon_utils.py
index c4097bed33b..5cb313ec41b 100644
--- a/release/scripts/modules/addon_utils.py
+++ b/release/scripts/modules/addon_utils.py
@@ -78,7 +78,7 @@ def modules_refresh(module_cache=addons_fake_modules):
         try:
             file_mod = open(mod_path, "r", encoding='UTF-8')
         except OSError as ex:
-            print("Error opening file %r: %s" % (mod_path, ex))
+            print("Error opening file:", mod_path, ex)
             return None
 
         with file_mod:
@@ -116,7 +116,7 @@ def modules_refresh(module_cache=addons_fake_modules):
         try:
             ast_data = ast.parse(data, filename=mod_path)
         except:
-            print("Syntax error 'ast.parse' can't read %r" % mod_path)
+            print("Syntax error 'ast.parse' can't read:", repr(mod_path))
             import traceback
             traceback.print_exc()
             ast_data = None
@@ -138,7 +138,7 @@ def modules_refresh(module_cache=addons_fake_modules):
                 mod.__file__ = mod_path
                 mod.__time__ = os.path.getmtime(mod_path)
             except:
-                print("AST error parsing bl_info for %s" % mod_name)
+                print("AST error parsing bl_info for:", mod_name)
                 import traceback
                 traceback.print_exc()
                 raise
@@ -148,8 +148,11 @@ def modules_refresh(module_cache=addons_fake_modules):
 
             return mod
         else:
-            print("fake_module: addon missing 'bl_info' "
-                  "gives bad performance!: %r" % mod_path)
+            print(
+                "fake_module: addon missing 'bl_info' "
+                "gives bad performance!:",
+                repr(mod_path),
+            )
             return None
 
     modules_stale = set(module_cache.keys())
@@ -167,17 +170,21 @@ def modules_refresh(module_cache=addons_fake_modules):
             mod = module_cache.get(mod_name)
             if mod:
                 if mod.__file__ != mod_path:
-                    print("multiple addons with the same name:\n  %r\n  %r" %
-                          (mod.__file__, mod_path))
+                    print(
+                        "multiple addons with the same name:\n"
+                        "  " f"{mod.__file__!r}" "\n"
+                        "  " f"{mod_path!r}"
+                    )
                     error_duplicates.append((mod.bl_info["name"], mod.__file__, mod_path))
 
                 elif mod.__time__ != os.path.getmtime(mod_path):
-                    print("reloading addon:",
-                          mod_name,
-                          mod.__time__,
-                          os.path.getmtime(mod_path),
-                          mod_path,
-                          )
+                    print(
+                        "reloading addon:",
+                        mod_name,
+                        mod.__time__,
+                        os.path.getmtime(mod_path),
+                        repr(mod_path),
+                    )
                     del module_cache[mod_name]
                     mod = None
 
@@ -233,10 +240,12 @@ def check(module_name):
     )
 
     if loaded_state is Ellipsis:
-        print("Warning: addon-module %r found module "
-              "but without __addon_enabled__ field, "
-              "possible name collision from file: %r" %
-              (module_name, getattr(mod, "__file__", "<unknown>")))
+        print(
+            "Warning: addon-module " f"{module_name:s}" " found module "
+            "but without '__addon_enabled__' field, "
+            "possible name collision from file:",
+            repr(getattr(mod, "__file__", "<unknown>")),
+        )
 
         loaded_state = False
 
@@ -303,8 +312,10 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
             try:
                 mod.unregister()
             except Exception as ex:
-                print("Exception in module unregister(): %r" %
-                      getattr(mod, "__file__", module_name))
+                print(
+                    "Exception in module unregister():",
+                    repr(getattr(mod, "__file__", module_name)),
+                )
                 handle_error(ex)
                 return None
 
@@ -313,7 +324,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
         mtime_new = os.path.getmtime(mod.__file__)
         if mtime_orig != mtime_new:
             import importlib
-            print("module changed on disk:", mod.__file__, "reloading...")
+            print("module changed on disk:", repr(mod.__file__), "reloading...")
 
             try:
                 importlib.reload(mod)
@@ -343,7 +354,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
         except Exception as ex:
             # if the addon doesn't exist, dont print full traceback
             if type(ex) is ImportError and ex.name == module_name:
-                print("addon not found: %r" % module_name)
+                print("addon not found:", repr(module_name))
             else:
                 handle_error(ex)
 
@@ -358,8 +369,10 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
         try:
             mod.register()
         except Exception as ex:
-            print("Exception in module register(): %r" %
-                  getattr(mod, "__file__", module_name))
+            print(
+                "Exception in module register():",
+                getattr(mod, "__file__", module_name),
+            )
             handle_error(ex)
             del sys.modules[module_name]
             if default_set:
@@ -406,12 +419,15 @@ def disable(module_name, *, default_set=False, handle_error=None):
         try:
             mod.unregister()
         except Exception as ex:
-            print("Exception in module unregister(): %r" %
-                  getattr(mod, "__file__", module_name))
+            mod_path = getattr(mod, "__file__", module_name)
+            print("Exception in module unregister():", repr(mod_path))
+            del mod_path
             handle_error(ex)
     else:
-        print("addon_utils.disable: %s not %s." %
-              (module_name, "disabled" if mod is None else "loaded"))
+        print(
+            "addon_utils.disable: " f"{module_name:s}" " not",
+            ("disabled" if mod is None else "loaded")
+        )
 
     # could be in more than once, unlikely but better do this just in case.
     if default_set:



More information about the Bf-blender-cvs mailing list