Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00e04062c6 |
@@ -2,6 +2,15 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
### The Model Manager finds a model in a subfolder of an extra model path
|
||||
|
||||
A model whose folder in the list has a subfolder, such as `checkpoints/SD1.5`,
|
||||
was shown as not installed when its file was in that subfolder of a folder
|
||||
that `extra_model_paths.yaml` adds (#1844). The Model Manager now also asks
|
||||
ComfyUI where the file is. ComfyUI looks in every folder it has for the first
|
||||
part of the path, the extra ones included, so the model is shown as installed.
|
||||
A model that was shown as installed before still is.
|
||||
|
||||
### The PyTorch restore after a nodepack installs the builds that were installed before
|
||||
|
||||
When a nodepack changed torch or torchvision and the torch from before had
|
||||
|
||||
@@ -1145,8 +1145,10 @@ def check_model_installed(json_obj):
|
||||
filename = item['filename']
|
||||
|
||||
fullpath = os.path.join(folder_paths.models_dir, item['save_path'], filename)
|
||||
subpath = os.path.join(item['save_path'].partition('/')[2], filename)
|
||||
found = os.path.exists(fullpath) or folder_paths.get_full_path(model_dir_name, subpath)
|
||||
|
||||
item['installed'] = 'True' if os.path.exists(fullpath) else 'False'
|
||||
item['installed'] = 'True' if found else 'False'
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(8) as executor:
|
||||
for item in json_obj['models']:
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import ast
|
||||
import concurrent.futures
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from manager_test_utils import GLOB_DIR
|
||||
|
||||
KEYS = ("checkpoints", "controlnet")
|
||||
|
||||
|
||||
def installed(tmp_path, save_path, file):
|
||||
folders = {key: [str(tmp_path / "models" / key), str(tmp_path / "extra" / key)] for key in KEYS}
|
||||
path = tmp_path / file
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_bytes(b"")
|
||||
|
||||
def get_full_path(key, name):
|
||||
return next((os.path.join(folder, name) for folder in folders.get(key, [])
|
||||
if os.path.isfile(os.path.join(folder, name))), None)
|
||||
|
||||
def get_filename_list(key):
|
||||
return [os.path.relpath(os.path.join(root, name), folder)
|
||||
for folder in folders.get(key, []) for root, _, names in os.walk(folder) for name in names]
|
||||
|
||||
folder_paths = SimpleNamespace(models_dir=str(tmp_path / "models"),
|
||||
folder_names_and_paths={key: (paths, set()) for key, paths in folders.items()},
|
||||
get_folder_paths=lambda key: folders[key],
|
||||
get_filename_list=get_filename_list, get_full_path=get_full_path)
|
||||
source = (GLOB_DIR / "manager_server.py").read_text(encoding="utf-8")
|
||||
nodes = [node for node in ast.parse(source).body
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "check_model_installed"]
|
||||
assert len(nodes) == 1
|
||||
namespace = {"os": os, "concurrent": concurrent, "folder_paths": folder_paths, "model_dir_name_map": {}}
|
||||
exec(compile(ast.Module(nodes, []), "<check_model_installed>", "exec"), namespace)
|
||||
|
||||
row = {"name": "m", "type": "checkpoint", "base": "SD1.5", "save_path": save_path,
|
||||
"filename": "model.safetensors", "url": "https://example.invalid/model.safetensors"}
|
||||
namespace["check_model_installed"]({"models": [row]})
|
||||
return row.get("installed")
|
||||
|
||||
|
||||
def test_model_in_a_subfolder_of_an_extra_model_path_is_installed(tmp_path):
|
||||
assert installed(tmp_path, "checkpoints/SD1.5", "extra/checkpoints/SD1.5/model.safetensors") == "True"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("save_path, file, expected", [
|
||||
("checkpoints/SD1.5", "models/checkpoints/SD1.5/model.safetensors", "True"),
|
||||
("checkpoints/SD1.5", "extra/checkpoints/model.safetensors", "True"),
|
||||
("RGT/RGT", "models/RGT/RGT/model.safetensors", "True"),
|
||||
("checkpoints/SD1.5", "extra/checkpoints/SDXL/model.safetensors", "False"),
|
||||
("checkpoints/SD1.5", "extra/controlnet/SD1.5/model.safetensors", "False"),
|
||||
("RGT/RGT", "extra/RGT/RGT/model.safetensors", "False"),
|
||||
], ids=["install folder", "top of an extra folder", "folder of no key", "other subfolder", "folder of another key",
|
||||
"extra folder of no key"])
|
||||
def test_other_layouts_keep_their_state(tmp_path, save_path, file, expected):
|
||||
assert installed(tmp_path, save_path, file) == expected
|
||||
Reference in New Issue
Block a user