graphwiz-ireland / check_versions.py
hirthickraj2015's picture
Fix dependency version conflict + add version checker
ec7f58f
raw
history blame
5 kB
#!/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())