File size: 5,002 Bytes
ec7f58f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
"""
Post-build Package Version Checker
Logs installed package versions and validates imports
"""
import sys
import subprocess
import importlib

def check_package_version(package_name):
    """Get installed version of a package"""
    try:
        result = subprocess.run(
            [sys.executable, "-m", "pip", "show", package_name],
            capture_output=True,
            text=True,
            timeout=10
        )
        if result.returncode == 0:
            for line in result.stdout.split('\n'):
                if line.startswith('Version:'):
                    return line.split(':', 1)[1].strip()
        return "NOT FOUND"
    except Exception as e:
        return f"ERROR: {e}"

def test_import(module_name, from_name=None):
    """Test if a module/class can be imported"""
    try:
        if from_name:
            module = importlib.import_module(module_name)
            getattr(module, from_name)
            return "βœ“ OK"
        else:
            importlib.import_module(module_name)
            return "βœ“ OK"
    except ImportError as e:
        return f"βœ— FAIL: {e}"
    except AttributeError as e:
        return f"βœ— FAIL: {e}"
    except Exception as e:
        return f"βœ— ERROR: {e}"

def main():
    print("=" * 80)
    print("GraphWiz Ireland - Package Version & Import Check")
    print("=" * 80)

    # Core packages to check
    packages = [
        'sentence-transformers',
        'transformers',
        'torch',
        'numpy',
        'huggingface-hub',
        'streamlit',
        'hnswlib',
        'networkx',
        'spacy',
        'rank-bm25',
        'groq',
        'pandas',
        'scikit-learn',
        'scipy'
    ]

    print("\nπŸ“¦ Installed Package Versions:")
    print("-" * 80)
    for pkg in packages:
        version = check_package_version(pkg)
        status = "βœ“" if version != "NOT FOUND" and not version.startswith("ERROR") else "βœ—"
        print(f"{status} {pkg:30s} {version}")

    # Check for version conflicts
    print("\nπŸ” Checking for Known Version Conflicts:")
    print("-" * 80)

    hf_hub_version = check_package_version('huggingface-hub')
    transformers_version = check_package_version('transformers')

    print(f"huggingface-hub version: {hf_hub_version}")
    print(f"transformers version: {transformers_version}")

    # Check if huggingface-hub is in valid range for transformers
    try:
        if hf_hub_version != "NOT FOUND":
            hf_major = int(hf_hub_version.split('.')[0])
            hf_minor = int(hf_hub_version.split('.')[1])

            if hf_major == 0 and hf_minor >= 19 and hf_minor < 100:
                print("βœ“ huggingface-hub version is compatible (>=0.19.3, <1.0)")
            else:
                print(f"βœ— WARNING: huggingface-hub {hf_hub_version} may not be compatible!")
                print("  transformers requires: >=0.19.3, <1.0")
    except:
        print("⚠️  Could not parse version numbers")

    # Test critical imports
    print("\nπŸ§ͺ Testing Critical Imports:")
    print("-" * 80)

    imports_to_test = [
        ('streamlit', None),
        ('sentence_transformers', 'SentenceTransformer'),
        ('transformers', None),
        ('huggingface_hub', 'hf_hub_download'),
        ('hnswlib', None),
        ('groq', 'Groq'),
        ('networkx', None),
        ('spacy', None),
    ]

    all_passed = True
    for module, from_name in imports_to_test:
        if from_name:
            test_name = f"from {module} import {from_name}"
        else:
            test_name = f"import {module}"

        result = test_import(module, from_name)
        print(f"{test_name:50s} {result}")
        if "FAIL" in result or "ERROR" in result:
            all_passed = False

    # Test application modules
    print("\nπŸ”§ Testing Application Modules:")
    print("-" * 80)

    sys.path.insert(0, '/app/src')  # Add source directory for HF Spaces

    app_modules = [
        ('groq_llm', 'GroqLLM'),
        ('text_processor', None),
        ('hybrid_retriever', 'HybridRetriever'),
        ('rag_engine', 'IrelandRAGEngine'),
    ]

    for module, from_name in app_modules:
        if from_name:
            test_name = f"from {module} import {from_name}"
        else:
            test_name = f"import {module}"

        result = test_import(module, from_name)
        print(f"{test_name:50s} {result}")
        if "FAIL" in result or "ERROR" in result:
            all_passed = False
            # Print more detailed error for app modules
            print(f"  Detailed error for {module}:")
            try:
                importlib.import_module(module)
            except Exception as e:
                print(f"    {type(e).__name__}: {e}")

    print("\n" + "=" * 80)
    if all_passed:
        print("βœ… All checks passed!")
    else:
        print("❌ Some checks failed - see details above")
    print("=" * 80)

    return 0 if all_passed else 1

if __name__ == "__main__":
    sys.exit(main())