mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-03-06 13:39:51 +00:00
better way to load google files
This commit is contained in:
@@ -133,8 +133,8 @@ def initialize_rest(*, reload_script_modules=False):
|
||||
extra_networks.register_default_extra_networks()
|
||||
startup_timer.record("initialize extra networks")
|
||||
|
||||
from modules_forge.google_blockly.loader import load_all_google_blockly
|
||||
load_all_google_blockly()
|
||||
from modules_forge import google_blockly
|
||||
google_blockly.initialization()
|
||||
startup_timer.record("initialize google blockly")
|
||||
|
||||
return
|
||||
|
||||
@@ -46,8 +46,27 @@ governing permissions and limitations under the license.
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
import gzip
|
||||
import importlib.util
|
||||
|
||||
google_blockly_context = gzip.open(__file__ + 'z', 'rb').read().decode('utf-8')
|
||||
exec(google_blockly_context, globals())
|
||||
del google_blockly_context
|
||||
|
||||
current_dir = os.path.dirname(__file__)
|
||||
module_suffix = ".pyz"
|
||||
|
||||
|
||||
def initialization():
|
||||
for filename in os.listdir(current_dir):
|
||||
if not filename.endswith(module_suffix):
|
||||
continue
|
||||
|
||||
module_name = filename[:-len(module_suffix)]
|
||||
module_package_name = __package__ + '.' + module_name
|
||||
dynamic_module = importlib.util.module_from_spec(importlib.util.spec_from_loader(module_package_name, loader=None))
|
||||
dynamic_module.__dict__['__file__'] = os.path.join(current_dir, module_name + '.py')
|
||||
dynamic_module.__dict__['__package__'] = module_package_name
|
||||
google_blockly_context = gzip.open(os.path.join(current_dir, filename), 'rb').read().decode('utf-8')
|
||||
exec(google_blockly_context, dynamic_module.__dict__)
|
||||
globals()[module_name] = dynamic_module
|
||||
|
||||
return
|
||||
@@ -1,28 +0,0 @@
|
||||
import os
|
||||
import importlib
|
||||
|
||||
|
||||
def load_all_google_blockly():
|
||||
current_dir = os.path.dirname(__file__)
|
||||
package = __package__
|
||||
|
||||
for filename in os.listdir(current_dir):
|
||||
if filename == os.path.basename(__file__):
|
||||
continue
|
||||
|
||||
if not filename.endswith(".py"):
|
||||
continue
|
||||
|
||||
if filename.endswith("_s.py"):
|
||||
continue
|
||||
|
||||
if filename.endswith("_u.py"):
|
||||
continue
|
||||
|
||||
if filename.endswith("_m.py"):
|
||||
continue
|
||||
|
||||
module_name = f"{package}.{filename[:-3]}"
|
||||
importlib.import_module(module_name)
|
||||
|
||||
return
|
||||
Reference in New Issue
Block a user