refactor: install replication dependencies in libs
This commit is contained in:
parent
c616054878
commit
b5405553dc
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,4 +13,5 @@ multi_user_updater/
|
|||||||
_build
|
_build
|
||||||
|
|
||||||
# ignore generated zip generated from blender_addon_tester
|
# ignore generated zip generated from blender_addon_tester
|
||||||
*.zip
|
*.zip
|
||||||
|
libs
|
@ -43,11 +43,6 @@ from bpy.app.handlers import persistent
|
|||||||
from . import environment
|
from . import environment
|
||||||
|
|
||||||
|
|
||||||
DEPENDENCIES = {
|
|
||||||
"zmq",
|
|
||||||
"deepdiff"
|
|
||||||
}
|
|
||||||
LIBS = os.path.dirname(os.path.abspath(__file__))+"/libs/replication"
|
|
||||||
|
|
||||||
module_error_msg = "Insufficient rights to install the multi-user \
|
module_error_msg = "Insufficient rights to install the multi-user \
|
||||||
dependencies, aunch blender with administrator rights."
|
dependencies, aunch blender with administrator rights."
|
||||||
@ -59,21 +54,7 @@ def register():
|
|||||||
level=logging.INFO)
|
level=logging.INFO)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if bpy.app.version[1] >= 91:
|
environment.register()
|
||||||
python_binary_path = sys.executable
|
|
||||||
else:
|
|
||||||
python_binary_path = bpy.app.binary_path_python
|
|
||||||
|
|
||||||
environment.setup(DEPENDENCIES, python_binary_path)
|
|
||||||
|
|
||||||
for module_name in list(sys.modules.keys()):
|
|
||||||
if 'replication' in module_name:
|
|
||||||
del sys.modules[module_name]
|
|
||||||
|
|
||||||
if LIBS not in sys.path:
|
|
||||||
logging.info('Adding local modules dir to the path')
|
|
||||||
sys.path.insert(0, LIBS)
|
|
||||||
|
|
||||||
|
|
||||||
from . import presence
|
from . import presence
|
||||||
from . import operators
|
from . import operators
|
||||||
@ -121,3 +102,5 @@ def unregister():
|
|||||||
del bpy.types.ID.uuid
|
del bpy.types.ID.uuid
|
||||||
del bpy.types.WindowManager.online_users
|
del bpy.types.WindowManager.online_users
|
||||||
del bpy.types.WindowManager.user_index
|
del bpy.types.WindowManager.user_index
|
||||||
|
|
||||||
|
environment.unregister()
|
||||||
|
@ -24,20 +24,25 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
|
import bpy
|
||||||
|
|
||||||
VERSION_EXPR = re.compile('\d+.\d+.\d+')
|
VERSION_EXPR = re.compile('\d+.\d+.\d+')
|
||||||
|
|
||||||
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
|
||||||
DEFAULT_CACHE_DIR = os.path.join(
|
DEFAULT_CACHE_DIR = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)), "cache")
|
os.path.dirname(os.path.abspath(__file__)), "cache")
|
||||||
|
REPLICATION_DEPENDENCIES = {
|
||||||
|
"zmq",
|
||||||
|
"deepdiff"
|
||||||
|
}
|
||||||
|
LIBS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
||||||
|
REPLICATION = os.path.join(LIBS,"replication")
|
||||||
|
|
||||||
PYTHON_PATH = None
|
PYTHON_PATH = None
|
||||||
SUBPROCESS_DIR = None
|
SUBPROCESS_DIR = None
|
||||||
|
|
||||||
|
|
||||||
rtypes = []
|
rtypes = []
|
||||||
|
|
||||||
|
|
||||||
def module_can_be_imported(name):
|
def module_can_be_imported(name: str) -> bool:
|
||||||
try:
|
try:
|
||||||
__import__(name)
|
__import__(name)
|
||||||
return True
|
return True
|
||||||
@ -50,7 +55,7 @@ def install_pip():
|
|||||||
subprocess.run([str(PYTHON_PATH), "-m", "ensurepip"])
|
subprocess.run([str(PYTHON_PATH), "-m", "ensurepip"])
|
||||||
|
|
||||||
|
|
||||||
def install_package(name):
|
def install_package(name: str, install_dir: str):
|
||||||
logging.info(f"installing {name} version...")
|
logging.info(f"installing {name} version...")
|
||||||
env = os.environ
|
env = os.environ
|
||||||
if "PIP_REQUIRE_VIRTUALENV" in env:
|
if "PIP_REQUIRE_VIRTUALENV" in env:
|
||||||
@ -60,12 +65,13 @@ def install_package(name):
|
|||||||
# env var for the subprocess.
|
# env var for the subprocess.
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
del env["PIP_REQUIRE_VIRTUALENV"]
|
del env["PIP_REQUIRE_VIRTUALENV"]
|
||||||
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", f"{name}"], env=env)
|
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", f"{name}", "-t", install_dir], env=env)
|
||||||
|
|
||||||
if name in sys.modules:
|
if name in sys.modules:
|
||||||
del sys.modules[name]
|
del sys.modules[name]
|
||||||
|
|
||||||
def check_package_version(name, required_version):
|
|
||||||
|
def check_package_version(name: str, required_version: str):
|
||||||
logging.info(f"Checking {name} version...")
|
logging.info(f"Checking {name} version...")
|
||||||
out = subprocess.run([str(PYTHON_PATH), "-m", "pip", "show", name], capture_output=True)
|
out = subprocess.run([str(PYTHON_PATH), "-m", "pip", "show", name], capture_output=True)
|
||||||
|
|
||||||
@ -77,6 +83,7 @@ def check_package_version(name, required_version):
|
|||||||
logging.info(f"{name} need an update")
|
logging.info(f"{name} need an update")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_ip():
|
def get_ip():
|
||||||
"""
|
"""
|
||||||
Retrieve the main network interface IP.
|
Retrieve the main network interface IP.
|
||||||
@ -94,7 +101,25 @@ def check_dir(dir):
|
|||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
|
||||||
|
|
||||||
def setup(dependencies, python_path):
|
def setup_paths(paths: list):
|
||||||
|
""" Add missing path to sys.path
|
||||||
|
"""
|
||||||
|
for path in paths:
|
||||||
|
if path not in sys.path:
|
||||||
|
logging.debug(f"Adding {path} dir to the path.")
|
||||||
|
sys.path.insert(0, path)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_paths(paths: list):
|
||||||
|
""" Remove list of path from sys.path
|
||||||
|
"""
|
||||||
|
for path in paths:
|
||||||
|
if path in sys.path:
|
||||||
|
logging.debug(f"Removing {path} dir from the path.")
|
||||||
|
sys.path.remove(path)
|
||||||
|
|
||||||
|
|
||||||
|
def install_modules(dependencies: list, python_path: str, install_dir: str):
|
||||||
global PYTHON_PATH, SUBPROCESS_DIR
|
global PYTHON_PATH, SUBPROCESS_DIR
|
||||||
|
|
||||||
PYTHON_PATH = Path(python_path)
|
PYTHON_PATH = Path(python_path)
|
||||||
@ -105,5 +130,21 @@ def setup(dependencies, python_path):
|
|||||||
|
|
||||||
for package_name in dependencies:
|
for package_name in dependencies:
|
||||||
if not module_can_be_imported(package_name):
|
if not module_can_be_imported(package_name):
|
||||||
install_package(package_name)
|
install_package(package_name, install_dir=install_dir)
|
||||||
module_can_be_imported(package_name)
|
module_can_be_imported(package_name)
|
||||||
|
|
||||||
|
def register():
|
||||||
|
if bpy.app.version[1] >= 91:
|
||||||
|
python_binary_path = sys.executable
|
||||||
|
else:
|
||||||
|
python_binary_path = bpy.app.binary_path_python
|
||||||
|
|
||||||
|
for module_name in list(sys.modules.keys()):
|
||||||
|
if 'replication' in module_name:
|
||||||
|
del sys.modules[module_name]
|
||||||
|
|
||||||
|
setup_paths([LIBS, REPLICATION])
|
||||||
|
install_modules(REPLICATION_DEPENDENCIES, python_binary_path, install_dir=LIBS)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
remove_paths([REPLICATION, LIBS])
|
@ -1 +1 @@
|
|||||||
Subproject commit d49651edb46d5b184af912f9949a5ec0ac6cf550
|
Subproject commit 9cd1f2e43545708ffe879c7b53d6e32e90c258f9
|
Loading…
Reference in New Issue
Block a user