Repository navigation
Distribute COMPAS for Blender as a Blender extension #1541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a63122
Replace compas_blender installer with a Blender extension
gonzalocasas 526876a
Build Blender extension in CI and attach it to releases
gonzalocasas 6109129
Pin Ubuntu CI runner to 24.04, the last image with Python 3.9
gonzalocasas ea35385
Upload each Blender extension package as its own artifact
gonzalocasas 6e96e1c
Correct wording
gonzalocasas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| name: blender_extension | ||
|
|
||
| # Builds the COMPAS Blender extension packages (one per Blender version range and platform) | ||
| # and uploads each package as its own, unzipped workflow artifact. | ||
| # Called by the release workflow, which attaches the packages to the GitHub release, | ||
| # and run on pull requests that touch the Blender integration. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| paths: | ||
| - "extensions/blender/**" | ||
| - "src/compas_blender/**" | ||
| - "requirements.txt" | ||
| - ".github/workflows/blender_extension.yml" | ||
|
|
||
| env: | ||
| # Any Blender >= 4.2 can build packages for all supported Blender versions. | ||
| BLENDER_VERSION: "5.2.4" | ||
|
|
||
| jobs: | ||
| build: | ||
| name: build (Blender ${{ matrix.blender }}, ${{ matrix.platform }}) | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - { blender: "4.2-5.0", python: "3.11", platform: windows-x64 } | ||
| - { blender: "4.2-5.0", python: "3.11", platform: macos-arm64 } | ||
| - { blender: "4.2-5.0", python: "3.11", platform: macos-x64 } | ||
| - { blender: "4.2-5.0", python: "3.11", platform: linux-x64 } | ||
| - { blender: "5.1+", python: "3.13", platform: windows-x64 } | ||
| - { blender: "5.1+", python: "3.13", platform: windows-arm64 } | ||
| - { blender: "5.1+", python: "3.13", platform: macos-arm64 } | ||
| - { blender: "5.1+", python: "3.13", platform: linux-x64 } | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install Blender runtime libraries | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y --no-install-recommends \ | ||
| libx11-6 libxi6 libxxf86vm1 libxfixes3 libxrender1 libxkbcommon0 \ | ||
| libsm6 libice6 libgl1 libegl1 | ||
|
|
||
| - name: Cache Blender | ||
| id: cache-blender | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/blender | ||
| key: blender-${{ env.BLENDER_VERSION }}-linux-x64 | ||
|
|
||
| - name: Download Blender | ||
| if: steps.cache-blender.outputs.cache-hit != 'true' | ||
| run: | | ||
| series="${BLENDER_VERSION%.*}" | ||
| curl -sSfL "https://download.blender.org/release/Blender${series}/blender-${BLENDER_VERSION}-linux-x64.tar.xz" | tar -xJ -C ~ | ||
| mv ~/blender-${BLENDER_VERSION}-linux-x64 ~/blender | ||
|
|
||
| - name: Check Blender | ||
| run: ~/blender/blender --version | ||
|
|
||
| - name: Build extension package | ||
| run: python extensions/blender/build.py --blender ~/blender/blender --python ${{ matrix.python }} --platform ${{ matrix.platform }} | ||
|
|
||
| # Uploaded unzipped, so the artifact is the extension package itself (named after the file). | ||
| - uses: actions/upload-artifact@v7 | ||
| with: | ||
| path: dist/blender/*.zip | ||
| archive: false | ||
| if-no-files-found: error | ||
| retention-days: 14 | ||
|
|
||
| # Downloads the packages the same way the release workflow does, to catch problems before a release. | ||
| check: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/download-artifact@v8 | ||
| with: | ||
| pattern: compas-*.zip | ||
| path: dist/blender | ||
| merge-multiple: true | ||
| skip-decompress: true | ||
|
|
||
| - name: Check extension packages | ||
| run: | | ||
| ls -l dist/blender | ||
| count=0 | ||
| for package in dist/blender/*.zip; do | ||
| unzip -l "$package" | grep -q " blender_manifest.toml$" || { echo "::error::$package is not an extension package"; exit 1; } | ||
| count=$((count + 1)) | ||
| done | ||
| [ "$count" -eq 8 ] || { echo "::error::Expected 8 extension packages, found $count"; exit 1; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # COMPAS Blender extension | ||
|
|
||
| Source of the [Blender extension](https://docs.blender.org/manual/en/latest/advanced/extensions/getting_started.html) that distributes COMPAS for Blender 4.2 and newer. | ||
|
|
||
| * `addon/` contains the extension source: the add-on `__init__.py` and the source `blender_manifest.toml`. | ||
| * `build.py` builds the extension packages into `dist/blender`, one per Blender version range and platform, | ||
| bundling the `compas` wheel and all its dependencies (except `numpy`, which ships with Blender). | ||
|
|
||
| ```bash | ||
| invoke build-blender-extension --blender /path/to/blender | ||
| ``` | ||
|
|
||
| The manifest `version` is kept in sync by `bump-my-version`; `blender_version_max`, `platforms` and `wheels` | ||
| are generated by `build.py` for each build. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| """COMPAS for Blender. | ||
|
|
||
| This extension only bundles COMPAS and its dependencies as Python wheels. | ||
| Blender installs them into the extensions site-packages folder, so once the | ||
| extension is enabled, ``compas`` and ``compas_blender`` can be imported from | ||
| any script, the Python console, or other add-ons. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| import bpy | ||
|
|
||
|
|
||
| class COMPAS_AddonPreferences(bpy.types.AddonPreferences): | ||
| bl_idname = __package__ | ||
|
|
||
| def draw(self, context): | ||
| layout = self.layout | ||
| try: | ||
| import compas | ||
| except ImportError as error: | ||
| layout.label(text="COMPAS could not be imported: {}".format(error), icon="ERROR") | ||
| return | ||
|
|
||
| column = layout.column(align=True) | ||
| column.label(text="COMPAS {}".format(compas.__version__), icon="CHECKMARK") | ||
| column.label(text=os.path.dirname(os.path.dirname(compas.__file__))) | ||
|
|
||
|
|
||
| classes = (COMPAS_AddonPreferences,) | ||
|
|
||
|
|
||
| def register(): | ||
| for cls in classes: | ||
| bpy.utils.register_class(cls) | ||
|
|
||
|
|
||
| def unregister(): | ||
| for cls in reversed(classes): | ||
| bpy.utils.unregister_class(cls) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why support 3.9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of Rhino 8, I would suggest to support 3.9 at the very least until Rhino 9 has been officially released, otherwise we drop testing on the "main stable" target for Rhino