forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_plugin_deps.py
35 lines (29 loc) · 959 Bytes
/
install_plugin_deps.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
import os
import subprocess
import sys
import zipfile
from pathlib import Path
def install_plugin_dependencies():
"""
Installs dependencies for all plugins in the plugins dir.
Args:
None
Returns:
None
"""
plugins_dir = Path(os.getenv("PLUGINS_DIR", "plugins"))
for plugin in plugins_dir.glob("*.zip"):
with zipfile.ZipFile(str(plugin), "r") as zfile:
try:
basedir = zfile.namelist()[0]
basereqs = os.path.join(basedir, "requirements.txt")
extracted = zfile.extract(basereqs, path=plugins_dir)
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "-r", extracted]
)
os.remove(extracted)
os.rmdir(os.path.join(plugins_dir, basedir))
except KeyError:
continue
if __name__ == "__main__":
install_plugin_dependencies()