Skip to content

Commit

Permalink
Do not use tomllib (external dep, not available
Browse files Browse the repository at this point in the history
  • Loading branch information
howetuft committed Jan 2, 2025
1 parent 38042b1 commit 9433902
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
32 changes: 22 additions & 10 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
print("here")
import tempfile
import platform
import os
import sys
import subprocess
from shutil import which
import pathlib
import tomlkit

import bpy
import addon_utils
Expand Down Expand Up @@ -35,7 +35,7 @@ def install_pyluxcore():
# Download wheel
root_folder = pathlib.Path(__file__).parent.resolve()
wheel_folder = root_folder / "wheels"
args = [
command = [
sys.executable,
'-m',
'pip',
Expand All @@ -44,21 +44,33 @@ def install_pyluxcore():
'-d',
wheel_folder
]
result = subprocess.run(args, capture_output=False)

if result.returncode != 0:
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
output = stdout.decode()
error_output = stderr.decode()
if output:
print("Output:\n", output)
if error_output:
print("Errors:\n", error_output)

if process.returncode != 0:
raise RuntimeError(f'Failed to download LuxCore with return code {result.returncode}.') from None

# Setup manifest with wheel list
manifest_path = root_folder / "blender_manifest.toml"
with open(manifest_path, "r") as fp:
manifest = tomlkit.load(fp)
files, *_ = os.walk(wheel_folder)
wheels = [os.path.join(".", "wheels", f) for f in files[2]]
print("Wheels: ", wheels)
manifest["wheels"] = wheels
wheel_statement = f"\nwheels = {wheels}\n"
print(wheel_statement)

with open(manifest_path, "r") as fp:
manifest = list(fp)
with open(manifest_path, "w") as fp:
tomlkit.dump(manifest, fp)
for line in manifest:
if line.startswith("## WHEELS ##"):
fp.write(wheel_statement)
else:
fp.write(line)

# Ask Blender to do the install
addon_utils.extensions_refresh(ensure_wheels=True)
Expand Down
3 changes: 2 additions & 1 deletion blender_manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ platforms = ["windows-x64", "macos-arm64", "linux-x64", "macos-x64"]

# # Optional: bundle 3rd party Python modules.
# # https://docs.blender.org/manual/en/dev/advanced/extensions/python_wheels.html
# wheels = []
# DO NOT ALTER following line, it will be replaced by actual wheel list at runtime
## WHEELS ##

# # Optional: add-ons can list which resources they will require:
# # * files (for access of any filesystem operations)
Expand Down

0 comments on commit 9433902

Please sign in to comment.