Skip to content

Commit b10923d

Browse files
Added support for auto-installing
Working on my birthday... *sigh* Anyway, Bpy-Build now supports automatically installing to specific Blender versions, either through the install_versions tag or the -v argument. Now Bpy-Build's basic functionality has been returned, yay... Also happy birthday to me ^_^
1 parent 9074c47 commit b10923d

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

bpy_addon_build/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main() -> None:
3535
return
3636
if "install_versions" in data and isinstance(data["install_versions"], List):
3737
versions = data["install_versions"]
38-
if len(cli.versions):
38+
if cli.versions:
3939
versions = cli.versions
4040
else:
4141
print("install_versions must be list of floats!")

bpy_addon_build/args.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ def path_validate(self, _: Attribute, value: Path) -> None:
3434

3535
@versions.validator
3636
def version_validate(self, _: Attribute, value: List[float]) -> None:
37-
for ver in value:
38-
if not isinstance(ver, float):
39-
raise ValueError("Expected List of floating point values!")
37+
if value:
38+
for ver in value:
39+
if not isinstance(ver, float):
40+
raise ValueError("Expected List of floating point values!")
4041

4142
@actions.validator
4243
def actions_validate(self, _: Attribute, value: List[str]) -> None:
43-
for act in value:
44-
if not isinstance(act, str):
45-
raise ValueError("Expect List of strings!")
44+
if value:
45+
for act in value:
46+
if not isinstance(act, str):
47+
raise ValueError("Expect List of strings!")
4648

4749

4850
def parse_args() -> Args:

bpy_addon_build/build_context.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
from typing import Dict, List
44
from attrs import define, field, Attribute
55

6+
INSTALL_PATHS: List[str] = [
7+
"~/AppData/Roaming/Blender Foundation/Blender/{0}/scripts/addons",
8+
"~/Library/Application Support/Blender/{0}/scripts/addons",
9+
"~/.config/blender/{0}/scripts/addons",
10+
]
11+
612

713
# Must be ignored to pass Mypy as this has
814
# an expression of Any, likely due to how
@@ -130,6 +136,33 @@ def combine_with_build(path: Path) -> Path:
130136
for act in self.defined_actions:
131137
self.action(act, STAGE_ONE.joinpath(ADDON_FOLDER.name))
132138
shutil.make_archive(str(combine_with_build(BUILD_DIR)), "zip", STAGE_ONE)
139+
self.install(Path(str(combine_with_build(BUILD_DIR)) + ".zip"))
140+
141+
def install(self, build_path: Path) -> None:
142+
"""
143+
Installs the addon to the specified Blender
144+
versions
145+
146+
build_path: Path to the built addon
147+
148+
Returns:
149+
None
150+
"""
151+
for v in self.install_versions:
152+
installed = False
153+
for p in INSTALL_PATHS:
154+
path = Path(p.format(str(v))).expanduser()
155+
if not path.exists():
156+
continue
157+
else:
158+
addon_path = path.joinpath(Path(self.build_name))
159+
if addon_path.exists():
160+
shutil.rmtree(addon_path)
161+
shutil.unpack_archive(build_path, path)
162+
print(f"Installed to {str(path)}")
163+
installed = True
164+
if not installed:
165+
print(f"Cound not find {v}")
133166

134167
def action(self, action: str, folder: Path) -> None:
135168
"""

0 commit comments

Comments
 (0)