lllyasviel commited on
Commit
5fb1426
·
1 Parent(s): 27db148
Files changed (2) hide show
  1. launch.py +7 -2
  2. modules/launch_util.py +39 -0
launch.py CHANGED
@@ -2,10 +2,11 @@ import os
2
  import sys
3
  import platform
4
 
5
- from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, python, run_pip, repo_dir, git_clone
 
6
 
7
 
8
- REINSTALL_ALL = True
9
 
10
 
11
  def prepare_environment():
@@ -42,6 +43,10 @@ def prepare_environment():
42
  elif platform.system() == "Linux":
43
  run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
44
 
 
 
 
 
45
 
46
 
47
  prepare_environment()
 
2
  import sys
3
  import platform
4
 
5
+ from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, python, \
6
+ run_pip, repo_dir, git_clone, requirements_met
7
 
8
 
9
+ REINSTALL_ALL = False
10
 
11
 
12
  def prepare_environment():
 
43
  elif platform.system() == "Linux":
44
  run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
45
 
46
+ if REINSTALL_ALL or not requirements_met(requirements_file):
47
+ run_pip(f"install -r \"{requirements_file}\"", "requirements")
48
+
49
+ return
50
 
51
 
52
  prepare_environment()
modules/launch_util.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import importlib
3
  import subprocess
4
  import sys
 
5
 
6
  from functools import lru_cache
7
 
@@ -95,3 +96,41 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_
95
  def run_pip(command, desc=None, live=default_command_live):
96
  index_url_line = f' --index-url {index_url}' if index_url != '' else ''
97
  return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import importlib
3
  import subprocess
4
  import sys
5
+ import re
6
 
7
  from functools import lru_cache
8
 
 
96
  def run_pip(command, desc=None, live=default_command_live):
97
  index_url_line = f' --index-url {index_url}' if index_url != '' else ''
98
  return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live)
99
+
100
+
101
+ re_requirement = re.compile(r"\s*([-_a-zA-Z0-9]+)\s*(?:==\s*([-+_.a-zA-Z0-9]+))?\s*")
102
+
103
+
104
+ def requirements_met(requirements_file):
105
+ """
106
+ Does a simple parse of a requirements.txt file to determine if all rerqirements in it
107
+ are already installed. Returns True if so, False if not installed or parsing fails.
108
+ """
109
+
110
+ import importlib.metadata
111
+ import packaging.version
112
+
113
+ with open(requirements_file, "r", encoding="utf8") as file:
114
+ for line in file:
115
+ if line.strip() == "":
116
+ continue
117
+
118
+ m = re.match(re_requirement, line)
119
+ if m is None:
120
+ return False
121
+
122
+ package = m.group(1).strip()
123
+ version_required = (m.group(2) or "").strip()
124
+
125
+ if version_required == "":
126
+ continue
127
+
128
+ try:
129
+ version_installed = importlib.metadata.version(package)
130
+ except Exception:
131
+ return False
132
+
133
+ if packaging.version.parse(version_required) != packaging.version.parse(version_installed):
134
+ return False
135
+
136
+ return True