Core: Make BLENDER_SYSTEM_SCRIPTS always add paths
Originally this would replace scripts that come bundled with Blender, but it's unclear how this is useful. Searching for this online mainly leads to people asking how they can use it to add scripts. For example in a studio environment you might want to deploy add-ons and startup scripts for all users. Even if you wanted to use it for replacement though, it wasn't really doing that and inconsistent for different types of scripts: * startup: ignored * modules: replaces bundled scripts * presets: adds to bundled scripts * addons (in 4.1): ignored * addons_core (in 4.2): ignored * startup/bl_app_templates_system: replaces bundled scripts This change makes it add scripts from this path for all. This is a breaking change, though arguably this feature was just broken to begin with and not used much in practice because of that. The alternative would be add a new set of environment variables to avoid breaking existing behavior. But that also means keeping around the broken behavior or fixing it in another way. Supporting multiple paths may be used too, but for now just support a single one as doing this for all BLENDER_SYSTEM variables is non-trivial. The main use case for that would be add-ons anyway, and those will mainly be handled through upcoming BLENDER_SYSTEM_EXTENSIONS instead. Ref #122512 Pull Request: https://projects.blender.org/blender/blender/pulls/122689
This commit is contained in:
committed by
Brecht Van Lommel
parent
15ec49ff28
commit
f7797a90f6
@@ -378,7 +378,13 @@ def script_paths_pref():
|
||||
return paths
|
||||
|
||||
|
||||
def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True):
|
||||
def script_paths_system_environment():
|
||||
"""Returns a list of system script directories from environment variables."""
|
||||
if env_system_path := _os.environ.get("BLENDER_SYSTEM_SCRIPTS"):
|
||||
return [_os.path.normpath(env_system_path)]
|
||||
return []
|
||||
|
||||
def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True, use_system_environment=True):
|
||||
"""
|
||||
Returns a list of valid script paths.
|
||||
|
||||
@@ -388,6 +394,10 @@ def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True)
|
||||
:type user_pref: bool
|
||||
:arg check_all: Include local, user and system paths rather just the paths Blender uses.
|
||||
:type check_all: bool
|
||||
:arg use_user: Include user paths
|
||||
:type use_user: bool
|
||||
:arg use_system_environment: Include BLENDER_SYSTEM_SCRIPTS variable path
|
||||
:type use_system_environment: bool
|
||||
:return: script paths.
|
||||
:rtype: list
|
||||
"""
|
||||
@@ -419,6 +429,9 @@ def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True)
|
||||
if user_pref:
|
||||
base_paths.extend(script_paths_pref())
|
||||
|
||||
if use_system_environment:
|
||||
base_paths.extend(script_paths_system_environment())
|
||||
|
||||
scripts = []
|
||||
for path in base_paths:
|
||||
if not path:
|
||||
@@ -473,16 +486,22 @@ def app_template_paths(*, path=None):
|
||||
"""
|
||||
subdir_args = (path,) if path is not None else ()
|
||||
# Note: keep in sync with: Blender's 'BKE_appdir_app_template_any'.
|
||||
# Uses 'BLENDER_USER_SCRIPTS', 'BLENDER_SYSTEM_SCRIPTS'
|
||||
# ... in this case 'system' accounts for 'local' too.
|
||||
for resource_fn, module_name in (
|
||||
(_user_resource, "bl_app_templates_user"),
|
||||
(system_resource, "bl_app_templates_system"),
|
||||
):
|
||||
path_test = resource_fn('SCRIPTS', path=_os.path.join("startup", module_name, *subdir_args))
|
||||
if path_test and _os.path.isdir(path_test):
|
||||
# Uses BLENDER_USER_SCRIPTS
|
||||
path_test = _user_resource('SCRIPTS', path=_os.path.join("startup", "bl_app_templates_user", *subdir_args))
|
||||
if path_test and _os.path.isdir(path_test):
|
||||
yield path_test
|
||||
|
||||
# Uses BLENDER_SYSTTEM_SCRIPTS
|
||||
for path in script_paths_system_environment():
|
||||
path_test = _os.path.join(path, "startup", "bl_app_templates_system", *subdir_args)
|
||||
if _os.path.isdir(path_test):
|
||||
yield path_test
|
||||
|
||||
# Uses default local or system location.
|
||||
path_test = system_resource('SCRIPTS', path=_os.path.join("startup", "bl_app_templates_system", *subdir_args))
|
||||
if path_test and _os.path.isdir(path_test):
|
||||
yield path_test
|
||||
|
||||
|
||||
def preset_paths(subdir):
|
||||
"""
|
||||
@@ -494,7 +513,7 @@ def preset_paths(subdir):
|
||||
:rtype: list
|
||||
"""
|
||||
dirs = []
|
||||
for path in script_paths(subdir="presets", check_all=True):
|
||||
for path in script_paths(subdir="presets"):
|
||||
directory = _os.path.join(path, subdir)
|
||||
if not directory.startswith(path):
|
||||
raise Exception("invalid subdir given {!r}".format(subdir))
|
||||
|
||||
Reference in New Issue
Block a user