aibilly_backend_code/mass_fix.py
laxmanhalaki b793ac859a
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / build (push) Has been cancelled
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-production (push) Has been cancelled
modification done to up the project
2026-03-12 20:52:08 +05:30

58 lines
2.4 KiB
Python

import os
from pathlib import Path
import re
def fix_models():
models_dir = Path("src/models")
for model_file in models_dir.glob("*.py"):
content = model_file.read_text(encoding="utf-8")
# Fix reserved 'metadata' name
content = content.replace('metadata = Column(JSON', 'doc_metadata = Column(JSON')
model_file.write_text(content, encoding="utf-8")
def fix_services():
services_dir = Path("src/services")
for service_file in services_dir.glob("*.py"):
content = service_file.read_text(encoding="utf-8")
# Add basic imports
needed_imports = []
if " date" in content and "from datetime import date" not in content and "import datetime" not in content:
needed_imports.append("from datetime import date")
if " datetime" in content and "from datetime import" not in content and "import datetime" not in content:
needed_imports.append("from datetime import datetime")
if " Decimal" in content and "from decimal import Decimal" not in content:
needed_imports.append("from decimal import Decimal")
if needed_imports:
content = "\n".join(needed_imports) + "\n" + content
# Fix missing model type hints by replacing them with Any
# Exclude common types like UUID, int, str, bool, List, Dict, Tuple, Optional
def replace_type(match):
type_name = match.group(1)
if type_name in ["UUID", "int", "str", "bool", "List", "Dict", "Tuple", "Optional", "Any", "None", "float", "bytes"]:
return match.group(0)
return match.group(0).replace(type_name, "Any")
content = re.sub(r"-> List\[([A-Z]\w+)\]", replace_type, content)
content = re.sub(r"-> ([A-Z]\w+)", replace_type, content)
content = re.sub(r": ([A-Z]\w+)", replace_type, content)
# Standardize CRUD class name
content = re.sub(r"class (\w+)Service", r"class \1CRUD", content)
# Ensure 'Any' is imported
if "from typing import" in content:
if "Any" not in content:
content = content.replace("from typing import", "from typing import Any, ")
else:
content = "from typing import Any\n" + content
service_file.write_text(content, encoding="utf-8")
print(f"Fixed service {service_file.name}")
if __name__ == "__main__":
fix_models()
fix_services()