homemaker-addon icon indicating copy to clipboard operation
homemaker-addon copied to clipboard

Blender 4.2 support

Open Andrej730 opened this issue 1 year ago • 15 comments

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).

blender-homemaker-2024-08-27-01.zip

Andrej730 avatar Aug 27 '24 10:08 Andrej730

Thanks @Andrej730 I've created a new release: https://github.com/brunopostle/homemaker-addon/releases/tag/2024-09-01

brunopostle avatar Sep 01 '24 10:09 brunopostle

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's bl_idname now - 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.path and 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 avatar Sep 01 '24 12:09 Andrej730

@Andrej730 thanks, I can see that there is a lot to do to switch to an Extension, for reference:

  • [x] remove blender_manifest.toml from the legacy add-on zip archive for now
  • [x] topologic is now topologic_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_idname to __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 Floor can't be rewritten as from . import floor.Floor as Floor so something else will be required~
  • [x] bundle molior and topologist as wheels
  • [x] figure-out how to find the share folder from inside a molior wheel
  • [x] bundle the topologic_core and pyyaml wheels
  • [x] re-add blender_manifest.toml

brunopostle avatar Sep 01 '24 22:09 brunopostle

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 avatar Sep 01 '24 22:09 Moult

@moult yes it looks like I'm going to have to create a couple of wheels for my molior and topologist modules :(

brunopostle avatar Sep 01 '24 23:09 brunopostle

Some examples of how to do a lazy wheel https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/Makefile#L194-L219

Moult avatar Sep 01 '24 23:09 Moult

Ah cool, so no need to create setup.py files

brunopostle avatar Sep 01 '24 23:09 brunopostle

Yay, a blender 4.2 extension: https://github.com/brunopostle/homemaker-addon/releases/tag/2024-09-03

brunopostle avatar Sep 03 '24 22:09 brunopostle

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

Andrej730 avatar Sep 04 '24 06:09 Andrej730

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.

brunopostle avatar Sep 04 '24 06:09 brunopostle

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.

Andrej730 avatar Sep 04 '24 07:09 Andrej730

..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.

brunopostle avatar Sep 04 '24 09:09 brunopostle

🤔

try:
    import .molior
except ImportError:
    import molior

brunopostle avatar Sep 04 '24 10:09 brunopostle

🧐

try:
    import molior
except ImportError:
    import .molior

brunopostle avatar Sep 04 '24 10:09 brunopostle

Now with relative imports: https://github.com/brunopostle/homemaker-addon/releases/tag/2024-09-04

brunopostle avatar Sep 05 '24 07:09 brunopostle