[Bf-extensions-cvs] [c9460499] master: io_scene_gltf2: don't reload package on startup

Campbell Barton noreply at git.blender.org
Tue Feb 26 23:43:52 CET 2019


Commit: c94604993b3e0bfbc733861e890aff18513e02b4
Author: Campbell Barton
Date:   Wed Feb 27 09:41:28 2019 +1100
Branches: master
https://developer.blender.org/rBAc94604993b3e0bfbc733861e890aff18513e02b4

io_scene_gltf2: don't reload package on startup

package reloading should only ever be done on reload,
also move `bl_info` to the top of the file for faster parsing
and avoid importing `Path` since it's only needed for reloading.

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

M	io_scene_gltf2/__init__.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index bf2aed21..a67b62f6 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -12,14 +12,42 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+bl_info = {
+    'name': 'glTF 2.0 format',
+    'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen',
+    "version": (0, 0, 1),
+    'blender': (2, 80, 0),
+    'location': 'File > Import-Export',
+    'description': 'Import-Export as glTF 2.0',
+    'warning': '',
+    'wiki_url': "https://docs.blender.org/manual/en/dev/addons/io_gltf2.html",
+    'tracker_url': "https://github.com/KhronosGroup/glTF-Blender-IO/issues/",
+    'support': 'OFFICIAL',
+    'category': 'Import-Export',
+}
+
 #
-# Imports
+# Script reloading (if the user calls 'Reload Scripts' from Blender)
 #
 
-import importlib
-import os
-import time
-from pathlib import Path
+def reload_package(module_dict_main):
+    import importlib
+    from pathlib import Path
+    def reload_package_recursive(current_dir, module_dict):
+        for path in current_dir.iterdir():
+            if "__init__" in str(path) or path.stem not in module_dict:
+                continue
+
+            if path.is_file() and path.suffix == ".py":
+                importlib.reload(module_dict[path.stem])
+            elif path.is_dir():
+                reload_package_recursive(path, module_dict[path.stem].__dict__)
+
+    reload_package_recursive(Path(__file__).parent, module_dict_main)
+
+
+if "bpy" in locals():
+    reload_package(locals())
 
 import bpy
 from bpy.props import (StringProperty,
@@ -31,43 +59,6 @@ from bpy_extras.io_utils import ImportHelper, ExportHelper
 
 from .io.com.gltf2_io_debug import Log
 
-
-#
-# Script reloading (if the user calls 'Reload Scripts' from Blender)
-#
-
-def reload_recursive(current_dir: Path, module_dict):
-    for path in current_dir.iterdir():
-        if "__init__" in str(path) or path.stem not in module_dict:
-            continue
-
-        if path.is_file() and path.suffix == ".py":
-            importlib.reload(module_dict[path.stem])
-        elif path.is_dir():
-            reload_recursive(path, module_dict[path.stem].__dict__)
-
-
-directory = Path(__file__).parent
-reload_recursive(directory, locals())
-
-#
-# Globals
-#
-
-bl_info = {
-    'name': 'glTF 2.0 format',
-    'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen',
-    "version": (0, 0, 1),
-    'blender': (2, 80, 0),
-    'location': 'File > Import-Export',
-    'description': 'Import-Export as glTF 2.0',
-    'warning': '',
-    'wiki_url': "https://docs.blender.org/manual/en/dev/addons/io_gltf2.html",
-    'tracker_url': "https://github.com/KhronosGroup/glTF-Blender-IO/issues/",
-    'support': 'OFFICIAL',
-    'category': 'Import-Export'}
-
-
 #
 #  Functions / Classes.
 #
@@ -294,6 +285,7 @@ class ExportGLTF2_Base:
         context.scene[self.scene_key] = export_props
 
     def execute(self, context):
+        import os
         import datetime
         from .blender.exp import gltf2_blender_export
 
@@ -470,6 +462,7 @@ class ImportGLTF2(Operator, ImportHelper):
         return self.import_gltf2(context)
 
     def import_gltf2(self, context):
+        import time
         from .io.imp.gltf2_io_gltf import glTFImporter
         from .blender.imp.gltf2_blender_gltf import BlenderGlTF
 
@@ -522,4 +515,3 @@ def unregister():
     # remove from the export / import menu
     bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
     bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
-



More information about the Bf-extensions-cvs mailing list