This commit is contained in:
Haoming 2025-08-06 13:52:18 +08:00
parent 54cad539a0
commit 80cadfe734
5 changed files with 12 additions and 28 deletions

View File

@ -3,8 +3,7 @@ import json
import os
from pathlib import Path
from modules.paths_internal import data_path, extensions_builtin_dir, extensions_dir, models_path, normalized_filepath, script_path, sd_model_file # noqa: F401
from backend.args import parser
from modules.paths_internal import data_path, extensions_builtin_dir, extensions_dir, parser, models_path, normalized_filepath, script_path # noqa: F401
parser.add_argument("-f", action="store_true", help=argparse.SUPPRESS)
@ -18,9 +17,6 @@ parser.add_argument("--skip-prepare-environment", action="store_true", help="lau
parser.add_argument("--skip-install", action="store_true", help="launch.py argument: skip installation of packages")
parser.add_argument("--dump-sysinfo", action="store_true", help="launch.py argument: dump limited sysinfo file (without information about extensions, options) to disk and quit")
parser.add_argument("--loglevel", type=str, help="log level; one of: CRITICAL, ERROR, WARNING, INFO, DEBUG", default=None)
parser.add_argument("--data-dir", type=normalized_filepath, default=os.path.dirname(os.path.dirname(os.path.realpath(__file__))), help="base path where all user data is stored")
parser.add_argument("--models-dir", type=normalized_filepath, default=None, help="base path where models are stored; overrides --data-dir")
parser.add_argument("--ckpt", type=normalized_filepath, default=sd_model_file, help="path to checkpoint of stable diffusion model; if specified, this checkpoint will be added to the list of checkpoints and loaded")
parser.add_argument("--ckpt-dir", type=normalized_filepath, default=None, help="Path to directory with stable diffusion checkpoints")
parser.add_argument("--vae-dir", type=normalized_filepath, default=None, help="Path to directory with VAE files")
parser.add_argument("--text-encoder-dir", type=normalized_filepath, default=None, help="Path to directory with text encoder models")

View File

@ -1,6 +1,7 @@
"""this module defines internal paths used by program and is safe to import before dependencies are installed in launch.py"""
"""
this module defines internal paths used by program and is safe to import before dependencies are installed in launch.py
"""
import argparse
import os
import shlex
import sys
@ -15,21 +16,18 @@ cwd = os.getcwd()
modules_path = os.path.dirname(os.path.realpath(__file__))
script_path = os.path.dirname(modules_path)
sd_model_file = os.path.join(script_path, "model.ckpt")
default_sd_model_file = sd_model_file
from backend.args import parser
# Parse the --data-dir flag first so we can use it as a base for our other argument default values
parser_pre = argparse.ArgumentParser(add_help=False)
parser_pre.add_argument("--data-dir", type=str, default=os.path.dirname(modules_path), help="base path where all user data is stored")
parser_pre.add_argument("--models-dir", type=str, default=None, help="base path where models are stored; overrides --data-dir")
cmd_opts_pre = parser_pre.parse_known_args()[0]
parser.add_argument("--data-dir", type=str, default=os.path.dirname(modules_path), help="base path where all user data is stored")
parser.add_argument("--model-ref", type=str, default=None, help="base path for all models")
cmd_opts_pre, _ = parser.parse_known_args()
data_path = cmd_opts_pre.data_dir
models_path = cmd_opts_pre.models_dir if cmd_opts_pre.models_dir else os.path.join(data_path, "models")
models_path = cmd_opts_pre.model_ref or os.path.join(data_path, "models")
extensions_dir = os.path.join(data_path, "extensions")
extensions_builtin_dir = os.path.join(script_path, "extensions-builtin")
config_states_dir = os.path.join(script_path, "config_states")
default_output_dir = os.path.join(data_path, "outputs")
default_output_dir = os.path.join(data_path, "output")
roboto_ttf_file = os.path.join(modules_path, "Roboto-Regular.ttf")

View File

@ -157,18 +157,8 @@ def list_models():
checkpoints_list.clear()
checkpoint_aliases.clear()
cmd_ckpt = shared.cmd_opts.ckpt
model_list = modelloader.load_models(model_path=model_path, model_url=None, command_path=shared.cmd_opts.ckpt_dir, ext_filter=[".ckpt", ".safetensors", ".gguf"], download_name=None, ext_blacklist=[".vae.ckpt", ".vae.safetensors"])
if os.path.exists(cmd_ckpt):
checkpoint_info = CheckpointInfo(cmd_ckpt)
checkpoint_info.register()
shared.opts.data['sd_model_checkpoint'] = checkpoint_info.title
elif cmd_ckpt is not None and cmd_ckpt != shared.default_sd_model_file:
print(f"Checkpoint in --ckpt argument not found (Possible it was moved to {model_path}: {cmd_ckpt}", file=sys.stderr)
for filename in model_list:
checkpoint_info = CheckpointInfo(filename)
checkpoint_info.register()

View File

@ -6,7 +6,7 @@ import gradio as gr
from backend import memory_management
from modules import options, shared_cmd_options, shared_gradio_themes, shared_items, util
from modules.paths_internal import data_path, default_sd_model_file, extensions_builtin_dir, extensions_dir, models_path, script_path, sd_model_file # noqa: F401
from modules.paths_internal import data_path, extensions_builtin_dir, extensions_dir, models_path, script_path # noqa: F401
if TYPE_CHECKING:
from modules import memmon, shared_state, shared_total_tqdm, styles

View File

@ -2,7 +2,7 @@ import os
import launch
from modules import cmd_args, script_loading
from modules.paths_internal import data_path, default_sd_model_file, extensions_builtin_dir, extensions_dir, models_path, script_path, sd_model_file # noqa: F401
from modules.paths_internal import data_path, extensions_builtin_dir, extensions_dir, models_path, script_path # noqa: F401
parser = cmd_args.parser