better way to load google files

This commit is contained in:
layerdiffusion
2024-09-08 18:03:14 -07:00
parent f40930c55b
commit 9439319007
3 changed files with 24 additions and 33 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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