Skip to content

Commit

Permalink
Merge pull request #501 from BradyAJohnston/4.2
Browse files Browse the repository at this point in the history
Refactoring and feature adding for Blender 4.2
  • Loading branch information
BradyAJohnston authored Jul 17, 2024
2 parents 33a0785 + 841a130 commit a530633
Show file tree
Hide file tree
Showing 123 changed files with 25,373 additions and 11,833 deletions.
57 changes: 22 additions & 35 deletions .github/workflows/test-addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test in Blender

on:
push:
branches: ["main"]
branches: ["main", "4.2", "extensions-platform"]
pull_request:
branches: ["main", "4.1"]
branches: ["main", "4.2", "extensions-platform"]

jobs:
build:
Expand All @@ -13,57 +13,44 @@ jobs:
max-parallel: 4
fail-fast: false
matrix:
blender-version: ["4.1"]
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
# os: [macos-13]
blender-version: ["4.2"]
os: [ubuntu-latest, macos-14]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11.7

- name: Test in Blender MacOS Intel
if: matrix.os == 'macos-13'
run: |
curl -L -o blender.dmg https://download.blender.org/release/Blender4.1/blender-4.1.0-macos-x64.dmg
hdiutil attach blender.dmg
cp -R /Volumes/Blender/Blender.app /Applications/
hdiutil detach /Volumes/Blender
/Applications/Blender.app/Contents/MacOS/Blender --version
/Applications/Blender.app/Contents/MacOS/Blender -b --python tests/install.py
/Applications/Blender.app/Contents/MacOS/Blender -b --python tests/run.py -- -v
- name: Cache Blender
uses: actions/cache@v2
with:
path: ~/blender.tar.xz
key: ${{ runner.os }}-blender-${{ hashFiles('**/test-addon.yml') }}

