|
1 | 1 | import subprocess |
2 | 2 | import sys |
| 3 | +import importlib.util |
3 | 4 | import traceback |
| 5 | +import os |
4 | 6 |
|
5 | | -# 1. Adım: graphillion bağımlılığını pip ile kur |
6 | | -print("--> Installing graphillion dependency via pip...") |
7 | | -try: |
8 | | - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--no-cache-dir', 'graphillion>=1.0']) |
9 | | - print("--> graphillion successfully installed.") |
10 | | -except subprocess.CalledProcessError as e: |
11 | | - with open("test_error.log", "w", encoding="utf-8") as f: |
12 | | - f.write("Failed to install graphillion.\n") |
13 | | - f.write(str(e)) |
14 | | - sys.exit(1) |
| 7 | +def check_and_install_package(package_name, min_version=None): |
| 8 | + """Paketi kontrol et, kurulu değilse/versiyon eskiyse kur/güncelle""" |
| 9 | + # 1. Paket kurulu mu kontrol et |
| 10 | + spec = importlib.util.find_spec(package_name) |
| 11 | + if spec is None: |
| 12 | + print(f"➤ {package_name} YOK - KURULUYOR...") |
| 13 | + install_cmd = [sys.executable, '-m', 'pip', 'install', '--no-cache-dir', package_name] |
| 14 | + if min_version: |
| 15 | + install_cmd.extend([f'>={min_version}']) |
| 16 | + else: |
| 17 | + print(f"➤ {package_name} KURULU - GÜNCELLENİYOR...") |
| 18 | + install_cmd = [sys.executable, '-m', 'pip', 'install', '--upgrade', '--no-cache-dir', package_name] |
| 19 | + |
| 20 | + try: |
| 21 | + subprocess.check_call(install_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 22 | + print(f"✅ {package_name} başarıyla güncellendi!") |
| 23 | + return True |
| 24 | + except subprocess.CalledProcessError: |
| 25 | + print(f"❌ {package_name} kurulamadı!") |
| 26 | + return False |
15 | 27 |
|
16 | | -# 2. Adım: kececilayout paketini import etmeyi dene |
17 | | -print("\n--> Attempting to import kececilayout...") |
18 | | -try: |
19 | | - import kececilayout |
20 | | - print("--> SUCCESS: kececilayout was imported successfully.") |
21 | | - # Başarıyı belirtmek için boş bir dosya oluştur |
22 | | - with open("test_success.log", "w", encoding="utf-8") as f: |
23 | | - f.write("OK") |
24 | | - sys.exit(0) |
25 | | -except Exception: |
26 | | - # HATA DURUMUNDA: Traceback'i bir dosyaya yazdır |
27 | | - print("\n!!! IMPORT FAILED, SAVING TRACEBACK TO test_error.log !!!") |
28 | | - with open("test_error.log", "w", encoding="utf-8") as f: |
29 | | - traceback.print_exc(file=f) |
30 | | - sys.exit(1) |
| 28 | +def main(): |
| 29 | + print("🔧 KececiLayout Kurulum/Test Aracı") |
| 30 | + print("=" * 50) |
| 31 | + |
| 32 | + # 1. graphillion kontrol et ve kur/güncelle |
| 33 | + if not check_and_install_package('graphillion', '1.0'): |
| 34 | + print("❌ Graphillion kurulamadı! Çıkılıyor...") |
| 35 | + sys.exit(1) |
| 36 | + |
| 37 | + # 2. kececilayout kontrol et ve kur/güncelle |
| 38 | + print("\n➤ kececilayout paketi kontrol ediliyor...") |
| 39 | + if not check_and_install_package('kececilayout'): |
| 40 | + print("❌ kececilayout kurulamadı! Çıkılıyor...") |
| 41 | + sys.exit(1) |
| 42 | + |
| 43 | + # 3. Import test et (Jupyter/konsol uyumlu) |
| 44 | + print("\n🔍 Import testi yapılıyor...") |
| 45 | + try: |
| 46 | + import kececilayout as kl |
| 47 | + print("✅ IMPORT BAŞARILI!") |
| 48 | + |
| 49 | + # Test çizimi (Jupyter uyumlu) |
| 50 | + try: |
| 51 | + import networkx as nx |
| 52 | + import matplotlib.pyplot as plt |
| 53 | + |
| 54 | + G = nx.gnp_random_graph(5, 0.3) |
| 55 | + pos = kl.kececi_layout_2d(G) |
| 56 | + plt.figure(figsize=(6,4)) |
| 57 | + nx.draw(G, pos, with_labels=True) |
| 58 | + plt.title("✅ KececiLayout Test - BAŞARILI!") |
| 59 | + plt.show() |
| 60 | + print("🎉 Test grafiği başarıyla çizildi!") |
| 61 | + |
| 62 | + except ImportError: |
| 63 | + print("ℹ️ NetworkX/Matplotlib yok - sadece import testi yapıldı") |
| 64 | + |
| 65 | + # Başarı dosyası oluştur |
| 66 | + with open("kececi_test_success.log", "w", encoding="utf-8") as f: |
| 67 | + f.write("OK") |
| 68 | + print("✅ test_success.log oluşturuldu") |
| 69 | + return 0 |
| 70 | + |
| 71 | + except Exception as e: |
| 72 | + print(f"\n❌ IMPORT HATASI: {e}") |
| 73 | + print("🔍 Detaylar test_error.log dosyasına kaydedildi") |
| 74 | + |
| 75 | + # Jupyter'de traceback göster, konsolda dosyaya yaz |
| 76 | + if 'ipykernel' in sys.modules or 'IPython' in sys.modules: |
| 77 | + traceback.print_exc() |
| 78 | + else: |
| 79 | + with open("test_error.log", "w", encoding="utf-8") as f: |
| 80 | + traceback.print_exc(file=f) |
| 81 | + |
| 82 | + return 1 |
| 83 | + |
| 84 | +if __name__ == "__main__": |
| 85 | + sys.exit(main()) |
0 commit comments