-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dependencies.py
107 lines (91 loc) · 4.35 KB
/
Dependencies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""Install dependencies when blender fails todo so.
"""
import os
import sys
import platform
import bpy
class MidiController_Dependencies:
"""Help with installing the dependencies needed, but let the user decide.
"""
required_packages_installed = True
finished_installing_package = False
progress_printer = []
def wrap(width, text):
lines = []
arr = text.splitlines()
lengthSum = 0
strSum = ""
for var in arr:
lengthSum += len(var) + 1
if lengthSum <= width:
strSum += " " + var
else:
lines.append(strSum)
lengthSum = 0
strSum = var
lines.append(" " + arr[len(arr) - 1])
return lines
def get_plugin_install_dir():
return os.path.dirname(os.path.realpath(__file__))
def select_system_package():
script_path = MidiController_Dependencies.get_plugin_install_dir()
python_version = ""
if sys.version_info[1] == 11:
python_version = "cp311-cp311"
elif sys.version_info[1] == 10:
python_version = "cp310-cp310"
else:
raise Exception(
f"Python version: {sys.version} currently unsupported!")
if platform.system() == "Windows":
if platform.machine() in ['AMD64', 'x86_64']:
return os.path.join(script_path, os.path.join('wheels', f'python_rtmidi-1.5.8-{python_version}-win_amd64.whl'))
elif platform.system() == "Darwin":
if platform.machine() in ['AMD64', 'x86_64']:
return os.path.join(script_path, os.path.join('wheels', f'python_rtmidi-1.5.8-{python_version}-macosx_10_9_x86_64.whl'))
if platform.machine() in ['aarch64_be', 'aarch64', 'armv8b', 'armv8l']:
return os.path.join(script_path, os.path.join('wheels', f'python_rtmidi-1.5.8-{python_version}-macosx_11_0_arm64.whl'))
else: # possibly linux, just gotta try
if platform.machine() in ['AMD64', 'x86_64']:
return os.path.join(script_path, os.path.join('wheels', f'python_rtmidi-1.5.8-{python_version}-manylinux_2_28_x86_64.whl'))
if platform.machine() in ['aarch64_be', 'aarch64', 'armv8b', 'armv8l']:
return os.path.join(script_path, os.path.join('wheels', f'python_rtmidi-1.5.8-{python_version}-manylinux_2_28_aarch64.whl'))
return None
def get_python_executable():
python_path = ""
for path in bpy.utils.script_paths():
if '\\\\' in bpy.app.binary_path:
splitpath = bpy.app.binary_path.split('\\\\')
last_in_path = splitpath[-2]
if last_in_path in path:
basepath = '\\\\'.join(path.split('\\\\')[0:-1])
python_path = os.path.join(basepath, os.path.join("python", "bin"))
if '\\' in bpy.app.binary_path:
splitpath = bpy.app.binary_path.split('\\')
last_in_path = splitpath[-2]
if last_in_path in path:
basepath = '\\'.join(path.split('\\')[0:-1])
python_path = os.path.join(basepath, os.path.join("python", "bin"))
if '/' in bpy.app.binary_path:
splitpath = bpy.app.binary_path.split('/')
last_in_path = splitpath[-2]
if last_in_path in path:
basepath = '/'.join(path.split('/')[0:-1])
python_path = os.path.join(basepath, os.path.join("python", "bin"))
print(f"Python path: {python_path}")
if '/' in python_path:
if 'python' in os.listdir(python_path):
return os.path.join(python_path, 'python')
else:
if 'python.exe' in os.listdir(python_path):
return os.path.join(python_path, 'python.exe')
return None
def get_packages_dir():
script_path = MidiController_Dependencies.get_plugin_install_dir()
site_packages_dir = os.path.join(script_path, 'site-packages')
if not os.path.exists(site_packages_dir):
MidiController_Dependencies.progress_printer += [
"Creating site package dir in plugin directory:"]
MidiController_Dependencies.progress_printer += [site_packages_dir]
os.makedirs(site_packages_dir)
return site_packages_dir