Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-08-15 08:53:11 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-08-15 09:09:15 +0300
commitbb2394a29889157a330bd1064d248c04055b117c (patch)
treea0ae32c821655a54724be59434ae65818645367e /release/scripts/modules/bpy
parent7c258a8ad1b04a91d24b015fed6c5eae020bf8cc (diff)
Fix T68014: Add-on's override Python built-in modules
Append addon paths to the sys.path to avoid name collisions with system modules.
Diffstat (limited to 'release/scripts/modules/bpy')
-rw-r--r--release/scripts/modules/bpy/utils/__init__.py18
1 files changed, 12 insertions, 6 deletions
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):