blendercam/scripts/addons/fabex/tests/install_addon.py

53 wiersze
1.8 KiB
Python

import pathlib
import shutil
import subprocess
import sys
import tempfile
INSTALL_CODE = f"""
2024-12-18 15:21:37 +00:00
import bpy
bpy.context.preferences.system.use_online_access = True
bpy.ops.extensions.repo_sync_all(use_active_only=False)
2024-12-18 15:54:43 +00:00
bpy.ops.extensions.package_install_files(filepath='{sys.argv[1]}', repo='user_default')
2024-12-18 15:21:37 +00:00
bpy.ops.extensions.package_install(repo_index=0, pkg_id="stl_format_legacy")
bpy.ops.extensions.package_install(repo_index=0, pkg_id="simplify_curves_plus")
bpy.ops.extensions.package_install(repo_index=0, pkg_id="curve_tools")
bpy.ops.wm.save_userpref()
"""
2024-12-18 01:03:52 +00:00
NUM_RETRIES = 10
2024-01-13 08:30:34 +00:00
2024-12-18 15:21:37 +00:00
with tempfile.TemporaryDirectory() as td:
file = pathlib.Path(td, "install.py")
file.write_text(INSTALL_CODE)
2024-12-19 01:05:27 +00:00
command = [shutil.which("blender"), "-b", "-P", str(file)]
2024-12-18 15:21:37 +00:00
# blender 4.0 installing addon crashes sometimes on mac github actions...
for x in range(NUM_RETRIES):
try:
subprocess.run(
2024-12-19 01:05:27 +00:00
command,
2024-12-18 15:21:37 +00:00
shell=False,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
2024-12-20 12:45:59 +00:00
print("Addon Install: Success!")
2024-12-18 15:21:37 +00:00
sys.exit(0)
2024-12-19 01:24:52 +00:00
except subprocess.CalledProcessError as e:
2024-12-20 12:45:59 +00:00
print("Addon Install: Failed!")
print(f"Retrying: {e}")
print("Command Output:")
2024-12-19 01:19:33 +00:00
print("------------------------------")
print(e.output)
print("------------------------------")
for line in str(e.output):
if line.startswith("Writing: "):
crash_file = pathlib.Path(line[len("Writing: ") :])
if crash_file.exists():
print("Crash log:\n================")
print(crash_file.read_text())
print("============================")