taichi-dev / taichi_elements

High-performance multi-material continuum physics engine in Taichi
MIT License
483 stars 69 forks source link

[Blender] Deploy in ZIP format for Blender-friendly addon installation #59

Open archibate opened 4 years ago

archibate commented 4 years ago

The traditional addon installation manner for Blender is via ZIP files instead of PyPI.

I recently succeed to deploy taichi_blend as a ZIP file, without using pip, which make the installation easier and less error-prone.

I use the following command for creating a ZIP archive that contains all the requried dependencies:

mkdir Taichi-Blend
pip install taichi taichi_blend -t Taichi-Blend  # install all dependencies of `taichi_blend` to that directory
cp bundle.py Taichi-Blend/__init__.py
zip -r Taichi-Blend.zip Taichi-Blend

The content of Taichi-Blend is:

astor                     easy_install.py           __pycache__
astor-0.8.1.dist-info     include                   setuptools
bin                       __init__.py               setuptools-50.1.0.dist-info
colorama                  numpy                     sourceinspect
colorama-0.4.3.dist-info  numpy-1.19.1.dist-info    sourceinspect-0.0.3.dist-info
dill                      numpy.libs                taichi
dill-0.3.2.dist-info      pkg_resources             taichi-0.6.31.dist-info
_distutils_hack           pybind11                  taichi_blend
distutils-precedence.pth  pybind11-2.5.0.dist-info  taichi_blend-0.0.1.dist-info

And the content of bundle.py is:

import sys
import os

bl_info = {
        ...
}

for p in sys.path:
    bundle_path = os.path.join(p, 'Taichi-Blend')
    if os.path.exists(bundle_path):
        break
else:
    raise Exception('Cannot find Taichi-Blend!')

def register():
    print('Found Taichi-Blend at', bundle_path)
    if bundle_path not in sys.path:
        sys.path.insert(0, bundle_path)  # add our Taichi-Blend to import path so that people can `import taichi`

def unregister():
    if bundle_path in sys.path:
        sys.path.remove(bundle_path)

So, maybe we can apply the same to taichi_elements by:

pip install taichi taichi_elements -t Taichi-Elements

and release the generated Taichi-Elements.zip?

The only difficulty is that different OS use different taichi_core.so, we may have 3 buildbots for Taichi-Elements-linux.zip, Taichi-Elements-win.zip, Taichi-Elements-osx.zip.

EaryChow commented 3 years ago

Why didn't I see this when I made that video ( ̄ェ ̄;) https://www.bilibili.com/video/BV1rt4y1S7PJ I made this video without the knowledge of this taichi_blend thing (; ̄д ̄) I should have included this in that video ( ̄ェ ̄;)

My method in that video was to make use of the pip that comes with Blender instead of downloading another version of pip online.

For taichi_elements , I simply extracted the blender folder and the engine folder, put engine in blender , zip the blender folder and rename it to "taichi_elements", and now this zip file can already be installed using the standard blender-addon way.

I still think my method is useful though. If people want the latest version, they still need to do it manually. My method is simpler than the method described in taichi elements' README.md nevertheless.