-
Notifications
You must be signed in to change notification settings - Fork 33
/
install.py
42 lines (34 loc) · 1.51 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
import launch
import pathlib
import pkg_resources
import re
import sys
import traceback
req_file = pathlib.Path(__file__).resolve().parent / "requirements.txt"
req_re = re.compile('^([^=<>~]*)\s*(?:([=<>~])=\s*([^=<>~]*))?$')
with open(req_file) as file:
for package in file:
try:
package = package.strip()
match = req_re.search(package)
package_name = match.group(1)
try:
installed_version = pkg_resources.get_distribution(package_name).version
except Exception:
installed_version = None
pass # package not installed, we still want to install it
package_already_installed = installed_version is not None
install_info = f"sd-webui-comfyui requirement: {package}"
comparison, required_version = match.group(2, 3)
if package_already_installed:
install_info = f"sd-webui-comfyui requirement: changing {package_name} version from {installed_version} to {required_version}"
if (
comparison == '~' or
required_version is None or
eval(f'"{installed_version}" {comparison}= "{required_version}"')
):
continue
launch.run_pip(f"install {package}", install_info)
except Exception as e:
print(traceback.format_exception_only(e))
print(f'Failed to install sd-webui-comfyui requirement: {package}', file=sys.stderr)