Fix bpy.utils.script_paths() ignoring environment variables
When check_all=True was passed,
- `os.path.join(bpy.utils.resource_path('USER'), "scripts")`
was used instead of BLENDER_USER_SCRIPTS.
- `os.path.join(bpy.utils.resource_path('SYSTEM'), "scripts")`
was used instead of BLENDER_SYSTEM_SCRIPTS.
Other minor changes:
- Simplify collecting paths.
- Don't add user-directories multiple times when check_all=True.
- Normalize paths before before checking duplicates to reduce the
change the same path is added multiple times.
Found these issues while investigating T101389.
This commit is contained in:
@@ -358,56 +358,50 @@ def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True)
|
|||||||
:return: script paths.
|
:return: script paths.
|
||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
scripts = []
|
|
||||||
|
|
||||||
# Only script paths Blender uses.
|
if check_all or use_user:
|
||||||
#
|
path_system, path_user = _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.
|
base_paths = []
|
||||||
if not use_user:
|
|
||||||
base_paths = base_paths[:1]
|
|
||||||
|
|
||||||
if check_all:
|
if check_all:
|
||||||
# All possible paths, no duplicates, keep order.
|
# Order: 'LOCAL', 'USER', 'SYSTEM' (where user is optional).
|
||||||
|
if path_local := resource_path('LOCAL'):
|
||||||
|
base_paths.append(_os.path.join(path_local, "scripts"))
|
||||||
if use_user:
|
if use_user:
|
||||||
test_paths = ('LOCAL', 'USER', 'SYSTEM')
|
base_paths.append(path_user)
|
||||||
else:
|
base_paths.append(path_system) # Same as: `system_resource('SCRIPTS')`.
|
||||||
test_paths = ('LOCAL', 'SYSTEM')
|
|
||||||
|
|
||||||
base_paths = (
|
# Note that `_script_base_dir` may be either:
|
||||||
*(path for path in (
|
# - `os.path.join(bpy.utils.resource_path('LOCAL'), "scripts")`
|
||||||
_os.path.join(resource_path(res), "scripts")
|
# - `bpy.utils.system_resource('SCRIPTS')`.
|
||||||
for res in test_paths) if path not in base_paths),
|
# When `check_all` is enabled duplicate paths will be added however
|
||||||
*base_paths,
|
# paths are de-duplicated so it wont cause problems.
|
||||||
)
|
base_paths.append(_script_base_dir)
|
||||||
|
|
||||||
test_paths = (
|
if not check_all:
|
||||||
*base_paths,
|
if use_user:
|
||||||
*((script_path_user(),) if use_user else ()),
|
base_paths.append(path_user)
|
||||||
*((script_path_pref(),) if user_pref else ()),
|
|
||||||
)
|
|
||||||
|
|
||||||
for path in test_paths:
|
if user_pref:
|
||||||
if path:
|
base_paths.append(script_path_pref())
|
||||||
path = _os.path.normpath(path)
|
|
||||||
if path not in scripts and _os.path.isdir(path):
|
|
||||||
scripts.append(path)
|
|
||||||
|
|
||||||
if subdir is None:
|
scripts = []
|
||||||
return scripts
|
for path in base_paths:
|
||||||
|
if not path:
|
||||||
|
continue
|
||||||
|
|
||||||
scripts_subdir = []
|
path = _os.path.normpath(path)
|
||||||
for path in scripts:
|
if subdir is not None:
|
||||||
path_subdir = _os.path.join(path, subdir)
|
path = _os.path.join(path, subdir)
|
||||||
if _os.path.isdir(path_subdir):
|
|
||||||
scripts_subdir.append(path_subdir)
|
|
||||||
|
|
||||||
return scripts_subdir
|
if path in scripts:
|
||||||
|
continue
|
||||||
|
if not _os.path.isdir(path):
|
||||||
|
continue
|
||||||
|
scripts.append(path)
|
||||||
|
|
||||||
|
return scripts
|
||||||
|
|
||||||
|
|
||||||
def refresh_script_paths():
|
def refresh_script_paths():
|
||||||
|
|||||||
Reference in New Issue
Block a user