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:
Diffstat (limited to 'release')
-rw-r--r--release/scripts/modules/bpy/utils/__init__.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 7f39cc5d422..d984a6f54a4 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -121,15 +121,25 @@ def _test_import(module_name, loaded_modules):
return mod
-# Reloading would add twice.
+# Check before adding paths as reloading would add twice.
+
+# Storing and restoring the full `sys.path` is risky as this may be intentionally modified
+# by technical users/developers.
+#
+# Instead, track which paths have been added, clearing them before refreshing.
+# This supports the case of loading a new preferences file which may reset scripts path.
+_sys_path_ensure_paths = set()
+
def _sys_path_ensure_prepend(path):
if path not in _sys.path:
_sys.path.insert(0, path)
+ _sys_path_ensure_paths.add(path)
def _sys_path_ensure_append(path):
if path not in _sys.path:
_sys.path.append(path)
+ _sys_path_ensure_paths.add(path)
def modules_from_path(path, loaded_modules):
@@ -391,6 +401,13 @@ def refresh_script_paths():
Run this after creating new script paths to update sys.path
"""
+ for path in _sys_path_ensure_paths:
+ try:
+ _sys.path.remove(path)
+ except ValueError:
+ pass
+ _sys_path_ensure_paths.clear()
+
for base_path in script_paths():
for path_subdir in _script_module_dirs:
path = _os.path.join(base_path, path_subdir)