From 4b0b0191ba2df14e1ed45d9bd82ffee6f76feb86 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 5 Feb 2025 16:39:40 +0500 Subject: [PATCH] Test enabling/disabling Bonsai before uploading to unstable repo #6075 --- .github/workflows/ci-bonsai-daily.yml | 58 +++++++++++++++++-------- src/bonsai/Makefile | 6 +++ src/bonsai/scripts/reregister_bonsai.py | 32 ++++++++++++++ 3 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 src/bonsai/scripts/reregister_bonsai.py diff --git a/.github/workflows/ci-bonsai-daily.yml b/.github/workflows/ci-bonsai-daily.yml index 1168c31776..03b7f6a8c5 100644 --- a/.github/workflows/ci-bonsai-daily.yml +++ b/.github/workflows/ci-bonsai-daily.yml @@ -99,9 +99,9 @@ jobs: token: ${{ secrets.IOS_TO_BLENDER_REPO }} path: bonsai_unstable_repo - - name: Update index.json on extensions repo + - name: Download Blender and run critical tests run: | - set -x -e + # Ensure Bonsai and ifcsverchok enable/disable works before uploading to extensions repo. # Download Blender. wget -q -O blender.tar.xz https://ftp.nluug.nl/pub/graphics/blender/release/Blender4.3/blender-4.3.0-linux-x64.tar.xz @@ -112,6 +112,41 @@ jobs: export PATH="$PATH:$BLENDER_PATH" blender --version + # Install Bonsai. + blender --command extension install-file -r user_default -e $bonsai_zip + blender --command extension list + + git clone https://github.com/IfcOpenShell/IfcOpenShell.git IfcOpenShell + + # Reregister Bonsai. + # Note that running it in background might miss some errors + # (e.g. tools are not registered in background mode). + blender --background --python IfcOpenShell/src/bonsai/scripts/reregister_bonsai.py + + # Install sverchok. + wget -q -O sverchok.zip https://github.com/nortikin/sverchok/archive/refs/heads/master.zip + # ifcsverchok expecting sverchok to be named "sverchok" and not "sverchok-master". + unzip -q sverchok.zip + mv sverchok-master sverchok + zip -q -r sverchok.zip sverchok + rm -r sverchok + blender --command extension install-file -r user_default sverchok.zip + + # Install ifcsverchok. + cd IfcOpenShell/src/ifcsverchok + make dist + sverchok_zip="$(pwd)/dist/$(ls dist)" + blender --command extension install-file -r user_default $sverchok_zip + + - name: Update index.json on extensions repo + run: | + set -x -e + + # Setup Blender. + BLENDER_PATH=$(find blender-*/ -maxdepth 0 -exec readlink -f {} \;) + export PATH="$PATH:$BLENDER_PATH" + blender --version + cd bonsai_unstable_repo pip install -r requirements.txt python setup_extensions_repo.py --last-tag @@ -121,6 +156,7 @@ jobs: git add readme.md git commit -m "Update index.json" git push + - name: Run bonsai tests run: | set -x -e @@ -128,28 +164,12 @@ jobs: export PATH="$PATH:$BLENDER_PATH" bonsai_zip="$(pwd)/$(ls bonsai_unstable_repo/bonsai_py311*-linux-x64.zip)" blender --version - blender --command extension install-file -r user_default -e $bonsai_zip - blender --command extension list - - wget -q -O sverchok.zip https://github.com/nortikin/sverchok/archive/refs/heads/master.zip - # ifcsverchok expecting sverchok to be named "sverchok" and not "sverchok-master". - unzip -q sverchok.zip - mv sverchok-master sverchok - zip -q -r sverchok.zip sverchok - rm -r sverchok - blender --command extension install-file -r user_default sverchok.zip - - git clone https://github.com/IfcOpenShell/IfcOpenShell.git IfcOpenShell - cd IfcOpenShell/src/ifcsverchok - make dist - sverchok_zip="$(pwd)/dist/$(ls dist)" - blender --command extension install-file -r user_default $sverchok_zip # Install Sun Position extension. blender --online-mode --command extension sync blender --online-mode --command extension install --enable --sync sun_position - cd ../bonsai + cd IfcOpenShell/src/bonsai pip install pytest-blender blender --background --python scripts/setup_pytest.py blender --python-expr "import bonsai; print(bonsai.bbim_semver); import ifcopenshell; print(ifcopenshell.version)" --background diff --git a/src/bonsai/Makefile b/src/bonsai/Makefile index 3bd8b76473..e8d6c6c385 100644 --- a/src/bonsai/Makefile +++ b/src/bonsai/Makefile @@ -402,6 +402,12 @@ else pytest test/tool/test_$(MODULE).py endif +# Reregistering test is not added to the standard test suite because during unregister +# Blender removes all Bonsai dependencies breaking dev-environment symlinks. +.PHONY: test-reregister +test-reregister: + blender --python scripts/reregister_bonsai.py + .PHONY: qa qa: black . diff --git a/src/bonsai/scripts/reregister_bonsai.py b/src/bonsai/scripts/reregister_bonsai.py new file mode 100644 index 0000000000..437c9f5b34 --- /dev/null +++ b/src/bonsai/scripts/reregister_bonsai.py @@ -0,0 +1,32 @@ +# Bonsai - OpenBIM Blender Add-on +# Copyright (C) 2021 Nathan Hild +# +# This file is part of Bonsai. +# +# Bonsai is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Bonsai is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Bonsai. If not, see . + +""" +Disabling addon without issues is crucial for extension update to work. + +Use operators instead of `blender --command extension remove` +to ensure disable and enable occur in the same Blender session. +""" + + +import bpy +import bonsai.tool as tool + +bonsai_name = tool.Blender.get_blender_addon_package_name() +bpy.ops.preferences.addon_disable(module=bonsai_name) +bpy.ops.preferences.addon_enable(module=bonsai_name)