fix [#28005] Python Add-Ons are constantly reloaded if twice in the path
authorCampbell Barton <ideasman42@gmail.com>
Mon, 18 Jul 2011 05:41:46 +0000 (05:41 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 18 Jul 2011 05:41:46 +0000 (05:41 +0000)
Addons are checked for their timestamps and reloaded when it changes but this failed when, 2 addons had the same name since different times caused 2 reloads on every redraw.

Now when duplicate addons are in the path now give a error message in the UI and print path conflict in the console and don't thrash reloading.

release/scripts/modules/addon_utils.py
release/scripts/startup/bl_ui/space_userpref.py

index 07f1dc618dcc4223e03f3dbf8892ca62af7cc651..cf74282d06489a05d88f5b74ce8bd6fed181abc5 100644 (file)
@@ -31,6 +31,8 @@ __all__ = (
 import bpy as _bpy
 
 
+error_duplicates = False
+
 def paths():
     # RELEASE SCRIPTS: official scripts distributed in Blender releases
     paths = _bpy.utils.script_paths("addons")
@@ -47,8 +49,11 @@ def paths():
 
 
 def modules(module_cache):
+    global error_duplicates
     import os
 
+    error_duplicates = False
+
     path_list = paths()
 
     # fake module importing
@@ -117,7 +122,12 @@ def modules(module_cache):
             modules_stale -= {mod_name}
             mod = module_cache.get(mod_name)
             if mod:
-                if mod.__time__ != os.path.getmtime(mod_path):
+                if mod.__file__ != mod_path:
+                    print("multiple addons with the same name:\n  %r\n  %r" %
+                          (mod.__file__, mod_path))
+                    error_duplicates = True
+
+                elif mod.__time__ != os.path.getmtime(mod_path):
                     print("reloading addon:", mod_name, mod.__time__, os.path.getmtime(mod_path), mod_path)
                     del module_cache[mod_name]
                     mod = None
index 6a809aefb9dfbf98df6daae06ebe457258fa8dcf..139b3205835d3c7847e8f4418666cc3f20847514 100644 (file)
@@ -889,6 +889,16 @@ class USERPREF_PT_addons(bpy.types.Panel):
                 return True
         return False
 
+    @staticmethod
+    def draw_error(layout, message):
+        lines = message.split("\n")
+        box = layout.box()
+        rowsub = box.row()
+        rowsub.label(lines[0])
+        rowsub.label(icon='ERROR')
+        for l in lines[1:]:
+            box.label(l)
+
     def draw(self, context):
         layout = self.layout
 
@@ -909,6 +919,14 @@ class USERPREF_PT_addons(bpy.types.Panel):
 
         col = split.column()
 
+        # set in addon_utils.modules(...)
+        if addon_utils.error_duplicates:
+            self.draw_error(col,
+                            "Multiple addons using the same name found!\n"
+                            "likely a problem with the script search path.\n"
+                            "(see console for details)",
+                            )
+
         filter = context.window_manager.addon_filter
         search = context.window_manager.addon_search.lower()
         support = context.window_manager.addon_support