Bundle BBIM as a wheel

Yes we really did it
This commit is contained in:
Dion Moult
2024-07-18 20:20:34 +10:00
parent 30623ba333
commit 5b96b4a414
7 changed files with 91 additions and 88 deletions
@@ -1,51 +0,0 @@
import importlib
import bpy
import types
from typing import Any
BBIM = None
MODULE_CACHE = {}
def __getattr__(name: str):
bbim = find_blenderbim_package()
return getattr(bbim, name)
class Wrapper:
def __init__(self, module):
self.module = module
def __getattribute__(self, name: str):
module = object.__getattribute__(self, "module")
try:
attr = getattr(module, name)
return attr
except AttributeError:
pass
# I guess it's a submodule.
name = f"{module.__name__}.{name}"
return get_wrapped_module(name)
def __dir__(self):
return dir(self.module)
def get_wrapped_module(name: str) -> Wrapper:
module = MODULE_CACHE.get(name)
if module:
return module
return Wrapper(importlib.import_module(name))
def find_blenderbim_package() -> types.ModuleType:
global BBIM
if BBIM is not None:
return BBIM
for package_name in bpy.context.preferences.addons.keys():
if package_name.endswith(".blenderbim"):
BBIM = Wrapper(importlib.import_module(package_name))
return BBIM
raise Exception("blenderbim is not found.")
+32
View File
@@ -0,0 +1,32 @@
import os
import sys
def find_whl_files(directory):
whl_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".whl"):
whl_files.append(os.path.relpath(os.path.join(root, file), directory))
return whl_files
def update_pyproject_toml(pyproject_path, whl_files):
with open(pyproject_path, "a") as f:
f.write("\nwheels = [\n")
for whl in whl_files:
f.write(f' "./wheels/{whl}",\n')
f.write("]\n")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py <folder_path> <pyproject.toml_path>")
sys.exit(1)
folder_path = sys.argv[1]
pyproject_toml_path = sys.argv[2]
whl_files = find_whl_files(folder_path)
update_pyproject_toml(pyproject_toml_path, whl_files)
print("pyproject.toml has been updated with the wheel files.")