[Bf-blender-cvs] [626b4b533af] temp-lanpr-staging: Fix T68014: Add-on's override Python built-in modules

Campbell Barton noreply at git.blender.org
Fri Aug 16 03:04:32 CEST 2019


Commit: 626b4b533afb25e9ed415e4f9caffe17785b7eec
Author: Campbell Barton
Date:   Thu Aug 15 15:53:11 2019 +1000
Branches: temp-lanpr-staging
https://developer.blender.org/rB626b4b533afb25e9ed415e4f9caffe17785b7eec

Fix T68014: Add-on's override Python built-in modules

Append addon paths to the sys.path to avoid name
collisions with system modules.

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

M	release/scripts/modules/addon_utils.py
M	release/scripts/modules/bpy/utils/__init__.py

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

diff --git a/release/scripts/modules/addon_utils.py b/release/scripts/modules/addon_utils.py
index 70768a102b3..376193f73a5 100644
--- a/release/scripts/modules/addon_utils.py
+++ b/release/scripts/modules/addon_utils.py
@@ -42,7 +42,7 @@ addons_fake_modules = {}
 def _initialize():
     path_list = paths()
     for path in path_list:
-        _bpy.utils._sys_path_ensure(path)
+        _bpy.utils._sys_path_ensure_append(path)
     for addon in _preferences.addons:
         enable(addon.module)
 
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index b39099158c6..04aaa7bd69d 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -119,11 +119,17 @@ def _test_import(module_name, loaded_modules):
     return mod
 
 
-def _sys_path_ensure(path):
-    if path not in _sys.path:  # reloading would add twice
+# Reloading would add twice.
+def _sys_path_ensure_prepend(path):
+    if path not in _sys.path:
         _sys.path.insert(0, path)
 
 
+def _sys_path_ensure_append(path):
+    if path not in _sys.path:
+        _sys.path.append(path)
+
+
 def modules_from_path(path, loaded_modules):
     """
     Load all modules in a path and return them as a list.
@@ -253,7 +259,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
             for path_subdir in _script_module_dirs:
                 path = _os.path.join(base_path, path_subdir)
                 if _os.path.isdir(path):
-                    _sys_path_ensure(path)
+                    _sys_path_ensure_prepend(path)
 
                     # Only add to 'sys.modules' unless this is 'startup'.
                     if path_subdir == "startup":
@@ -385,13 +391,13 @@ def refresh_script_paths():
         for path_subdir in _script_module_dirs:
             path = _os.path.join(base_path, path_subdir)
             if _os.path.isdir(path):
-                _sys_path_ensure(path)
+                _sys_path_ensure_prepend(path)
 
     for path in _addon_utils.paths():
-        _sys_path_ensure(path)
+        _sys_path_ensure_append(path)
         path = _os.path.join(path, "modules")
         if _os.path.isdir(path):
-            _sys_path_ensure(path)
+            _sys_path_ensure_append(path)
 
 
 def app_template_paths(subdir=None):



More information about the Bf-blender-cvs mailing list