Include comments in config.yaml even when converting from config.json

This commit is contained in:
cmdr2 2023-06-30 11:53:38 +05:30
parent 26042b1e26
commit 45f99ab48a
5 changed files with 16 additions and 0 deletions

View File

@ -68,6 +68,7 @@ if "%update_branch%"=="" (
@copy sd-ui-files\scripts\on_sd_start.bat scripts\ /Y
@copy sd-ui-files\scripts\check_modules.py scripts\ /Y
@copy sd-ui-files\scripts\get_config.py scripts\ /Y
@copy sd-ui-files\scripts\config.yaml.sample scripts\ /Y
@copy "sd-ui-files\scripts\Start Stable Diffusion UI.cmd" . /Y
@copy "sd-ui-files\scripts\Developer Console.cmd" . /Y

View File

@ -51,6 +51,7 @@ cp sd-ui-files/scripts/on_sd_start.sh scripts/
cp sd-ui-files/scripts/bootstrap.sh scripts/
cp sd-ui-files/scripts/check_modules.py scripts/
cp sd-ui-files/scripts/get_config.py scripts/
cp sd-ui-files/scripts/config.yaml.sample scripts/
cp sd-ui-files/scripts/start.sh .
cp sd-ui-files/scripts/developer_console.sh .
cp sd-ui-files/scripts/functions.sh scripts/

View File

@ -6,6 +6,7 @@
@copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y
@copy sd-ui-files\scripts\check_modules.py scripts\ /Y
@copy sd-ui-files\scripts\get_config.py scripts\ /Y
@copy sd-ui-files\scripts\config.yaml.sample scripts\ /Y
if exist "%cd%\profile" (
set HF_HOME=%cd%\profile\.cache\huggingface

View File

@ -5,6 +5,7 @@ cp sd-ui-files/scripts/on_env_start.sh scripts/
cp sd-ui-files/scripts/bootstrap.sh scripts/
cp sd-ui-files/scripts/check_modules.py scripts/
cp sd-ui-files/scripts/get_config.py scripts/
cp sd-ui-files/scripts/config.yaml.sample scripts/
source ./scripts/functions.sh

View File

@ -145,6 +145,18 @@ def setConfig(config):
try: # config.yaml
config_yaml_path = os.path.join(CONFIG_DIR, "config.yaml")
yaml = YAML()
if not hasattr(config, "_yaml_comment"):
config_yaml_sample_path = os.path.join(CONFIG_DIR, "config.yaml.sample")
if os.path.exists(config_yaml_sample_path):
with open(config_yaml_sample_path, "r", encoding="utf-8") as f:
commented_config = yaml.load(f)
for k in config:
commented_config[k] = config[k]
config = commented_config
yaml.indent(mapping=2, sequence=4, offset=2)
with open(config_yaml_path, "w", encoding="utf-8") as f:
yaml.dump(config, f)