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 <campbell@blender.org>2022-09-21 04:59:16 +0300
committerCampbell Barton <campbell@blender.org>2022-09-21 05:01:49 +0300
commitf97728248ec95f4db5b0152dd3ba770135656e39 (patch)
treed35965ee462b3f31ba5f5aaaa861bc93e8af1bde /release
parent5517c848bdf18df758466c0c6c8b7389f9df558a (diff)
Fix module search path for Python on initialization
Initializing the sys.path on startup attempted to add subdirectories of {BLENDER_SYSTEM_SCRIPTS}: - ./modules/modules - ./modules/startup As the directories aren't expected to exist there is no need to add them. Also improved comments for path searching logic.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/modules/bpy/utils/__init__.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 54fcb4cdc67..a1e34731a94 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -61,9 +61,18 @@ import sys as _sys
import addon_utils as _addon_utils
_preferences = _bpy.context.preferences
-_script_module_dirs = "startup", "modules"
_is_factory_startup = _bpy.app.factory_startup
+# Directories added to the start of `sys.path` for all of Blender's "scripts" directories.
+_script_module_dirs = "startup", "modules"
+
+# Base scripts, this points to the directory containing: "modules" & "startup" (see `_script_module_dirs`).
+# In Blender's code-base this is `./release/scripts`.
+#
+# NOTE: in virtually all cases this should match `BLENDER_SYSTEM_SCRIPTS` as this script is it's self a system script,
+# it must be in the `BLENDER_SYSTEM_SCRIPTS` by definition and there is no need for a look-up from `_bpy_script_paths`.
+_script_base_dir = _os.path.dirname(_os.path.dirname(_os.path.dirname(_os.path.dirname(__file__))))
+
def execfile(filepath, *, mod=None):
"""
@@ -324,12 +333,6 @@ def load_scripts(*, reload_scripts=False, refresh_scripts=False):
)
-# base scripts
-_scripts = (
- _os.path.dirname(_os.path.dirname(_os.path.dirname(__file__))),
-)
-
-
def script_path_user():
"""returns the env var and falls back to home dir or None"""
path = _user_resource('SCRIPTS')
@@ -350,19 +353,20 @@ def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True)
:type subdir: string
:arg user_pref: Include the user preference script path.
:type user_pref: bool
- :arg check_all: Include local, user and system paths rather just the paths
- blender uses.
+ :arg check_all: Include local, user and system paths rather just the paths Blender uses.
:type check_all: bool
:return: script paths.
:rtype: list
"""
- scripts = list(_scripts)
+ scripts = []
- # Only paths Blender uses.
+ # Only script paths Blender uses.
#
- # Needed this is needed even when 'check_all' is enabled,
- # so the 'BLENDER_SYSTEM_SCRIPTS' environment variable will be used.
- base_paths = _bpy_script_paths()
+ # This is needed even when `check_all` is enabled.
+ # NOTE: Use `_script_base_dir` instead of `_bpy_script_paths()[0]` as it's taken from this files path.
+ base_paths = (_script_base_dir, )
+ if use_user:
+ base_paths += _bpy_script_paths()[1:]
# Defined to be (system, user) so we can skip the second if needed.
if not use_user: