Skip to content

Commit

Permalink
Added support for auto-installing
Browse files Browse the repository at this point in the history
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 ^_^
  • Loading branch information
StandingPadAnimations committed Sep 3, 2023
1 parent 9074c47 commit b10923d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bpy_addon_build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main() -> None:
return
if "install_versions" in data and isinstance(data["install_versions"], List):
versions = data["install_versions"]
if len(cli.versions):
if cli.versions:
versions = cli.versions
else:
print("install_versions must be list of floats!")
Expand Down
14 changes: 8 additions & 6 deletions bpy_addon_build/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ def path_validate(self, _: Attribute, value: Path) -> None:

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

@actions.validator
def actions_validate(self, _: Attribute, value: List[str]) -> None:
for act in value:
if not isinstance(act, str):
raise ValueError("Expect List of strings!")
if value:
for act in value:
if not isinstance(act, str):
raise ValueError("Expect List of strings!")


def parse_args() -> Args:
Expand Down
33 changes: 33 additions & 0 deletions bpy_addon_build/build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
from typing import Dict, List
from attrs import define, field, Attribute

INSTALL_PATHS: List[str] = [
"~/AppData/Roaming/Blender Foundation/Blender/{0}/scripts/addons",
"~/Library/Application Support/Blender/{0}/scripts/addons",
"~/.config/blender/{0}/scripts/addons",
]


# Must be ignored to pass Mypy as this has
# an expression of Any, likely due to how
Expand Down Expand Up @@ -130,6 +136,33 @@ def combine_with_build(path: Path) -> Path:
for act in self.defined_actions:
self.action(act, STAGE_ONE.joinpath(ADDON_FOLDER.name))
shutil.make_archive(str(combine_with_build(BUILD_DIR)), "zip", STAGE_ONE)
self.install(Path(str(combine_with_build(BUILD_DIR)) + ".zip"))

def install(self, build_path: Path) -> None:
"""
Installs the addon to the specified Blender
versions
build_path: Path to the built addon
Returns:
None
"""
for v in self.install_versions:
installed = False
for p in INSTALL_PATHS:
path = Path(p.format(str(v))).expanduser()
if not path.exists():
continue
else:
addon_path = path.joinpath(Path(self.build_name))
if addon_path.exists():
shutil.rmtree(addon_path)
shutil.unpack_archive(build_path, path)
print(f"Installed to {str(path)}")
installed = True
if not installed:
print(f"Cound not find {v}")

def action(self, action: str, folder: Path) -> None:
"""
Expand Down

0 comments on commit b10923d

Please sign in to comment.