#!/usr/bin/env python3 """ Fix pyrf Python 3 compatibility. The pyrf library ships with Python 2 syntax in pyrf/devices/thinkrf.py. This script uses lib2to3 to automatically convert it to Python 3. Usage: python scripts/fix_pyrf_python3.py Run this after installing pyrf: pip install ria-toolkit-oss[thinkrf] python scripts/fix_pyrf_python3.py """ from lib2to3.refactor import RefactoringTool, get_fixers_from_package from pathlib import Path try: import pyrf except ImportError: print("ERROR: pyrf is not installed.") print("Install with: pip install pyrf") print("Or install ria with ThinkRF support: pip install ria-toolkit-oss[thinkrf]") exit(1) # Find the thinkrf.py file in the pyrf package thinkrf_path = Path(pyrf.__file__).resolve().parent / "devices" / "thinkrf.py" if not thinkrf_path.exists(): print(f"ERROR: Could not find {thinkrf_path}") print("Is pyrf installed correctly?") exit(1) print(f"Found pyrf ThinkRF module at: {thinkrf_path}") # Apply lib2to3 fixes print("Applying Python 3 compatibility fixes...") fixers = get_fixers_from_package("lib2to3.fixes") tool = RefactoringTool(fixers) tool.refactor_file(str(thinkrf_path), write=True) print(f"✅ Successfully patched {thinkrf_path} for Python 3 compatibility.") print("\nYou can now use ria_toolkit_oss.sdr.thinkrf.ThinkRF")