(config)
| 189 | |
| 190 | |
| 191 | def setConfig(config): |
| 192 | global MODELS_DIR |
| 193 | |
| 194 | try: # config.yaml |
| 195 | config_yaml_path = os.path.join(CONFIG_DIR, "..", "config.yaml") |
| 196 | config_yaml_path = os.path.abspath(config_yaml_path) |
| 197 | yaml = YAML() |
| 198 | |
| 199 | if not hasattr(config, "_yaml_comment"): |
| 200 | config_yaml_sample_path = os.path.join(CONFIG_DIR, "config.yaml.sample") |
| 201 | |
| 202 | if os.path.exists(config_yaml_sample_path): |
| 203 | with open(config_yaml_sample_path, "r", encoding="utf-8") as f: |
| 204 | commented_config = yaml.load(f) |
| 205 | |
| 206 | for k in config: |
| 207 | commented_config[k] = config[k] |
| 208 | |
| 209 | config = commented_config |
| 210 | yaml.indent(mapping=2, sequence=4, offset=2) |
| 211 | |
| 212 | if "config_on_startup" in config: |
| 213 | del config["config_on_startup"] |
| 214 | |
| 215 | try: |
| 216 | f = open(config_yaml_path + ".tmp", "w", encoding="utf-8") |
| 217 | yaml.dump(config, f) |
| 218 | finally: |
| 219 | f.close() # do this explicitly to avoid NUL bytes (possible rare bug when using 'with') |
| 220 | |
| 221 | # verify that the new file is valid, and only then overwrite the old config file |
| 222 | # helps prevent the rare NUL bytes error from corrupting the config file |
| 223 | yaml = YAML() |
| 224 | with open(config_yaml_path + ".tmp", "r", encoding="utf-8") as f: |
| 225 | yaml.load(f) |
| 226 | shutil.move(config_yaml_path + ".tmp", config_yaml_path) |
| 227 | except: |
| 228 | log.error(traceback.format_exc()) |
| 229 | |
| 230 | if config.get("models_dir"): |
| 231 | MODELS_DIR = config["models_dir"] |
| 232 | |
| 233 | |
| 234 | def save_to_config(ckpt_model_name, vae_model_name, hypernetwork_model_name, vram_usage_level): |
no test coverage detected