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
+26 -7
View File
@@ -94,6 +94,16 @@ bump:
cd ../ifcopenshell-python/ && $(SED) -b "s/$(OLD)/$(NEW)/" Makefile
cd ../ifcopenshell-python/docs/ifcconvert/ && $(SED) -b "s/$(OLD)/$(NEW)/" installation.rst
.PHONY: dist-blenderbim
dist-blenderbim:
cp pyproject.toml pyproject.toml.bak
cp blenderbim/__init__.py __init__.py.bak
$(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' pyproject.toml
$(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' blenderbim/__init__.py
python -m build
mv pyproject.toml.bak pyproject.toml
mv __init__.py.bak blenderbim/__init__.py
.PHONY: dist
dist:
ifndef PLATFORM
@@ -244,18 +254,27 @@ endif
rm -rf dist/blenderbim/wheels/numpy*
ifeq ($(IS_STABLE), TRUE)
cd dist/blenderbim && $(SED) "s/0, 0, 0/$(VERSION_MAJOR), $(VERSION_MINOR), $(VERSION_PATCH)/" __init__.py
cd dist/blenderbim && $(SED) "s/0.0.0/$(VERSION)/" blender_manifest.toml
else
cd dist/blenderbim && $(SED) "s/0.0.0/$(VERSION)-$(VERSION_DATE)/" blender_manifest.toml
cd dist/blenderbim && $(SED) "s/8888888/$(LAST_COMMIT_HASH)/" __init__.py
endif
cd dist/blenderbim && $(SED) "s/os-arch/$(BLENDER_PLATFORM)/" blender_manifest.toml
# Provides BlenderBIM Add-on functionality
make dist-blenderbim && cp dist/*.whl ./dist/blenderbim/wheels/
$(PYTHON) scripts/get_wheels.py dist/blenderbim/wheels dist/blenderbim/blender_manifest.toml
rm -rf dist/blenderbim/bim/
rm -rf dist/blenderbim/core/
rm -rf dist/blenderbim/tool/
ifeq ($(IS_STABLE), TRUE)
cd dist && zip -r blenderbim_$(PYVERSION)-$(VERSION)-$(BLENDER_PLATFORM).zip ./*
else
cd dist/blenderbim && $(SED) "s/0, 0, 0/$(VERSION_MAJOR), $(VERSION_MINOR), $(VERSION_PATCH), $(VERSION_DATE)/" __init__.py
# Blender manifest version must be semver compatible.
cd dist/blenderbim && $(SED) "s/0.0.0/$(VERSION)-$(VERSION_DATE)/" blender_manifest.toml
cd dist/blenderbim && $(SED) "s/os-arch/$(BLENDER_PLATFORM)/" blender_manifest.toml
$(PYTHON) scripts/get_wheels.py dist/blenderbim/wheels dist/blenderbim/blender_manifest.toml
cd dist/blenderbim && $(SED) "s/8888888/$(LAST_COMMIT_HASH)/" __init__.py
cd dist && zip -r blenderbim_$(PYVERSION)-$(VERSION)-$(VERSION_DATE)-$(BLENDER_PLATFORM).zip ./*
endif
rm -rf dist/blenderbim
.PHONY: test
-28
View File
@@ -38,20 +38,6 @@ from pathlib import Path
from typing import Union, Any
# NOTE: bl_info is superseded by blender_manifest.toml
# if addon is installed as an extension (Blender 4.2+)
bl_info = {
"name": "BlenderBIM",
"description": "Transforms Blender into a native Building Information Model authoring platform using IFC.",
"author": "IfcOpenShell Contributors",
"blender": (3, 1, 0),
"version": (0, 0, 0),
"location": "File Menu, Scene Properties Tab. See documentation for more.",
"doc_url": "https://docs.blenderbim.org/",
"tracker_url": "https://github.com/IfcOpenShell/IfcOpenShell/issues",
"category": "System",
}
last_commit_hash = "8888888"
@@ -107,12 +93,6 @@ def format_debug_info(info: dict):
if IN_BLENDER:
# Process *.pth in /libs/site/packages to setup globally importable modules
# This is 3 levels deep as required by the static RPATH of ../../ from dependencies taken from Anaconda
# site.addsitedir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "libs", "site", "packages"))
site_path = Path(__file__).parent.resolve() / "libs" / "site" / "packages"
sys.path.insert(0, str(site_path))
def get_binary_info() -> dict[str, Any]:
info = {}
lib = site_path / "ifcopenshell"
@@ -165,14 +145,6 @@ if IN_BLENDER:
ifcopenshell.api.add_pre_listener("*", "action_logger", log_api)
def register():
global BLENDER_PACKAGE_NAME, __name__, __package__
BLENDER_PACKAGE_NAME = __name__
if bpy.app.version >= (4, 2, 0):
sys.modules["blenderbim"] = sys.modules[__name__]
__name__ = "blenderbim"
# Only renaming __name__ is actually required to make imports work.
# We renaming __package__ just for consistency.
__package__ = "blenderbim"
import blenderbim.bim
blenderbim.bim.register()
+3 -2
View File
@@ -1109,8 +1109,9 @@ class Blender(blenderbim.core.tool.Blender):
@classmethod
def get_blender_addon_package_name(cls) -> str:
if bpy.app.version >= (4, 2, 0):
return blenderbim.BLENDER_PACKAGE_NAME
for package_name in bpy.context.preferences.addons.keys():
if package_name.endswith(".blenderbim"):
return package_name
return "blenderbim"
@classmethod
+30
View File
@@ -0,0 +1,30 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "blenderbim"
version = "0.0.0"
authors = [
{ name="Dion Moult", email="dion@thinkmoult.com" },
]
description = "A native Building Information Model authoring platform using IFC"
keywords = ["IFC", "Blender", "BIM"]
classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"ifcopenshell",
]
[project.urls]
Homepage = "http://blenderbim.org"
Documentation = "https://docs.blenderbim.org"
Issues = "https://github.com/IfcOpenShell/IfcOpenShell/issues"
[tool.setuptools.packages.find]
include = ["blenderbim*"]
exclude = ["test*"]
[tool.setuptools.package-data]
"*" = ["*.*"]
@@ -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.")