From e723b060fc596876ec4778589a5d6c88027187db Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 18 Jan 2010 10:02:55 +0000 Subject: 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. --- release/scripts/modules/bpy/__init__.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'release/scripts/modules/bpy/__init__.py') diff --git a/release/scripts/modules/bpy/__init__.py b/release/scripts/modules/bpy/__init__.py index c760268d6f7..28f082c9bd1 100644 --- a/release/scripts/modules/bpy/__init__.py +++ b/release/scripts/modules/bpy/__init__.py @@ -46,7 +46,11 @@ def load_scripts(reload_scripts=False): 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 @@ def load_scripts(reload_scripts=False): 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 -- cgit v1.2.3