report-detect/archive/temp_scripts/force_reload_test.py

59 lines
1.5 KiB
Python
Raw Permalink Normal View History

chore(project): conservative cleanup - archive temp scripts and old docs Major cleanup to improve project organization and maintainability. Changes: - Moved 34 temp/debug/test scripts to archive/temp_scripts/ - Moved 9 auxiliary tools to archive/tools/ - Moved 3 CRT test scripts to archive/crt_tests/ - Moved 4 OCR test scripts to archive/ocr_tests/ - Moved 14 old documentation files to archive/docs/ - Deleted 4 useless files (duplicates, temp files) Root directory: - Before: 67 files (cluttered) - After: 10 core files (clean and organized) Core files retained: - test_accuracy_batch_full.py (main script) - cma_extraction_template_primary.py (CMA extraction) - cma_extraction_final.py (backup CMA extraction) - CLAUDE.md (project guide) - TEST_ACCURACY_BATCH_README.md (usage guide) - TEST_ACCURACY_BATCH_DEPENDENCIES.md (dependency docs) - CLEANUP_PLAN.md (cleanup plan) - CLEANUP_SUMMARY.md (this file) - IMPLEMENTATION_SUMMARY.md (implementation summary) - requirements.txt (dependencies) Archive structure: archive/ ├── temp_scripts/ (34 files: test_, debug_, analyze_, etc.) ├── tools/ (9 files: find_, show_, visualize_, etc.) ├── crt_tests/ (3 files: CRT extraction tests) ├── ocr_tests/ (4 files: OCR timeout tests) └── docs/ (14 files: old reports and guides) Benefits: ✓ Cleaner root directory - easier navigation ✓ Better organization - clear separation of concerns ✓ Preserved history - all files archived, not deleted ✓ Improved maintainability - easier to find active files ✓ Better git history - removed 198 deleted files from tracking No functional changes - all core functionality preserved. Related: - TEST_ACCURACY_BATCH_DEPENDENCIES.md - dependency analysis - CLEANUP_PLAN.md - detailed cleanup plan Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 14:35:06 +08:00
"""
Force reload and test with fresh Python process
"""
import subprocess
import sys
print("=" * 80)
print("CLEARING ALL CACHE AND STARTING FRESH PYTHON PROCESS")
print("=" * 80)
# Delete all __pycache__ directories
print("\n1. Deleting Python cache...")
result = subprocess.run(
["python", "-c",
"import os, shutil; [shutil.rmtree(os.path.join(root, d)) for root, dirs, files in os.walk('.') for d in dirs if d == '__pycache__']"],
capture_output=True
)
print(f" Cache cleared (exit code: {result.returncode})")
# Now run the test in a fresh subprocess
print("\n2. Starting fresh Python process...")
test_cmd = [
sys.executable, "-c",
"""
import sys
import os
os.environ["DISABLE_MODEL_SOURCE_CHECK"] = "True"
# Force fresh imports
for mod in list(sys.modules.keys()):
if 'cma_extraction' in mod or 'test_accuracy' in mod:
del sys.modules[mod]
# Now run the test
from test_accuracy_batch_full import process_single_pdf_standalone
from pathlib import Path
pdf_path = Path("src/test/resources/data/pdfs/YDQ23_001838.pdf")
output_dir = Path("test_reports_fresh")
print(f"Processing: {pdf_path}")
print(f"Output: {output_dir}")
print()
result = process_single_pdf_standalone(pdf_path, output_dir, "ppocr_v5")
print()
print("=" * 80)
print("RESULT")
print("=" * 80)
print(f"Status: {result['status']}")
print(f"CMA: {result['cma']}")
"""
]
print(" Command:", " ".join(test_cmd))
print()
result = subprocess.run(test_cmd, capture_output=False, text=True)