-
Notifications
You must be signed in to change notification settings - Fork 8.5k
fix: Missing data dirs should be handled gracefully #8115
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,7 +30,22 @@ def apply_custom_paths(): | |||||||||||||||||||||
for config_path in itertools.chain(*args.extra_model_paths_config): | ||||||||||||||||||||||
utils.extra_config.load_extra_path_config(config_path) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# --output-directory, --input-directory, --user-directory | ||||||||||||||||||||||
# --temp-directory, --user-directory, --input-directory, --output-directory | ||||||||||||||||||||||
if args.temp_directory: | ||||||||||||||||||||||
temp_dir = os.path.join(os.path.abspath(args.temp_directory), "temp") | ||||||||||||||||||||||
logging.info(f"Setting temp directory to: {temp_dir}") | ||||||||||||||||||||||
folder_paths.set_temp_directory(temp_dir) | ||||||||||||||||||||||
Comment on lines
+34
to
+37
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. Breaking change, but would be consistent with expectations of related args:
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
if args.user_directory: | ||||||||||||||||||||||
user_dir = os.path.abspath(args.user_directory) | ||||||||||||||||||||||
logging.info(f"Setting user directory to: {user_dir}") | ||||||||||||||||||||||
folder_paths.set_user_directory(user_dir) | ||||||||||||||||||||||
|
||||||||||||||||||||||
if args.input_directory: | ||||||||||||||||||||||
input_dir = os.path.abspath(args.input_directory) | ||||||||||||||||||||||
logging.info(f"Setting input directory to: {input_dir}") | ||||||||||||||||||||||
folder_paths.set_input_directory(input_dir) | ||||||||||||||||||||||
|
||||||||||||||||||||||
if args.output_directory: | ||||||||||||||||||||||
output_dir = os.path.abspath(args.output_directory) | ||||||||||||||||||||||
logging.info(f"Setting output directory to: {output_dir}") | ||||||||||||||||||||||
|
@@ -44,15 +59,20 @@ def apply_custom_paths(): | |||||||||||||||||||||
os.path.join(folder_paths.get_output_directory(), "diffusion_models")) | ||||||||||||||||||||||
folder_paths.add_model_folder_path("loras", os.path.join(folder_paths.get_output_directory(), "loras")) | ||||||||||||||||||||||
|
||||||||||||||||||||||
if args.input_directory: | ||||||||||||||||||||||
input_dir = os.path.abspath(args.input_directory) | ||||||||||||||||||||||
logging.info(f"Setting input directory to: {input_dir}") | ||||||||||||||||||||||
folder_paths.set_input_directory(input_dir) | ||||||||||||||||||||||
|
||||||||||||||||||||||
if args.user_directory: | ||||||||||||||||||||||
user_dir = os.path.abspath(args.user_directory) | ||||||||||||||||||||||
logging.info(f"Setting user directory to: {user_dir}") | ||||||||||||||||||||||
folder_paths.set_user_directory(user_dir) | ||||||||||||||||||||||
# These are created at startup if missing. Other data directories are created on-demand when needed. | ||||||||||||||||||||||
def create_data_folders(): | ||||||||||||||||||||||
data_dirs = [ | ||||||||||||||||||||||
folder_paths.get_input_directory(), | ||||||||||||||||||||||
folder_paths.get_temp_directory() | ||||||||||||||||||||||
] | ||||||||||||||||||||||
Comment on lines
+65
to
+68
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. Optionally create the
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
for dir_path in data_dirs: | ||||||||||||||||||||||
if not os.path.exists(dir_path): | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
os.makedirs(dir_path) | ||||||||||||||||||||||
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. maybe adding 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. I don't see why?
Hence this approach is better, only attempt to create a directory when it doesn't exist but is expected to. |
||||||||||||||||||||||
except: | ||||||||||||||||||||||
logging.error(f"Failed to create directory: {dir_path}") | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def execute_prestartup_script(): | ||||||||||||||||||||||
|
@@ -72,7 +92,11 @@ def execute_script(script_path): | |||||||||||||||||||||
|
||||||||||||||||||||||
node_paths = folder_paths.get_folder_paths("custom_nodes") | ||||||||||||||||||||||
for custom_node_path in node_paths: | ||||||||||||||||||||||
possible_modules = os.listdir(custom_node_path) | ||||||||||||||||||||||
if not os.path.exists(custom_node_path): | ||||||||||||||||||||||
logging.warning(f"Directory {custom_node_path} for custom nodes does not exist, skipping") | ||||||||||||||||||||||
continue | ||||||||||||||||||||||
Comment on lines
+95
to
+97
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. This is the primary fix I'm interested in, if the directory does not need to exist but is checked by default, it seems better to skip instead of crash? I am not sure if that aligns with your expectations, so if it makes sense to log a warning I've added one here, otherwise the warning could be removed? |
||||||||||||||||||||||
|
||||||||||||||||||||||
possible_modules = os.listdir(os.path.realpath(custom_node_path)) | ||||||||||||||||||||||
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.
A user reported the lack of resolving symlinks as problematic for similar I added it here for consistency. |
||||||||||||||||||||||
node_prestartup_times = [] | ||||||||||||||||||||||
|
||||||||||||||||||||||
for possible_module in possible_modules: | ||||||||||||||||||||||
|
@@ -95,7 +119,9 @@ def execute_script(script_path): | |||||||||||||||||||||
logging.info("{:6.1f} seconds{}: {}".format(n[0], import_message, n[1])) | ||||||||||||||||||||||
logging.info("") | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
apply_custom_paths() | ||||||||||||||||||||||
create_data_folders() | ||||||||||||||||||||||
execute_prestartup_script() | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -250,10 +276,6 @@ def start_comfyui(asyncio_loop=None): | |||||||||||||||||||||
Starts the ComfyUI server using the provided asyncio event loop or creates a new one. | ||||||||||||||||||||||
Returns the event loop, server instance, and a function to start the server asynchronously. | ||||||||||||||||||||||
""" | ||||||||||||||||||||||
if args.temp_directory: | ||||||||||||||||||||||
temp_dir = os.path.join(os.path.abspath(args.temp_directory), "temp") | ||||||||||||||||||||||
logging.info(f"Setting temp directory to: {temp_dir}") | ||||||||||||||||||||||
folder_paths.set_temp_directory(temp_dir) | ||||||||||||||||||||||
cleanup_temp() | ||||||||||||||||||||||
|
||||||||||||||||||||||
if args.windows_standalone_build: | ||||||||||||||||||||||
|
@@ -283,7 +305,6 @@ def start_comfyui(asyncio_loop=None): | |||||||||||||||||||||
if args.quick_test_for_ci: | ||||||||||||||||||||||
exit(0) | ||||||||||||||||||||||
|
||||||||||||||||||||||
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True) | ||||||||||||||||||||||
call_on_start = None | ||||||||||||||||||||||
if args.auto_launch: | ||||||||||||||||||||||
def startup_server(scheme, address, port): | ||||||||||||||||||||||
|
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.
For consistency, could set this to
str
and it'll be created if it's missing, otherwise the other related options could also usetype=is_valid_directory
to enforce a valid dir is provided (but that may break some expectations?)