Path: blob/master/modules/paths.py
3055 views
import os1import sys2from modules.paths_internal import models_path, script_path, data_path, extensions_dir, extensions_builtin_dir, cwd # noqa: F40134import modules.safe # noqa: F401567def mute_sdxl_imports():8"""create fake modules that SDXL wants to import but doesn't actually use for our purposes"""910class Dummy:11pass1213module = Dummy()14module.LPIPS = None15sys.modules['taming.modules.losses.lpips'] = module1617module = Dummy()18module.StableDataModuleFromConfig = None19sys.modules['sgm.data'] = module202122# data_path = cmd_opts_pre.data23sys.path.insert(0, script_path)2425# search for directory of stable diffusion in following places26sd_path = None27possible_sd_paths = [os.path.join(script_path, 'repositories/stable-diffusion-stability-ai'), '.', os.path.dirname(script_path)]28for possible_sd_path in possible_sd_paths:29if os.path.exists(os.path.join(possible_sd_path, 'ldm/models/diffusion/ddpm.py')):30sd_path = os.path.abspath(possible_sd_path)31break3233assert sd_path is not None, f"Couldn't find Stable Diffusion in any of: {possible_sd_paths}"3435mute_sdxl_imports()3637path_dirs = [38(sd_path, 'ldm', 'Stable Diffusion', []),39(os.path.join(sd_path, '../generative-models'), 'sgm', 'Stable Diffusion XL', ["sgm"]),40(os.path.join(sd_path, '../BLIP'), 'models/blip.py', 'BLIP', []),41(os.path.join(sd_path, '../k-diffusion'), 'k_diffusion/sampling.py', 'k_diffusion', ["atstart"]),42]4344paths = {}4546for d, must_exist, what, options in path_dirs:47must_exist_path = os.path.abspath(os.path.join(script_path, d, must_exist))48if not os.path.exists(must_exist_path):49print(f"Warning: {what} not found at path {must_exist_path}", file=sys.stderr)50else:51d = os.path.abspath(d)52if "atstart" in options:53sys.path.insert(0, d)54elif "sgm" in options:55# Stable Diffusion XL repo has scripts dir with __init__.py in it which ruins every extension's scripts dir, so we56# import sgm and remove it from sys.path so that when a script imports scripts.something, it doesbn't use sgm's scripts dir.5758sys.path.insert(0, d)59import sgm # noqa: F40160sys.path.pop(0)61else:62sys.path.append(d)63paths[what] = d646566