Blender 4.2 support
Creating an issue to keep track of Blender 4.2 support.
I've created an example build for tests with blenderbim replaced with bonsai in https://github.com/brunopostle/homemaker-addon/blob/main/init.py and topologic replaced with files from https://github.com/wassimj/Topologic/releases/tag/v6.0.3 (Blender 4.2 is using python 3.11).
Thanks @Andrej730 I've created a new release: https://github.com/brunopostle/homemaker-addon/releases/tag/2024-09-01
A couple notes - since blender_manifest.toml is present in the .zip, Blender will install it as an extension and there could be some issues:
- I believe preferences require
__package__as it'sbl_idnamenow - https://docs.blender.org/manual/en/4.2/extensions/addons.html#user-preferences-and-package
https://github.com/brunopostle/homemaker-addon/blob/7007df84889c2f5869071733b46c3a3f7f048e9d/init.py#L38-L47
- Blender will complain about modifying
sys.pathand importing other packages from the addon folder (extensions are expected to provide dependencies as wheels). It will lead to some warnings in the addon's preferences but not sure if it really breaks anything.
It's possible to exclude blender_manifest.toml from .zip to avoid solving issues. There is also a special installation that makes possible installing extensions as legacy addons - https://github.com/IfcOpenShell/IfcOpenShell/issues/4373#issuecomment-2242113593
@Andrej730 thanks, I can see that there is a lot to do to switch to an Extension, for reference:
- [x] remove
blender_manifest.tomlfrom the legacy add-on zip archive for now - [x]
topologicis nowtopologic_core, so will need to be referenced as such before it can be bundled as a wheel (I'll need to update the fedora package too) - [x] change
bl_idnameto__package__to get the preferences working in 4.2 - [x] ~figure out how to do relative imports instead of modifying
sys.path, eg.from molior.floor import Floorcan't be rewritten asfrom . import floor.Floor as Floorso something else will be required~ - [x] bundle
moliorandtopologistas wheels - [x] figure-out how to find the
sharefolder from inside amoliorwheel - [x] bundle the
topologic_coreandpyyamlwheels - [x] re-add
blender_manifest.toml
figure out how to do relative imports instead of modifying sys.path, eg. from molior.floor import Floor can't be rewritten as from . import floor.Floor as Floor so something else will be required
We cheated. We bundled the add-on itself as a wheel (apart from the init) and voila :)
@moult yes it looks like I'm going to have to create a couple of wheels for my molior and topologist modules :(
Some examples of how to do a lazy wheel https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/Makefile#L194-L219
Ah cool, so no need to create setup.py files
Yay, a blender 4.2 extension: https://github.com/brunopostle/homemaker-addon/releases/tag/2024-09-03
Works for me! 🎉
Though there are couple warnings during installation but it is expected for a multiple platform build.
Skipping wheel for other system (manylinux_2_17_x86_64.manylinux2014_x86_64 != win_amd64): PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Skipping wheel for other system (macosx_11_0_arm64 != win_amd64): PyYAML-6.0.2-cp311-cp311-macosx_11_0_arm64.whl
Skipping wheel for other system (linux_x86_64 != win_amd64): topologic_core-6.0.3-cp311-cp311-linux_x86_64.whl
Skipping wheel for other system (macosx_11_0_arm64 != win_amd64): topologic_core-6.0.3-cp311-cp311-macosx_11_0_arm64.whl
One thing that might be missing is versioning for generated wheels - if user will reinstall extension Blender will not reinstall the dependency if it already has the same version of it installed. So e.g. if there will be any changes to molior, the version in the wheel should be bumped, otherwise Blender might miss it:
https://github.com/brunopostle/homemaker-addon/blob/a329d9d3838552b460777b9151b5603c3fc56407/dist/Makefile#L23
I was afraid that it might have this behaviour with wheels. It looks like I'll have to bump the version automatically and template the manifest file. There is no documentation on this, and the UI for the extension site is 'upload a single file'.
I'd prefer to just bundle this code without turning it into a wheel, but it seems to be a deficiency in python that relative imports work fine within modules, but not between a script and subdirectories (without fiddling with the path).
I should download some blender extensions, this must be a common problem and maybe someone has solved it.
At first Blender recommended us to create a "blenderbim" wheel that would redirect all the queries from "blenderbim" to "bl_ext.xxxx.blenderbim". I had an attempt to do it in https://github.com/IfcOpenShell/IfcOpenShell/pull/5021#issuecomment-2233800016 and it worked but it still had those warnings but I never reported it back to Blender since we decided to pack the entire codebase into the wheel.
Maybe it is some Blender issue that it falsely recognizes those redirects as warnings or perhaps there is some other way to create this kind of redirection.
..so it looks like when you install an extension, blender registers it as a python module, so relative path imports do work, but only when running in blender.
ie. I can import .molior from my main script when molior is just a sub-folder.
Need to think about this a bit as it might get messy.
🤔
try:
import .molior
except ImportError:
import molior
🧐
try:
import molior
except ImportError:
import .molior
Now with relative imports: https://github.com/brunopostle/homemaker-addon/releases/tag/2024-09-04