Skip to content

Commit 3ba7843

Browse files
authored
Merge pull request #14 from monsurcodes/feature/ScriptToInstallModulesForTests
Add script to install required Python modules for tests
2 parents d8f5116 + a1d1780 commit 3ba7843

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import subprocess
2+
import sys
3+
import importlib
4+
import os
5+
6+
def install_module(module_name):
7+
"""Install a Python module using pip."""
8+
9+
pip = ""
10+
if os.name == 'nt':
11+
pip = "pip"
12+
else:
13+
pip = "pip3"
14+
15+
try:
16+
subprocess.check_call([sys.executable, "-m", pip, "install", module_name])
17+
return True
18+
except subprocess.CalledProcessError as e:
19+
print(f"[ERROR] Failed to install module {module_name}: {e}")
20+
21+
return False
22+
23+
def check_module_installed(module_name):
24+
"""Check if a Python module is installed."""
25+
try:
26+
importlib.import_module(module_name)
27+
return True
28+
except ImportError:
29+
return False
30+
31+
if __name__ == "__main__":
32+
required_modules = [
33+
"starlette",
34+
"fastapi",
35+
"aiohttp",
36+
"flask",
37+
"django",
38+
]
39+
40+
for module in required_modules:
41+
if not check_module_installed(module):
42+
print(f"[INFO] Module {module} is not installed. Attempting to install...")
43+
44+
if install_module(module):
45+
print(f"[INFO] Rechecking installation of module: {module}")
46+
else:
47+
print(f"[ERROR] Installation attempt for module {module} failed.")
48+
continue
49+
50+
if not check_module_installed(module):
51+
print(f"[ERROR] Module {module} could not be installed. Please install it manually.")
52+
53+
print(f"[INFO] Module {module} is installed.")
54+
55+
print("[INFO] All required modules are installed.")

0 commit comments

Comments
 (0)