import os import re PROJECT_ROOT = "." # Change this if your root is not the current folder matches = [] for dirpath, _, filenames in os.walk(PROJECT_ROOT): for filename in filenames: if filename.endswith(".py"): filepath = os.path.join(dirpath, filename) with open(filepath, encoding="utf-8") as f: for lineno, line in enumerate(f, 1): if re.match(r"\s*from\s+\.+", line): matches.append((filepath, lineno, line.strip())) # Print results if matches: print("\n⚠️ Relative imports found:\n") for filepath, lineno, line in matches: print(f"{filepath}:{lineno}: {line}") print(f"\nTotal: {len(matches)} relative imports detected.") else: print("✅ No relative imports found.")