Spaces:
Runtime error
Runtime error
| import os | |
| import sys | |
| PATCH_FILE = os.path.abspath(__file__) | |
| ROOT = os.path.dirname(PATCH_FILE) | |
| APP_FILE = os.path.join(ROOT, "app.py") | |
| TARGET_PREFIX = "omniscientframework.utils" | |
| def patch_file(filepath): | |
| if not os.path.exists(filepath): | |
| print(f"[patch] File not found: {filepath}") | |
| return False | |
| with open(filepath, "r") as f: | |
| original = f.read() | |
| patched = original.replace( | |
| "from utils.", | |
| f"from {TARGET_PREFIX}." | |
| ) | |
| if patched == original: | |
| print("[patch] No changes needed in app.py.") | |
| else: | |
| with open(filepath, "w") as f: | |
| f.write(patched) | |
| print("[patch] Patched import paths in app.py.") | |
| return True | |
| def ensure_init_files(): | |
| package_dirs = [ | |
| os.path.join(ROOT, "omniscientframework"), | |
| os.path.join(ROOT, "omniscientframework", "utils") | |
| ] | |
| for d in package_dirs: | |
| init_file = os.path.join(d, "__init__.py") | |
| if not os.path.exists(d): | |
| print(f"[patch] Directory missing: {d}") | |
| continue | |
| if not os.path.exists(init_file): | |
| with open(init_file, "w") as f: | |
| f.write("") # empty init file | |
| print(f"[patch] Created {init_file}") | |
| else: | |
| print(f"[patch] Init exists: {init_file}") | |
| def self_delete(): | |
| print("[patch] Cleaning up patch file...") | |
| try: | |
| os.remove(PATCH_FILE) | |
| print("[patch] Patch file removed from container runtime.") | |
| except Exception as e: | |
| print(f"[patch] Failed to delete self: {e}") | |
| def main(): | |
| print("[patch] Running import patcher...") | |
| ok = patch_file(APP_FILE) | |
| ensure_init_files() | |
| if ok: | |
| self_delete() | |
| print("[patch] Done.") | |
| if __name__ == "__main__": | |
| main() | |