- name: Test in Blender MacOS ARM
if: matrix.os == 'macos-14'
run: |
curl -L -o blender.dmg https://download.blender.org/release/Blender4.1/blender-4.1.0-macos-arm64.dmg
curl -L -o blender.dmg https://download.blender.org/release/Blender4.2/blender-4.2.0-macos-arm64.dmg
hdiutil attach blender.dmg
cp -R /Volumes/Blender/Blender.app /Applications/
hdiutil detach /Volumes/Blender
/Applications/Blender.app/Contents/MacOS/Blender --version
/Applications/Blender.app/Contents/MacOS/Blender -b --python tests/install.py
/Applications/Blender.app/Contents/MacOS/Blender -b --python tests/run.py -- -v
- name: Test in Blender Windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Invoke-WebRequest -Uri "https://download.blender.org/release/Blender4.1/blender-4.1.0-windows-x64.zip" -OutFile "blender.zip"
Expand-Archive -Path "blender.zip" -DestinationPath "blender"
.\blender\blender-4.1.0-windows-x64\blender.exe --version
.\blender\blender-4.1.0-windows-x64\blender.exe -b --python tests/install.py
.\blender\blender-4.1.0-windows-x64\blender.exe -b --python tests/run.py -- -v tests/
/Applications/Blender.app/Contents/MacOS/Blender -b --python tests/run.py -- -v tests/
- name: Test in Blender Linux
if: matrix.os == 'ubuntu-latest'
run: |
wget -nv https://download.blender.org/release/Blender4.1/blender-4.1.0-linux-x64.tar.xz
tar -xf blender-4.1.0-linux-x64.tar.xz
blender-4.1.0-linux-x64/blender --version
blender-4.1.0-linux-x64/blender -b --python tests/install.py
blender-4.1.0-linux-x64/blender -b --python tests/run.py -- -v tests/ --cov=molecularnodes --cov-report=xml:coverage.xml --ignore=molecularnodes/ui/panel.py
if [[ ! -f ./blender.tar.xz ]]; then
wget -nv https://download.blender.org/release/Blender4.2/blender-4.2.0-linux-x64.tar.xz -O ./blender.tar.xz
fi
mkdir -p ./blender
ls -lrta
tar -xf ./blender.tar.xz -C ./blender --strip-components=1
ls -lrta
blender/blender --version
blender/blender -b --python tests/install.py
blender/blender -b --python tests/run.py -- -v tests/ --cov=molecularnodes --cov-report=xml:coverage.xml --ignore=molecularnodes/ui/panel.py
- name: Expose coverage as a CI download
uses: actions/upload-artifact@v1
if: matrix.os == 'ubuntu-latest'
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*.blend1
__pycache__/*
.vscode/*
molecularnodes_*.zip
molecularnodes*.zip
*.pyc
.Rproj.user
/.quarto/
Expand All @@ -27,5 +27,5 @@ poetry.lock
*.vdb
docs/nodes/*.qmd
!docs/nodes/index.qmd


*.whl
*.MNSession
173 changes: 156 additions & 17 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,163 @@
import glob
import os
import zipfile
import subprocess
import sys
from dataclasses import dataclass
from typing import List, Union
import bpy

import tomlkit

# zips up the template file
def zip_template():
# Define the directory and zip file paths
dir_path = 'molecularnodes/assets/template/Molecular Nodes'
zip_file_path = 'molecularnodes/assets/template/Molecular Nodes.zip'
toml_path = "molecularnodes/blender_manifest.toml"
whl_path = "./molecularnodes/wheels"

# Create a ZipFile object in write mode
with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
# Walk the directory tree and add files to the zip file
for root, dirs, files in os.walk(dir_path):
for file in files:
# Get the path of the file
file_path = os.path.join(root, file)
# Add the file to the zip file
zipf.write(file_path, arcname=os.path.relpath(
file_path, start='molecularnodes/assets/template/'))

@dataclass
class Platform:
pypi_suffix: str
metadata: str


# tags for blender metadata
# platforms = ["windows-x64", "macos-arm64", "linux-x64", "windows-arm64", "macos-x64"]


windows_x64 = Platform(pypi_suffix="win_amd64", metadata="windows-x64")
linux_x64 = Platform(pypi_suffix="manylinux2014_x86_64", metadata="linux-x64")
macos_arm = Platform(pypi_suffix="macosx_12_0_arm64", metadata="macos-arm64")
macos_intel = Platform(pypi_suffix="macosx_10_16_x86_64", metadata="macos-x64")


required_packages = [
"mrcfile==1.4.3",
"starfile==0.5.6",
"MDAnalysis==2.7.0",
"biotite==0.41.2",
]


build_platforms = [
windows_x64,
linux_x64,
macos_arm,
macos_intel,
]


def run_python(args: str):
python = os.path.realpath(sys.executable)
subprocess.run([python] + args.split(" "))


def remove_whls():
for whl_file in glob.glob(os.path.join(whl_path, "*.whl")):
os.remove(whl_file)


def download_whls(
platforms: Union[Platform, List[Platform]],
required_packages: List[str] = required_packages,
python_version="3.11",
clean: bool = True,
):
if isinstance(platforms, Platform):
platforms = [platforms]

if clean:
remove_whls()

for platform in platforms:
run_python(
f"-m pip download {' '.join(required_packages)} --dest ./molecularnodes/wheels --only-binary=:all: --python-version={python_version} --platform={platform.pypi_suffix}"
)


def update_toml_whls(platforms):
# Define the path for wheel files
wheels_dir = "molecularnodes/wheels"
wheel_files = glob.glob(f"{wheels_dir}/*.whl")
wheel_files.sort()

# Packages to remove
packages_to_remove = {
"pyarrow",
"certifi",
"charset_normalizer",
"idna",
"numpy",
"requests",
"urllib3",
}

# Filter out unwanted wheel files
to_remove = []
to_keep = []
for whl in wheel_files:
if any(pkg in whl for pkg in packages_to_remove):
to_remove.append(whl)
else:
to_keep.append(whl)

# Remove the unwanted wheel files from the filesystem
for whl in to_remove:
os.remove(whl)

# Load the TOML file
with open(toml_path, "r") as file:
manifest = tomlkit.parse(file.read())

# Update the wheels list with the remaining wheel files
manifest["wheels"] = [f"./wheels/{os.path.basename(whl)}" for whl in to_keep]

# Simplify platform handling
if not isinstance(platforms, list):
platforms = [platforms]
manifest["platforms"] = [p.metadata for p in platforms]

# Write the updated TOML file
with open(toml_path, "w") as file:
file.write(
tomlkit.dumps(manifest)
.replace('["', '[\n\t"')
.replace("\\\\", "/")
.replace('", "', '",\n\t"')
.replace('"]', '",\n]')
)


def clean_files(suffix: str = ".blend1") -> None:
pattern_to_remove = f"molecularnodes/**/*{suffix}"
for blend1_file in glob.glob(pattern_to_remove, recursive=True):
os.remove(blend1_file)


def build_extension(split: bool = True) -> None:
for suffix in [".blend1", ".MNSession"]:
clean_files(suffix=suffix)

if split:
subprocess.run(
f"{bpy.app.binary_path} --command extension build"
" --split-platforms --source-dir molecularnodes --output-dir .".split(" ")
)
else:
subprocess.run(
f"{bpy.app.binary_path} --command extension build "
"--source-dir molecularnodes --output-dir .".split(" ")
)


def build(platform) -> None:
download_whls(platform)
update_toml_whls(platform)
build_extension()


def main():
# for platform in build_platforms:
# build(platform)
build(build_platforms)


if __name__ == "__main__":
zip_template()
main()
1 change: 0 additions & 1 deletion docs/.jupyter_cache/__version__.txt

This file was deleted.

Loading

0 comments on commit a530633

Please sign in to comment.