Repository navigation
Expand file tree
/
Copy pathtest_code_structure.py
More file actions
142 lines (126 loc) · 4.03 KB
/
Copy pathtest_code_structure.py
File metadata and controls
142 lines (126 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
Kod yapısı testi - Bağımlılıklar olmadan syntax ve yapı kontrolü
"""
import os
import sys
import ast
import importlib.util
print("=" * 70)
print("🔍 Kod Yapısı ve Syntax Kontrolü")
print("=" * 70)
print()
# SUMO_HOME ayarla
sumo_home = "/opt/homebrew/opt/sumo/share/sumo"
os.environ["SUMO_HOME"] = sumo_home
sys.path.insert(0, os.path.join(sumo_home, "tools"))
def check_syntax(file_path):
"""Dosyanın syntax'ını kontrol et"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
code = f.read()
ast.parse(code)
return True, None
except SyntaxError as e:
return False, str(e)
except Exception as e:
return False, str(e)
def check_file_exists(file_path):
"""Dosyanın varlığını kontrol et"""
return os.path.exists(file_path)
def check_imports_in_file(file_path):
"""Dosyadaki import'ları kontrol et (syntax için)"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
code = f.read()
tree = ast.parse(code)
imports = []
for node in ast.walk(tree):
if isinstance(node, ast.Import):
for alias in node.names:
imports.append(alias.name)
elif isinstance(node, ast.ImportFrom):
if node.module:
imports.append(node.module)
return imports
except:
return []
print("1️⃣ Python Dosyaları Syntax Kontrolü:")
print("-" * 70)
python_files = [
"src/environment/sumo_env.py",
"src/environment/traffic_agent.py",
"src/algorithms/dqn.py",
"src/algorithms/maddpg.py",
"src/algorithms/qmix.py",
"src/utils/visualization.py",
"src/utils/metrics.py",
"src/train.py",
]
all_syntax_ok = True
for file_path in python_files:
exists = check_file_exists(file_path)
if not exists:
print(f" ❌ {file_path}: Dosya bulunamadı")
all_syntax_ok = False
continue
is_valid, error = check_syntax(file_path)
if is_valid:
imports = check_imports_in_file(file_path)
print(f" ✅ {file_path}")
if imports:
print(f" 📦 İmportlar: {', '.join(imports[:5])}{'...' if len(imports) > 5 else ''}")
else:
print(f" ❌ {file_path}: Syntax hatası - {error}")
all_syntax_ok = False
print()
print("2️⃣ TraCI Import Testi:")
print("-" * 70)
try:
import traci
print(" ✅ TraCI başarıyla import edildi")
print(f" 📍 TraCI modülü: {traci.__file__}")
except ImportError as e:
print(f" ❌ TraCI import hatası: {e}")
except Exception as e:
print(f" ⚠️ TraCI kontrolü: {e}")
print()
print("3️⃣ Yapılandırma Dosyaları:")
print("-" * 70)
config_files = [
"configs/default.yaml",
"requirements.txt",
"setup.py",
]
for config_file in config_files:
if check_file_exists(config_file):
size = os.path.getsize(config_file)
print(f" ✅ {config_file} ({size} bytes)")
else:
print(f" ❌ {config_file} bulunamadı")
print()
print("4️⃣ Senaryo Dosyaları:")
print("-" * 70)
scenario_files = [
"data/scenarios/single_intersection/single_intersection.net.xml",
"data/scenarios/single_intersection/single_intersection.rou.xml",
"data/scenarios/single_intersection/single_intersection.sumocfg",
]
for scenario_file in scenario_files:
if check_file_exists(scenario_file):
size = os.path.getsize(scenario_file)
print(f" ✅ {scenario_file} ({size} bytes)")
else:
print(f" ❌ {scenario_file} bulunamadı")
print()
print("=" * 70)
if all_syntax_ok:
print("✅ Tüm Python dosyaları syntax hatasızdır!")
print()
print("📝 Sonraki adımlar:")
print(" 1. Bağımlılıkları yükleyin: pip install -r requirements.txt")
print(" 2. Test çalıştırın: python3 test_imports.py")
print(" 3. Eğitimi başlatın: python3 src/train.py --algorithm dqn")
else:
print("⚠️ Bazı dosyalarda sorunlar var. Lütfen kontrol edin.")
print("=" * 70)