forked from adieyal/sd-dynamic-prompts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
61 lines (47 loc) · 1.57 KB
/
install.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
import sys
import logging
from pathlib import Path
logger = logging.getLogger(__name__)
if sys.version_info < (3, 8):
import importlib_metadata
else:
import importlib.metadata as importlib_metadata
import launch
def clean_package_name(s):
s = s.split("==")[0].strip()
s = s.split(">=")[0].strip()
s = s.split("<=")[0].strip()
s = s.split(">")[0].strip()
s = s.split("<")[0].strip()
s = s.split("~=")[0].strip()
s = s.split("!=")[0].strip()
s = s.split(" ")[0].strip()
s = s.split("[")[0].strip()
return s
def ensure_installed(package):
isinstalled = launch.is_installed(package)
if not isinstalled:
launch.run_pip(f"install {package}", desc=f"{package}")
def ensure_version(dependency, version):
package = clean_package_name(dependency)
isinstalled = launch.is_installed(package)
if isinstalled:
installed_version = importlib_metadata.version(package)
if installed_version == version:
return
launch.run_pip(f"install {dependency}=={version}", desc=f"{dependency}=={version}")
def check_versions():
req_file = Path(__file__).parent / "requirements.txt"
for row in open(req_file):
splits = row.split("==")
try:
if len(splits) == 2:
dependency = splits[0].strip()
version = splits[1].strip()
ensure_version(dependency, version)
else:
package = row.strip()
ensure_installed(package)
except Exception as e:
logger.exception(e)
check_versions()