Update main_app.py
Browse files- main_app.py +23 -24
main_app.py
CHANGED
@@ -425,33 +425,32 @@ def _(function_editor, mo, os):
|
|
425 |
try:
|
426 |
return __import__(name, *args, **kwargs)
|
427 |
except ImportError:
|
428 |
-
#
|
429 |
-
class DummyModule:
|
430 |
-
_instance = None
|
431 |
-
|
432 |
-
def __new__(cls):
|
433 |
-
if cls._instance is None:
|
434 |
-
cls._instance = super().__new__(cls)
|
435 |
-
return cls._instance
|
436 |
-
|
437 |
-
def __getattr__(self, name):
|
438 |
-
return self
|
439 |
-
|
440 |
-
def __call__(self, *args, **kwargs):
|
441 |
-
return self
|
442 |
-
|
443 |
-
# Add to sys.modules to handle nested imports
|
444 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
if '.' in name:
|
446 |
parts = name.split('.')
|
447 |
-
for i in range(1, len(parts)
|
448 |
-
|
449 |
-
if
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
return
|
455 |
|
456 |
# Create a namespace to execute the code in
|
457 |
namespace = {'__builtins__': __builtins__, '__import__': safe_import}
|
|
|
425 |
try:
|
426 |
return __import__(name, *args, **kwargs)
|
427 |
except ImportError:
|
428 |
+
# Create a dummy module that returns itself for any attribute
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
import sys
|
430 |
+
import types
|
431 |
+
|
432 |
+
# Create a proper module object rather than a class
|
433 |
+
dummy = types.ModuleType(name)
|
434 |
+
|
435 |
+
# Make the module return itself for any attribute
|
436 |
+
def __getattr__(attr):
|
437 |
+
return dummy
|
438 |
+
dummy.__getattr__ = __getattr__
|
439 |
+
|
440 |
+
# Register in sys.modules to handle nested imports
|
441 |
+
sys.modules[name] = dummy
|
442 |
+
|
443 |
+
# Also register parent modules
|
444 |
if '.' in name:
|
445 |
parts = name.split('.')
|
446 |
+
for i in range(1, len(parts)):
|
447 |
+
parent_name = '.'.join(parts[:i])
|
448 |
+
if parent_name not in sys.modules:
|
449 |
+
parent = types.ModuleType(parent_name)
|
450 |
+
parent.__getattr__ = lambda attr: dummy if attr == parts[i] else parent
|
451 |
+
sys.modules[parent_name] = parent
|
452 |
+
|
453 |
+
return dummy
|
454 |
|
455 |
# Create a namespace to execute the code in
|
456 |
namespace = {'__builtins__': __builtins__, '__import__': safe_import}
|