MCPcopy
hub / github.com/AUTOMATIC1111/stable-diffusion-webui / load_scripts

Function load_scripts

modules/scripts.py:487–530  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

485
486
487def load_scripts():
488 global current_basedir
489 scripts_data.clear()
490 postprocessing_scripts_data.clear()
491 script_callbacks.clear_callbacks()
492
493 scripts_list = list_scripts("scripts", ".py") + list_scripts("modules/processing_scripts", ".py", include_extensions=False)
494
495 syspath = sys.path
496
497 def register_scripts_from_module(module):
498 for script_class in module.__dict__.values():
499 if not inspect.isclass(script_class):
500 continue
501
502 if issubclass(script_class, Script):
503 scripts_data.append(ScriptClassData(script_class, scriptfile.path, scriptfile.basedir, module))
504 elif issubclass(script_class, scripts_postprocessing.ScriptPostprocessing):
505 postprocessing_scripts_data.append(ScriptClassData(script_class, scriptfile.path, scriptfile.basedir, module))
506
507 # here the scripts_list is already ordered
508 # processing_script is not considered though
509 for scriptfile in scripts_list:
510 try:
511 if scriptfile.basedir != paths.script_path:
512 sys.path = [scriptfile.basedir] + sys.path
513 current_basedir = scriptfile.basedir
514
515 script_module = script_loading.load_module(scriptfile.path)
516 register_scripts_from_module(script_module)
517
518 except Exception:
519 errors.report(f"Error loading script: {scriptfile.filename}", exc_info=True)
520
521 finally:
522 sys.path = syspath
523 current_basedir = paths.script_path
524 timer.startup_timer.record(scriptfile.filename)
525
526 global scripts_txt2img, scripts_img2img, scripts_postproc
527
528 scripts_txt2img = ScriptRunner()
529 scripts_img2img = ScriptRunner()
530 scripts_postproc = scripts_postprocessing.ScriptPostprocessingRunner()
531
532
533def wrap_call(func, filename, funcname, *args, default=None, **kwargs):

Callers

nothing calls this directly

Calls 5

list_scriptsFunction · 0.85
ScriptRunnerClass · 0.85
clearMethod · 0.80
recordMethod · 0.80

Tested by

no test coverage detected