updated bootstrap script for non developers
zeffii opened this issue · 26 comments
the long form of the script... node readall()
should now be read()
import re
import os
import zipfile
import urllib
import json
import bpy
from urllib.request import urlopen
def get_raw_url_from_gist_id(gist_id):
gist_id = str(gist_id)
url = 'https://api.github.com/gists/' + gist_id
found_json = urlopen(url).readall().decode()
wfile = json.JSONDecoder()
wjson = wfile.decode(found_json)
files_flag = 'files'
file_names = list(wjson[files_flag].keys())
file_name = file_names[0]
return wjson[files_flag][file_name]['raw_url']
def get_gist_as_string(gist_id):
url = get_raw_url_from_gist_id(gist_id)
conn = urlopen(url).readall().decode()
return conn
def get_sv():
print("getting sverchok bootstrapper")
string_load = get_gist_as_string("5a4440e7455940174ab9")
svbl = bpy.data.texts.new('sverchok bootloader')
svbl.write(string_load)
print("obtained bootstrapper code from github")
# until a tidier solution comes along
ctx = bpy.context.copy()
ctx['edit_text'] = svbl # specify the text datablock to execute
bpy.ops.text.run_script(ctx)
print("execution bootstrapper complete")
get_sv()
that could be truncated even further to:
import re
import os
import zipfile
import urllib
import bpy
from urllib.request import urlopen
def get_sv():
url = "".join([
"https://gist.githubusercontent.com/zeffii/",
"5a4440e7455940174ab9/raw/",
"39fcbbd3692da87b920ab48fb2f6c664aca74af4/",
"bootstrap.py"])
print("getting sverchok bootstrapper")
string_load = urlopen(url).readall().decode()
svbl = bpy.data.texts.new('sverchok bootloader')
svbl.write(string_load)
print("obtained bootstrapper code from github")
ctx = bpy.context.copy()
ctx['edit_text'] = svbl # specify the text datablock to execute
bpy.ops.text.run_script(ctx)
print("execution bootstrapper complete")
get_sv()
The above script does the following (beware, this is a like a matroska doll, scripts inside scripts):
- download the real bootstrap script
- the script it produces
- downloads the zip
- renames it to sverchok
- places it in scripts/addons
- enables it
Thus:
small script -> gets bigger script -> bigger script knows how to download, unpack and install Sverchok.
apparently this script doesn't work on win10 64 build of Blender. error 'HTTPResponse has no attribute 'readall' .. but works fine on ubuntu64
works on 2.93 or 3.0
import re
import os
import zipfile
import urllib
import bpy
from urllib.request import urlopen
# 2.93 or 3.0 ... you don't need to set this manually anymore.
MAJOR, MINOR = bpy.app.version_file[0:2]
blender_version = f"{MAJOR}.{MINOR}"
url = "https://gist.githubusercontent.com/zeffii/5a4440e7455940174ab9/raw/bootstrap.py"
def get_sv():
print("getting sverchok bootstrapper")
string_load = urlopen(url).read().decode()
# depending on the current version...
new_string_load = re.sub("version=(\d\.\d+)", f"version={blender_version}", string_load)
svbl = bpy.data.texts.new('sverchok bootloader')
svbl.write(new_string_load)
print("obtained bootstrapper code from github")
ctx = bpy.context.copy()
ctx['edit_text'] = svbl # specify the text datablock to execute
bpy.ops.text.run_script(ctx)
print("execution bootstrapper complete")
get_sv()
i got this error when running on my macbook:
Traceback (most recent call last):
File "/Users/cd/Downloads/install_sverchok.blend/InstallSverchok", line 34, in
File "/Applications/Blender.app/Contents/Resources/3.0/scripts/modules/bpy/ops.py", line 130, in call
ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Traceback (most recent call last):
File "/Applications/Blender.app/Contents/Resources/3.0/scripts/modules/addon_utils.py", line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named 'sverchok'
Error: Python script failed, check the message in the system console
If you used the "install Addon" button in Blender preferences, then Blender will put the add-on in a system-specific folder.
as you use osx, if you get the message no module named sverchok
, then Blender is not finding a folder named sverchok
in any of the scripts
subdirs in https://docs.blender.org/manual/en/latest/advanced/blender_directory_layout.html#macos
maybe Blender 3.0 needs to be given permissions to modify the filesystem ? else Python can not create a directory to unzip the sverchok source correctly.
Maybe - but why did all other adons work?🙈
beats me.
Or don’t they create folders? I don’t know. You are the expert.
ok, don't know why and don't know how...maybe because i downloaded the newest blender3.0 alpha....but all of a sudden it showed now for the first time the 1.0 version in sverchok and i could enable it. And believe or not ....rendering works too now. But i have no idea why i now could see 1.0 and it worked. Whenever i saw 1.0 version until now, i wasn't able to enable it.
rename it to sverchok , the extra -1.0.0-beta.2
turns the folder into an invalid module name i think... for the enable
step
correct, i have no explanation at the moment for the folder being called sverchok-0
unless that's what happens if you have two folders called sverchok
, there might be some autorenaming of new folders..
next "clean try" was: renaming it to sverchok BEFORE enabling, same result with "no module named 'sverchok-1' ...it's weird.
if there was no other folder in scripts/addons
called sverchok
, then there should be no reason for Blender to automatically rename that folder, this suggests to me that there are parallel folders ( system specific as listed above ) that do have a folder named sverchok
and blender attempts to avoid name collisions over all the potential folders.
but i'm not certain.
nope, that's why i wrote "clean try" and copied the folder structure as screenshot for you. There were no sverchok folders.
well.. now you've seen the dirtier side of add-on development.
I just cannot believe I am the only one with a macOS having this problem….🙈
https://gist.github.com/zeffii/a325ab87931114311198c4571322b82b
this is a slightly modified that drops features i planned but never used.
ok, don't know why and don't know how...maybe because i downloaded the newest blender3.0 alpha....but all of a sudden it showed now for the first time the 1.0 version in sverchok and i could enable it. And believe or not ....rendering works too now. But i have no idea why i now could see 1.0 and it worked. Whenever i saw 1.0 version until now, i wasn't able to enable it.
Wow this works!! Thank you haha...After trying with many versions I gave it a try and it worked.