-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootCheck.py
More file actions
121 lines (106 loc) · 4.44 KB
/
Copy pathbootCheck.py
File metadata and controls
121 lines (106 loc) · 4.44 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
from importlib.metadata import distributions
class EnvVariable:
def __init__(self, name: str, booleanValue: bool, required: bool=True, children: 'list[EnvVariable]'=None):
self.name = name
self.booleanValue = booleanValue
self.required = required
self.children = children if children is not None else []
def check(self):
if self.name not in os.environ and self.required:
raise Exception("BOOTCHECK ERROR: Required environment variable '{}' was not found.".format(self.name))
if self.booleanValue and os.environ.get(self.name, "False") == "True":
if len(self.children) > 0:
for child in self.children:
child.check()
return self.name if (self.name not in os.environ and not self.required) else True
@staticmethod
def defaults():
return [
EnvVariable("DI_FAILOVER_STRATEGY", False, False),
EnvVariable("DEVICE", False, False),
EnvVariable("LOGGING_ENABLED", True, False),
EnvVariable("DEBUG_MODE", True, False),
EnvVariable("LLM_INFERENCE", True, True),
EnvVariable("FM_DEBUG_MODE", True, False),
EnvVariable("DECORATOR_DEBUG_MODE", True, False),
EnvVariable("DB_DEBUG_MODE", True, False),
EnvVariable("ARCHSMITH_ENABLED", True, True),
EnvVariable("API_KEY", False, True),
EnvVariable("SECRET_KEY", False, True),
EnvVariable("FRONTEND_URL", False, True),
EnvVariable("RAW_FILE_SERVICE", True, True),
EnvVariable("MAX_FILE_UPLOADS", False, False),
EnvVariable("MAX_ARTEFACT_SIZE", False, False),
EnvVariable("MAX_PFP_SIZE", False, False),
EnvVariable("MAX_CONTENT_SIZE", False, False),
EnvVariable("LATEST_CAPTIONING_MODEL", True, False),
EnvVariable("EMAILING_ENABLED", True, True, [
EnvVariable("SENDER_EMAIL", False, True),
EnvVariable("SENDER_EMAIL_APP_PASSWORD", False, True)
]),
EnvVariable("FireConnEnabled", True, True, [
EnvVariable("FireRTDBEnabled", True, False, [
EnvVariable("RTDB_URL", False, True)
]),
EnvVariable("FireStorageEnabled", True, False, [
EnvVariable("STORAGE_URL", False, True)
])
]),
EnvVariable("LLMINTERFACE_ENABLED", True, True, [
EnvVariable("QWEN_API_KEY", False, True),
EnvVariable("OPENAI_API_KEY", False, True)
])
]
class BootCheck:
dependencyMappings = {
"python-dotenv": "python-dotenv",
"requests": "requests",
"torch": "torch",
"torchvision": "torchvision",
"flask": "Flask",
"flask-limiter": "Flask-Limiter",
"flask-cors": "flask-cors",
"openai": "openai",
"passlib": "passlib",
"apscheduler": "APScheduler",
"firebase-admin": "firebase-admin",
"pillow": "pillow",
"numpy": "numpy",
"facenet-pytorch": "facenet-pytorch",
"uuid": "uuid",
"nltk": "nltk",
"Pympler": "Pympler"
}
@staticmethod
def getInstallations() -> list:
pkgs = []
for x in distributions():
pkgs.append(x.name)
return pkgs
@staticmethod
def checkDependencies():
requiredDependencies = list(BootCheck.dependencyMappings.values())
deps = BootCheck.getInstallations()
for req in requiredDependencies:
if req not in deps:
if req == "firebase-admin":
if "firebase_admin" in deps:
continue
raise Exception("BOOTCHECK ERROR: Required package '{}' not found.".format(req))
return True
@staticmethod
def checkEnvVariables():
from dotenv import load_dotenv
load_dotenv()
notFound = []
for var in EnvVariable.defaults():
res = var.check()
if res != True:
notFound.append(res)
if len(notFound) > 0:
print("BOOTCHECK WARNING: Optional environment variables {} not found.".format(', '.join(notFound)))
return True
@staticmethod
def check():
return BootCheck.checkDependencies() and BootCheck.checkEnvVariables()