mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
major refactor
This commit is contained in:
+5
-6
@@ -4,7 +4,7 @@ import sys
|
||||
import time
|
||||
from collections import namedtuple
|
||||
import gradio as gr
|
||||
from modules import paths, script_callbacks, extensions, script_loading, scripts_postprocessing, errors
|
||||
from modules import paths, script_callbacks, extensions, script_loading, scripts_postprocessing, errors, timer
|
||||
from installer import log
|
||||
|
||||
|
||||
@@ -226,13 +226,14 @@ def list_files_with_name(filename):
|
||||
|
||||
|
||||
def load_scripts():
|
||||
t = timer.Timer()
|
||||
t0 = time.time()
|
||||
global current_basedir # pylint: disable=global-statement
|
||||
scripts_data.clear()
|
||||
postprocessing_scripts_data.clear()
|
||||
script_callbacks.clear_callbacks()
|
||||
scripts_list = list_scripts("scripts", ".py")
|
||||
syspath = sys.path
|
||||
time_load = {}
|
||||
|
||||
def register_scripts_from_module(module, scriptfile):
|
||||
for script_class in module.__dict__.values():
|
||||
@@ -245,7 +246,6 @@ def load_scripts():
|
||||
postprocessing_scripts_data.append(ScriptClassData(script_class, scriptfile.path, scriptfile.basedir, module))
|
||||
|
||||
for scriptfile in scripts_list:
|
||||
t0 = time.time()
|
||||
try:
|
||||
if scriptfile.basedir != paths.script_path:
|
||||
sys.path = [scriptfile.basedir] + sys.path
|
||||
@@ -256,7 +256,7 @@ def load_scripts():
|
||||
errors.display(e, f'Loading script: {scriptfile.filename}')
|
||||
finally:
|
||||
current_basedir = paths.script_path
|
||||
time_load[scriptfile.basedir] = time_load.get(scriptfile.basedir, 0) + (time.time()-t0)
|
||||
t.record(os.path.basename(scriptfile.basedir))
|
||||
sys.path = syspath
|
||||
|
||||
global scripts_txt2img, scripts_img2img, scripts_postproc # pylint: disable=global-statement
|
||||
@@ -264,8 +264,7 @@ def load_scripts():
|
||||
scripts_img2img = ScriptRunner()
|
||||
scripts_postproc = scripts_postprocessing.ScriptPostprocessingRunner()
|
||||
|
||||
time_summary = [f'{os.path.basename(k)}:{round(v,3)}s' for (k,v) in time_load.items() if v > 0.05]
|
||||
log.debug(f'Scripts load: {time_summary}')
|
||||
return t, time.time()-t0
|
||||
|
||||
|
||||
def wrap_call(func, filename, funcname, *args, default=None, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user