summaryrefslogtreecommitdiff
path: root/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to '__init__.py')
-rw-r--r--__init__.py88
1 files changed, 53 insertions, 35 deletions
diff --git a/__init__.py b/__init__.py
index 6628161..0e6316c 100644
--- a/__init__.py
+++ b/__init__.py
@@ -3,36 +3,23 @@
# https://web.archive.org/web/20210925181415/https://blenderbrew.com/custom-application-templates-in-blender/
# elemental python modules blenxy needs
-# that the python interpreter must have built in
-import bpy, importlib, sys, subprocess, os, shutil
-import math, mathutils, warnings, struct, site
+# that the python interpreter to be used must have built in
+# python interpreter to be used has to be an external one (I am sick of the internal one)
+import bpy, importlib, sys, subprocess, os, shutil, io, copy
+import math, mathutils, warnings, struct, site, re, random
from . import file_ops # uses os and shutil modules
# elemental python modules blenxy needs
# that the python interpreter probably does not have built in/needs to be updated
-pip_modules = ["pip", "wheel", "setuptools"]
-new_modules = ["lxml", "numpy"]
+NEEDED_MODULE_NAMES = ["pip", "lxml", "numpy"]
# check which of the new modules needs to be installed
def new_mod_check(mod_names):
# variable to return
rtn = []
- # traverse into all the new_modules
- for mod_name in mod_names:
- # skip numpy if the numpy_bad folder was created
- if (mod_name == "numpy"):
- for path in site.getsitepackages():
- numpy_path = path + "/numpy"
- numpy_bad_path = path + "/numpy_bad"
- # rename the existing numpy folder to numpy bad and install newer numpy
- if (("2.79" in path) and ("site-packages" in path)
- and (file_ops.f_exists(numpy_bad_path) == False)):
- file_ops.rename(numpy_path, numpy_bad_path)
- rtn.append("numpy")
- break
- continue
-
+ # traverse into all the needed modules
+ for mod_name in NEEDED_MODULE_NAMES:
# try importing the module
try:
importlib.import_module(mod_name)
@@ -41,23 +28,29 @@ def new_mod_check(mod_names):
# done!
return rtn
-
+
+# find python interpreter
+def find_python_interpreter():
+ # start.bat/start.sh sends the python interpreter
+ # path as an argument to Blender the only argument it sends
+ return sys.argv[2]
+
# install given modules with pip but be sure to have pip first
def new_mod_install(mod_names):
# get python's interpreter binary path
- py_bin = bpy.app.binary_path_python
+ py_bin = find_python_interpreter()
pip_install = [py_bin, "-B", "-m", "pip", "install",
"--trusted-host", "pypi.python.org",
"--trusted-host", "files.pythonhosted.org",
"--trusted-host", "pypi.org",
- "-U", "--force-reinstall", "--only-binary", ":all:"]
+ "-U", "--only-binary", ":all:"]
# check if the pip module is available
try:
importlib.import_module("pip")
- except: # install pip
+ except: # install pip with ensurepip
subprocess.run([py_bin, "-B", "-m", "ensurepip"])
- subprocess.run(pip_install + pip_modules)
+ subprocess.run(pip_install + ["pip", "wheel", "setuptools"])
# install the rest of the modules
if (mod_names != []):
@@ -68,13 +61,14 @@ def new_mod_install(mod_names):
return False
# all blenxy custom modules
-blenxy_modules = ["basic_settings", # user settings blenxy has
+BLENXY_MODULES = ["basic_settings", # user settings blenxy has
"collada_superbmd_import", # custom importer for SuperBMD collada files
"collada_superbmd_export", # custom exporter for SuperBMD collada files
"obj_kcl_export", # custom exporter for OBJ files (collision)
"obj_neokclcreate_import", # custom importer for OBJ files (collision, NeoKCLCreate)
"bck_import", # custom importer for SMG BCK files
- "bck_export"] # custom exporter for SMG BCK files
+ "bck_export", # custom exporter for SMG BCK files
+ "bcsv_editing"] # custom interface for BCSV loading
# function used to refresh blenxy's custom modules
# so that they can be updated without closing blender
@@ -82,11 +76,11 @@ blenxy_modules = ["basic_settings", # user settings blenxy has
def unload_blenxy_stuff(dummy):
# execute the unregister functions from each module
# these functions won't die if the stuff to unregister isn't there
- for mod_name in blenxy_modules:
+ for mod_name in BLENXY_MODULES:
mod = importlib.import_module("." + mod_name, __package__)
mod.unregister()
# reload the modules in case they were modified (dev stuff)
- for mod_name in blenxy_modules:
+ for mod_name in BLENXY_MODULES:
mod = importlib.import_module("." + mod_name, __package__)
importlib.reload(mod)
@@ -94,20 +88,44 @@ def unload_blenxy_stuff(dummy):
def register():
# print the welcome
print("\nWelcome to Blenxy!")
- print("Running on Blender: %s\n" % (bpy.app.version.__str__()))
+ print("Running on Blender: %s" % (bpy.app.version.__str__()))
+ print("Using interpreter: %s\n" % (find_python_interpreter()))
+
+ # "fix" python3.7/lib/python3.7/ctypes/__init__.py
+ ctypes_path = importlib.__path__[0] # I assume this path is alright
+ ctypes_path = file_ops.get_path_str(ctypes_path.replace("importlib", "ctypes") + "/__init__.py")
+ f = open(ctypes_path, "r", encoding = "utf-8")
+ all_lines = f.readlines()
+ f.close()
+ # comment this line out
+ # https://projects.blender.org/blender/blender/issues/84752
+ needs_update = False
+ for i in range(len(all_lines)):
+ if ((all_lines[i].startswith("#") == False)
+ and ("CFUNCTYPE(c_int)(lambda: None)" in all_lines[i])):
+ all_lines[i] = "#" + all_lines[i]
+ needs_update = True
+ break
+ # save the file
+ if (needs_update):
+ print("Patching %s..." % (ctypes_path))
+ f = open(ctypes_path, "w", encoding = "utf-8")
+ for line in all_lines:
+ f.write(line)
+ f.close()
# checking python modules
- if (new_mod_install(new_mod_check(new_modules)) == True):
+ if (new_mod_install(new_mod_check(NEEDED_MODULE_NAMES)) == True):
print("New modules installed. Exiting...")
exit(0)
- for mod_name in new_modules:
+ for mod_name in NEEDED_MODULE_NAMES:
mod = importlib.import_module(mod_name)
print("%s %s is installed!" % (mod_name, mod.__version__))
# add this function to load_post first
bpy.app.handlers.load_post.append(unload_blenxy_stuff)
# add the register functions to load_post
- for mod_name in blenxy_modules:
+ for mod_name in BLENXY_MODULES:
mod = importlib.import_module("." + mod_name, __package__)
bpy.app.handlers.load_post.append(mod.register)
@@ -117,7 +135,7 @@ def unregister():
print("\nLeaving Blenxy!\n")
# remove the stuff added to the load_post list
bpy.app.handlers.load_post.remove(unload_blenxy_stuff)
- for mod_name in blenxy_modules:
+ for mod_name in BLENXY_MODULES:
mod = importlib.import_module("." + mod_name, __package__)
for func in bpy.app.handlers.load_post:
if (mod.__name__ in func.__module__):
@@ -125,6 +143,6 @@ def unregister():
break
# execute module's unregister functions
- for mod_name in blenxy_modules:
+ for mod_name in BLENXY_MODULES:
mod = importlib.import_module("." + mod_name, __package__)
mod.unregister()