Spaces:
Sleeping
Sleeping
| """Patch lightglue __init__.py to wrap optional imports in try/except.""" | |
| import pathlib | |
| matches = list(pathlib.Path("/usr/local/lib").rglob("lightglue/__init__.py")) | |
| if not matches: | |
| print("lightglue __init__.py not found, skipping patch") | |
| exit(0) | |
| f = matches[0] | |
| print(f"Patching {f}") | |
| text = f.read_text() | |
| lines = text.split("\n") | |
| out = [] | |
| # Keep superpoint, lightglue, utils imports untouched | |
| # Wrap disk, aliked, doghardnet etc. in try/except | |
| keep = {"superpoint", "lightglue", "utils", "sift"} | |
| for line in lines: | |
| if line.startswith("from .") and "import" in line: | |
| module = line.split("from .")[1].split(" ")[0] | |
| if module in keep: | |
| out.append(line) | |
| else: | |
| out.append("try:") | |
| out.append(" " + line) | |
| out.append("except Exception:") | |
| out.append(" pass") | |
| else: | |
| out.append(line) | |
| f.write_text("\n".join(out)) | |
| print("Patched OK") | |