From cb5e0a695f517ba0882ab5c69a8550f252b4dfa2 Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Sat, 5 Sep 2020 00:59:30 +0800 Subject: [PATCH 1/3] [Blender] Support bundled ZIP format distrubtion --- .gitignore | 1 + blender/__init__.py | 38 +++++++++++++++++++++++++++++++++----- make_bundle.sh | 9 +++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 make_bundle.sh diff --git a/.gitignore b/.gitignore index bcf673c..4f14554 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ htmlcov *.xml *.zip blender/engine +build/ diff --git a/blender/__init__.py b/blender/__init__.py index 7df46cf..95ea542 100644 --- a/blender/__init__.py +++ b/blender/__init__.py @@ -24,12 +24,40 @@ pass if use_blender: - from . import addon + import sys + import os - def register(): - addon.register() + use_bundle = False - def unregister(): - addon.unregister() + for p in sys.path: + bundle_path = os.path.join(p, 'Taichi-Elements', 'bundle') + if os.path.exists(bundle_path): + use_bundle = True + break + + if use_bundle: + def register(): + print('Found Taichi-Elements/bundle at', bundle_path) + if bundle_path not in sys.path: + sys.path.insert(0, bundle_path) + from . import addon + addon.register() + + def unregister(): + from . import addon + addon.unregister() + if bundle_path in sys.path: + sys.path.remove(bundle_path) + + else: + print('Cannot find Taichi-Elements/bundle, assuming PyPI install.') + + from . import addon + + def register(): + addon.register() + + def unregister(): + addon.unregister() # Otherwise act as a PyPI package diff --git a/make_bundle.sh b/make_bundle.sh new file mode 100644 index 0000000..4a33397 --- /dev/null +++ b/make_bundle.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e +mkdir -p build/Taichi-Elements/bundle +python3 -m pip install taichi -t build/Taichi-Elements/bundle +cp -r blender/* build/Taichi-Elements +cp -r engine build/Taichi-Elements +rm -f build/Taichi-Elements.zip +cd build && zip -r Taichi-Elements.zip Taichi-Elements From c0d7a6924e68e05184b3841803e247a3be7c0182 Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Sat, 5 Sep 2020 11:11:31 +0800 Subject: [PATCH 2/3] use requirements.txt --- .gitignore | 2 +- blender/__init__.py | 11 +++-------- blender/requirements.txt | 6 ++++++ make_bundle.sh | 6 +++++- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 blender/requirements.txt diff --git a/.gitignore b/.gitignore index 4f14554..04dfea0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ htmlcov *.xml *.zip blender/engine -build/ +/build diff --git a/blender/__init__.py b/blender/__init__.py index 95ea542..aecfd7d 100644 --- a/blender/__init__.py +++ b/blender/__init__.py @@ -27,19 +27,14 @@ import sys import os - use_bundle = False + bundle_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'bundle') - for p in sys.path: - bundle_path = os.path.join(p, 'Taichi-Elements', 'bundle') - if os.path.exists(bundle_path): - use_bundle = True - break - - if use_bundle: + if os.path.exists(bundle_path): def register(): print('Found Taichi-Elements/bundle at', bundle_path) if bundle_path not in sys.path: sys.path.insert(0, bundle_path) + # import addon after path is inserted, so that `import taichi` works from . import addon addon.register() diff --git a/blender/requirements.txt b/blender/requirements.txt new file mode 100644 index 0000000..982ec02 --- /dev/null +++ b/blender/requirements.txt @@ -0,0 +1,6 @@ +astor +colorama +dill +pybind11>=2.5.0 +sourceinspect>=0.0.3 +taichi diff --git a/make_bundle.sh b/make_bundle.sh index 4a33397..67185b3 100644 --- a/make_bundle.sh +++ b/make_bundle.sh @@ -1,9 +1,13 @@ #!/bin/bash set -e +rm -rf build/Taichi-Elements mkdir -p build/Taichi-Elements/bundle -python3 -m pip install taichi -t build/Taichi-Elements/bundle +python3 -m pip install --no-deps -r blender/requirements.txt -t build/Taichi-Elements/bundle cp -r blender/* build/Taichi-Elements cp -r engine build/Taichi-Elements +rm -rf build/Taichi-Elements/bundle/include +rm -rf build/Taichi-Elements/bundle/*.dist-info +rm -rf build/Taichi-Elements/bundle/bin rm -f build/Taichi-Elements.zip cd build && zip -r Taichi-Elements.zip Taichi-Elements From fa63c6eb184e6a4883c8a776ee3cc920d4c675d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BA=8E=E6=96=8C?= <1931127624@qq.com> Date: Fri, 30 Oct 2020 13:02:22 +0800 Subject: [PATCH 3/3] Update blender/__init__.py Co-authored-by: Yuanming Hu --- blender/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blender/__init__.py b/blender/__init__.py index aecfd7d..33e1287 100644 --- a/blender/__init__.py +++ b/blender/__init__.py @@ -45,7 +45,7 @@ def unregister(): sys.path.remove(bundle_path) else: - print('Cannot find Taichi-Elements/bundle, assuming PyPI install.') + print('Cannot find Taichi-Elements/bundle, assuming PyPI installation.') from . import addon