From b78a51f358c0c4e1f035dc4710374fdb0f0905e4 Mon Sep 17 00:00:00 2001 From: Runew0lf Date: Fri, 8 Dec 2023 19:34:28 +0000 Subject: [PATCH] changed os.path in pathlib during model loading --- modules/path.py | 29 ++++++++++++----------------- update_log.md | 3 +++ version.py | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/modules/path.py b/modules/path.py index 9e39a7d04..b11aea2b0 100644 --- a/modules/path.py +++ b/modules/path.py @@ -1,5 +1,5 @@ import os - +from pathlib import Path import json from os.path import exists @@ -70,29 +70,24 @@ def get_abspath(path): def get_model_filenames(folder_path, isLora=False): - if not os.path.isdir(folder_path): + folder_path = Path(folder_path) + if not folder_path.is_dir(): raise ValueError("Folder path is not a valid directory.") filenames = [] - for root, dirs, files in os.walk(folder_path): - relative_path = os.path.relpath(root, folder_path) - if relative_path == ".": - relative_path = "" - for filename in files: - _, ext = os.path.splitext(filename) - if ext.lower() in [".pth", ".ckpt", ".bin", ".safetensors"]: - path = os.path.join(relative_path, filename) - if isLora: - txtcheck = path.replace(".safetensors", ".txt") - if os.path.isfile(f"{folder_path}{txtcheck}"): - path = path + " 🗒️" - - filenames.append(path) + for path in folder_path.rglob("*"): + if path.suffix.lower() in [".pth", ".ckpt", ".bin", ".safetensors"]: + if isLora: + txtcheck = path.with_suffix(".txt") + if txtcheck.exists(): + path = path.with_suffix(f"{path.suffix} 🗒️") + + filenames.append(str(path.relative_to(folder_path))) return sorted( filenames, - key=lambda x: f"0{x.casefold()}" if os.sep in x else f"1{x.casefold()}", + key=lambda x: f"0{x.casefold()}" if Path(x).suffix in x else f"1{x.casefold()}", ) diff --git a/update_log.md b/update_log.md index de3ebf78d..638ed433c 100644 --- a/update_log.md +++ b/update_log.md @@ -1,3 +1,6 @@ +### 1.25.2 +* Fixed an os.path issue by replaceing with pathlib + ### 1.25.1 * Now displays 🗒️ at the end of the loraname if it has a keyword .txt file diff --git a/version.py b/version.py index a47c3b6f0..586707982 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -version = "1.25.1" +version = "1.25.2"