diff --git a/bpy_addon_build/__init__.py b/bpy_addon_build/__init__.py index 40b8ea3..055aab9 100644 --- a/bpy_addon_build/__init__.py +++ b/bpy_addon_build/__init__.py @@ -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!") diff --git a/bpy_addon_build/args.py b/bpy_addon_build/args.py index 4cabdf0..a9adfa7 100644 --- a/bpy_addon_build/args.py +++ b/bpy_addon_build/args.py @@ -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: diff --git a/bpy_addon_build/build_context.py b/bpy_addon_build/build_context.py index 8695c12..8ada679 100644 --- a/bpy_addon_build/build_context.py +++ b/bpy_addon_build/build_context.py @@ -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 @@ -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: """