Update app.py
Browse files
app.py
CHANGED
|
@@ -57,33 +57,35 @@ def _patch_relative_imports(project_root: str):
|
|
| 57 |
# --- END ABSOLUTE-IMPORT & ENV HOTFIX ---
|
| 58 |
|
| 59 |
|
| 60 |
-
# --- BEGIN runtime compatibility:
|
| 61 |
-
# Some modules still do `import utilities`.
|
| 62 |
-
#
|
| 63 |
-
#
|
| 64 |
import importlib
|
| 65 |
-
import
|
| 66 |
|
| 67 |
if "utilities" not in sys.modules:
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
# --- END runtime compatibility ---------------------------------------------
|
| 88 |
|
| 89 |
|
|
|
|
| 57 |
# --- END ABSOLUTE-IMPORT & ENV HOTFIX ---
|
| 58 |
|
| 59 |
|
| 60 |
+
# --- BEGIN runtime compatibility: lazy proxy for "utilities" -> "utils" -------
|
| 61 |
+
# Some modules still do `import utilities`. Create a lazy proxy that will import
|
| 62 |
+
# the real `utils` only when attributes are accessed, avoiding recursive
|
| 63 |
+
# import-time interactions with any lazy `utils` implementation.
|
| 64 |
import importlib
|
| 65 |
+
from types import ModuleType
|
| 66 |
|
| 67 |
if "utilities" not in sys.modules:
|
| 68 |
+
class _LazyUtilities(ModuleType):
|
| 69 |
+
def __getattr__(self, name):
|
| 70 |
+
# Import the real utils once on first attribute access and replace
|
| 71 |
+
# the 'utilities' entry in sys.modules with it so subsequent
|
| 72 |
+
# imports refer to the real module.
|
| 73 |
+
real = importlib.import_module("utils")
|
| 74 |
+
sys.modules["utilities"] = real
|
| 75 |
+
# Alias already-imported utils submodules as utilities.<submodule>
|
| 76 |
+
for modname, module in list(sys.modules.items()):
|
| 77 |
+
if modname.startswith("utils.") and isinstance(module, ModuleType):
|
| 78 |
+
suffix = modname.partition(".")[2]
|
| 79 |
+
sys.modules[f"utilities.{suffix}"] = module
|
| 80 |
+
return getattr(real, name)
|
| 81 |
+
def __dir__(self):
|
| 82 |
+
try:
|
| 83 |
+
real = importlib.import_module("utils")
|
| 84 |
+
return dir(real)
|
| 85 |
+
except Exception:
|
| 86 |
+
return list(super().__dir__())
|
| 87 |
+
|
| 88 |
+
sys.modules["utilities"] = _LazyUtilities("utilities")
|
| 89 |
# --- END runtime compatibility ---------------------------------------------
|
| 90 |
|
| 91 |
|