Spaces:
Runtime error
Runtime error
File size: 1,791 Bytes
688136c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
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()
|