Skip to content

Commit f2b6970

Browse files
committed
move option access checking to options class out of various places scattered through code
1 parent 26108a7 commit f2b6970

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

modules/processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
418418

419419
try:
420420
for k, v in p.override_settings.items():
421-
opts.data[k] = v # we don't call onchange for simplicity which makes changing model, hypernet impossible
421+
setattr(opts, k, v) # we don't call onchange for simplicity which makes changing model, hypernet impossible
422422

423423
res = process_images_inner(p)
424424

425425
finally:
426426
for k, v in stored_opts.items():
427-
opts.data[k] = v
427+
setattr(opts, k, v)
428428

429429
return res
430430

modules/shared.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ def __init__(self):
396396
def __setattr__(self, key, value):
397397
if self.data is not None:
398398
if key in self.data or key in self.data_labels:
399+
assert not cmd_opts.freeze_settings, "changing settings is disabled"
400+
401+
comp_args = opts.data_labels[key].component_args
402+
if isinstance(comp_args, dict) and comp_args.get('visible', True) is False:
403+
raise RuntimeError(f"not possible to set {key} because it is restricted")
404+
405+
if cmd_opts.hide_ui_dir_config and key in restricted_opts:
406+
raise RuntimeError(f"not possible to set {key} because it is restricted")
407+
399408
self.data[key] = value
400409
return
401410

@@ -412,6 +421,8 @@ def __getattr__(self, item):
412421
return super(Options, self).__getattribute__(item)
413422

414423
def save(self, filename):
424+
assert not cmd_opts.freeze_settings, "saving settings is disabled"
425+
415426
with open(filename, "w", encoding="utf8") as file:
416427
json.dump(self.data, file, indent=4)
417428

modules/ui.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,6 @@ def fun():
14381438
def run_settings(*args):
14391439
changed = 0
14401440

1441-
assert not shared.cmd_opts.freeze_settings, "changing settings is disabled"
1442-
14431441
for key, value, comp in zip(opts.data_labels.keys(), args, components):
14441442
if comp != dummy_component and not opts.same_type(value, opts.data_labels[key].default):
14451443
return f"Bad value for setting {key}: {value}; expecting {type(opts.data_labels[key].default).__name__}", opts.dumpjson()
@@ -1448,15 +1446,9 @@ def run_settings(*args):
14481446
if comp == dummy_component:
14491447
continue
14501448

1451-
comp_args = opts.data_labels[key].component_args
1452-
if comp_args and isinstance(comp_args, dict) and comp_args.get('visible') is False:
1453-
continue
1454-
1455-
if cmd_opts.hide_ui_dir_config and key in restricted_opts:
1456-
continue
1457-
14581449
oldval = opts.data.get(key, None)
1459-
opts.data[key] = value
1450+
1451+
setattr(opts, key, value)
14601452

14611453
if oldval != value:
14621454
if opts.data_labels[key].onchange is not None:
@@ -1469,17 +1461,15 @@ def run_settings(*args):
14691461
return f'{changed} settings changed.', opts.dumpjson()
14701462

14711463
def run_settings_single(value, key):
1472-
assert not shared.cmd_opts.freeze_settings, "changing settings is disabled"
1473-
14741464
if not opts.same_type(value, opts.data_labels[key].default):
14751465
return gr.update(visible=True), opts.dumpjson()
14761466

14771467
oldval = opts.data.get(key, None)
1478-
if cmd_opts.hide_ui_dir_config and key in restricted_opts:
1468+
try:
1469+
setattr(opts, key, value)
1470+
except Exception:
14791471
return gr.update(value=oldval), opts.dumpjson()
14801472

1481-
opts.data[key] = value
1482-
14831473
if oldval != value:
14841474
if opts.data_labels[key].onchange is not None:
14851475
opts.data_labels[key].onchange()

0 commit comments

Comments
 (0)