Create scan_relative_imports.py
Browse files- scan_relative_imports.py +24 -0
scan_relative_imports.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
PROJECT_ROOT = "." # Change this if your root is not the current folder
|
| 5 |
+
|
| 6 |
+
matches = []
|
| 7 |
+
|
| 8 |
+
for dirpath, _, filenames in os.walk(PROJECT_ROOT):
|
| 9 |
+
for filename in filenames:
|
| 10 |
+
if filename.endswith(".py"):
|
| 11 |
+
filepath = os.path.join(dirpath, filename)
|
| 12 |
+
with open(filepath, encoding="utf-8") as f:
|
| 13 |
+
for lineno, line in enumerate(f, 1):
|
| 14 |
+
if re.match(r"\s*from\s+\.+", line):
|
| 15 |
+
matches.append((filepath, lineno, line.strip()))
|
| 16 |
+
|
| 17 |
+
# Print results
|
| 18 |
+
if matches:
|
| 19 |
+
print("\n⚠️ Relative imports found:\n")
|
| 20 |
+
for filepath, lineno, line in matches:
|
| 21 |
+
print(f"{filepath}:{lineno}: {line}")
|
| 22 |
+
print(f"\nTotal: {len(matches)} relative imports detected.")
|
| 23 |
+
else:
|
| 24 |
+
print("✅ No relative imports found.")
|