import os def nuke_imports(path): with open(path, 'r') as f: lines = f.readlines() new_lines = [] in_imports = False modified = False for line in lines: stripped = line.strip() if stripped == "imports:": in_imports = True new_lines.append(line) continue if in_imports: if not stripped.startswith("-"): if stripped and not stripped.startswith("#"): in_imports = False new_lines.append(line) else: import_path = stripped.lstrip("- ").strip() # Remove imports of sibling classes (starting with ./) if import_path.startswith("./"): # But keep some if absolutely necessary? No, try removing all. # Keep SpecificityScore maybe? No. # Keep Type/Types? No. print(f"Removing sibling import in {path}: {stripped}") modified = True continue # Remove imports of parent classes (starting with ../classes/) elif import_path.startswith("../classes/"): print(f"Removing parent class import in {path}: {stripped}") modified = True continue else: new_lines.append(line) else: new_lines.append(line) if modified: with open(path, 'w') as f: f.writelines(new_lines) def process_directory(directory): for root, dirs, files in os.walk(directory): for file in files: if file.endswith(".yaml"): nuke_imports(os.path.join(root, file)) process_directory("schemas/20251121/linkml/modules/classes")