Extensions: support using a default local user directory

This is needed so extensions repositories can reference
user-script directories without them having hard-coded paths
which will be invalid when upgrading a Blender version.
This commit is contained in:
Campbell Barton
2024-01-24 16:35:44 +11:00
parent f54348edc9
commit 9cc6ee75e7
4 changed files with 22 additions and 3 deletions
+2 -2
View File
@@ -68,7 +68,7 @@ def _paths_with_extension_repos():
for repo in _preferences.filepaths.extension_repos:
if not repo.enabled:
continue
dirpath = repo.directory
dirpath = repo.directory_or_default
if not os.path.isdir(dirpath):
continue
addon_paths.append((dirpath, "%s.%s" % (_ext_base_pkg_idname, repo.module)))
@@ -652,7 +652,7 @@ def _extension_dirpath_from_preferences():
for repo in _preferences.filepaths.extension_repos:
if not repo.enabled:
continue
repos_dict[repo.module] = repo.directory
repos_dict[repo.module] = repo.directory_or_default
return repos_dict
+12
View File
@@ -1307,6 +1307,18 @@ class RenderEngine(StructRNA, metaclass=RNAMeta):
__slots__ = ()
class UserExtensionRepo(StructRNA):
__slots__ = ()
@property
def directory_or_default(self):
"""Return ``directory`` or a default path derived from the users scripts path."""
if directory := self.directory:
return directory
import os
return os.path.join(_bpy.utils.user_resource('SCRIPTS', path="extensions"), self.module)
class HydraRenderEngine(RenderEngine):
__slots__ = ()
@@ -623,6 +623,10 @@ typedef struct bUserExtensionRepo {
*/
char module[48];
/**
* The "local" directory where extensions are stored.
* When unset, use `{BLENDER_USER_SCRIPTS}/extensions/{bUserExtensionRepo::module}`.
*/
char dirpath[1024]; /* FILE_MAX */
char remote_path[1024]; /* FILE_MAX */
@@ -6612,7 +6612,10 @@ static void rna_def_userdef_filepaths_extension_repo(BlenderRNA *brna)
prop = RNA_def_property(srna, "directory", PROP_STRING, PROP_DIRPATH);
RNA_def_property_string_sdna(prop, nullptr, "dirpath");
RNA_def_property_ui_text(prop, "Local Directory", "The local directory containing extensions");
RNA_def_property_ui_text(prop,
"Local Directory",
"The local directory containing extensions. "
"When unset, a path is used based on the user scripts path");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_EDITOR_FILEBROWSER);
RNA_def_property_string_funcs(
prop, nullptr, nullptr, "rna_userdef_extension_repo_directory_set");