-
Notifications
You must be signed in to change notification settings - Fork 14k
Refactor model directory structure and add new configuration files #14768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||
| import logging | ||||||
| from typing import Literal, List | ||||||
| from collections.abc import Collection | ||||||
|
|
||||||
| import json | ||||||
| from comfy.cli_args import args | ||||||
|
|
||||||
| supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.pt2', '.bin', '.pth', '.safetensors', '.pkl', '.sft'} | ||||||
|
|
@@ -13,11 +13,39 @@ | |||||
|
|
||||||
| # --base-directory - Resets all default paths configured in folder_paths with a new base path | ||||||
| if args.base_directory: | ||||||
| base_path = os.path.abspath(args.base_directory) | ||||||
| raw_path = os.path.abspath(args.base_directory) | ||||||
| else: | ||||||
| base_path = os.path.dirname(os.path.realpath(__file__)) | ||||||
| raw_path = os.path.dirname(os.path.realpath(__file__)) | ||||||
|
|
||||||
|
|
||||||
| def valid_path(saved_path,description = "Instance Folder"): | ||||||
| if os.path.exists(saved_path): | ||||||
| return saved_path | ||||||
|
|
||||||
| redirect_path = os.path.join(os.path.dirname(__file__),"path.redirects.json") | ||||||
| if os.path.exists(redirect_path): | ||||||
| with open("redirect_path","r") as f: | ||||||
| redirects = json.load(f) | ||||||
| if description in redirects and os.path.exists(redirects[description]): | ||||||
| return redirects[description] | ||||||
| print(f"\n[!] ALERT: {description} not found at: {saved_path}") | ||||||
| new_path= input(f"Please paste the updated absolute path for '{description}': ").strip() | ||||||
| try: | ||||||
| redirects = {} | ||||||
| if os.path.exists(redirects): | ||||||
| with open(redirects, "r") as f: redirects = json.load(f) | ||||||
| redirects[description] = new_path | ||||||
| with open(redirects, "w") as f: json.dump(redirects, f, indent=4) | ||||||
| except Exception: | ||||||
| pass | ||||||
|
|
||||||
| return new_path | ||||||
|
|
||||||
| models_dir = os.path.join(base_path, "models") | ||||||
|
|
||||||
|
|
||||||
| base_path = valid_path(raw_path,description = "ComfyUI Core Directory") | ||||||
|
|
||||||
| models_dir =valid_path( os.path.join(base_path,"model"),description = "Model Directory") | ||||||
|
Comment on lines
+21
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift
🧰 Tools🪛 ast-grep (0.44.0)[warning] 35-35: File path is request-/variable-derived; validate and normalize to prevent path traversal. (open-filename-from-request) [warning] 37-37: File path is request-/variable-derived; validate and normalize to prevent path traversal. (open-filename-from-request) 🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
The directory has always been 🐛 Proposed fix-models_dir =valid_path( os.path.join(base_path,"model"),description = "Model Directory")
+models_dir = valid_path(os.path.join(base_path, "models"), description="Model Directory")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| folder_names_and_paths["checkpoints"] = ([os.path.join(models_dir, "checkpoints")], supported_pt_extensions) | ||||||
| folder_names_and_paths["configs"] = ([os.path.join(models_dir, "configs")], [".yaml"]) | ||||||
|
|
||||||
|
|
@@ -60,7 +88,7 @@ | |||||
|
|
||||||
| folder_names_and_paths["detection"] = ([os.path.join(models_dir, "detection")], supported_pt_extensions) | ||||||
|
|
||||||
| output_directory = os.path.join(base_path, "output") | ||||||
| output_directory =valid_path( os.path.join(base_path, "output"),"Output Directory") | ||||||
| temp_directory = os.path.join(base_path, "temp") | ||||||
| input_directory = os.path.join(base_path, "input") | ||||||
| user_directory = os.path.join(base_path, "user") | ||||||
|
|
@@ -102,6 +130,8 @@ def __exit__(self, exc_type, exc_value, traceback): | |||||
| "fbx" : "model", | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| def map_legacy(folder_name: str) -> str: | ||||||
| legacy = {"unet": "diffusion_models", | ||||||
| "clip": "text_encoders"} | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
The redirect-file plumbing is riddled with wrong variables — it can crash and never persists.
Three concrete bugs in the redirect logic:
"redirect_path"instead of theredirect_pathvariable, so whenever the real JSON file exists this raisesFileNotFoundError(and it's not inside thetry).redirectsdict ({}) toos.path.exists/openwhere the path is expected.os.path.exists({})raisesTypeError, which the bareexcept Exception: passsilently swallows, so the mapping is never written.Net effect: the redirect file is never read correctly and never saved.
🐛 Proposed fix
redirect_path = os.path.join(os.path.dirname(__file__),"path.redirects.json") if os.path.exists(redirect_path): - with open("redirect_path","r") as f: + with open(redirect_path,"r") as f: redirects = json.load(f) if description in redirects and os.path.exists(redirects[description]): return redirects[description] print(f"\n[!] ALERT: {description} not found at: {saved_path}") new_path= input(f"Please paste the updated absolute path for '{description}': ").strip() try: redirects = {} - if os.path.exists(redirects): - with open(redirects, "r") as f: redirects = json.load(f) + if os.path.exists(redirect_path): + with open(redirect_path, "r") as f: redirects = json.load(f) redirects[description] = new_path - with open(redirects, "w") as f: json.dump(redirects, f, indent=4) + with open(redirect_path, "w") as f: json.dump(redirects, f, indent=4) except Exception: pass📝 Committable suggestion
🧰 Tools
🪛 ast-grep (0.44.0)
[warning] 35-35: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(redirects, "r")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(open-filename-from-request)
[warning] 37-37: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(redirects, "w")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(open-filename-from-request)
🤖 Prompt for AI Agents