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