[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26072] trunk/blender/release/scripts/ modules/bpy/__init__.py: python script reloading (f8)

Campbell Barton ideasman42 at gmail.com
Mon Jan 18 11:02:56 CET 2010


Revision: 26072
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26072
Author:   campbellbarton
Date:     2010-01-18 11:02:55 +0100 (Mon, 18 Jan 2010)

Log Message:
-----------
python script reloading (f8)
- reload modules from types that are not directly included. for example wm.py uses classes from modules/rna_prop_ui.py which wasnt reloaded.
- script paths were being added to sys.path multiple times.

note: now the second reload gives a crash right away but this is a bug elsewhere.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/__init__.py

Modified: trunk/blender/release/scripts/modules/bpy/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/__init__.py	2010-01-18 08:38:53 UTC (rev 26071)
+++ trunk/blender/release/scripts/modules/bpy/__init__.py	2010-01-18 10:02:55 UTC (rev 26072)
@@ -46,7 +46,11 @@
 
     t_main = time.time()
 
+    loaded_modules = set()
+
     def test_import(module_name):
+        if module_name in loaded_modules:
+            return None
         if "." in module_name:
             print("Ignoring '%s', can't import files containing multiple periods." % module_name)
             return None
@@ -61,12 +65,25 @@
             traceback.print_exc()
             return None
 
+    if reload_scripts:
+        # reload modules that may not be directly included
+        for type_class_name in dir(types):
+            type_class = getattr(types, type_class_name)
+            module_name = getattr(type_class, "__module__", "")
 
+            if module_name and module_name != "bpy.types": # hard coded for C types
+               loaded_modules.add(module_name)
+
+        for module_name in loaded_modules:
+            print("Reloading:", module_name)
+            reload(sys.modules[module_name])
+
     for base_path in utils.script_paths():
         for path_subdir in ("ui", "op", "io"):
             path = os.path.join(base_path, path_subdir)
             if os.path.isdir(path):
-                sys.path.insert(0, path)
+                if path not in sys.path: # reloading would add twice
+                    sys.path.insert(0, path)
                 for f in sorted(os.listdir(path)):
                     if f.endswith(".py"):
                         # python module





More information about the Bf-blender-cvs mailing list