Create installation.py
Browse files- utils/installation.py +144 -0
utils/installation.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Installation helper utilities for ARF Demo
|
| 3 |
+
"""
|
| 4 |
+
import subprocess
|
| 5 |
+
import sys
|
| 6 |
+
import logging
|
| 7 |
+
from typing import Dict, Any, List, Optional
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class InstallationHelper:
|
| 13 |
+
"""Helper class for ARF package installation"""
|
| 14 |
+
|
| 15 |
+
@staticmethod
|
| 16 |
+
def install_arf_oss() -> Dict[str, Any]:
|
| 17 |
+
"""Install ARF OSS package"""
|
| 18 |
+
try:
|
| 19 |
+
logger.info("Installing ARF OSS v3.3.7...")
|
| 20 |
+
result = subprocess.run(
|
| 21 |
+
[sys.executable, "-m", "pip", "install", "agentic-reliability-framework==3.3.7"],
|
| 22 |
+
capture_output=True,
|
| 23 |
+
text=True,
|
| 24 |
+
check=True
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
return {
|
| 28 |
+
"success": True,
|
| 29 |
+
"message": "β
ARF OSS v3.3.7 installed successfully",
|
| 30 |
+
"output": result.stdout
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
except subprocess.CalledProcessError as e:
|
| 34 |
+
return {
|
| 35 |
+
"success": False,
|
| 36 |
+
"message": "β Failed to install ARF OSS",
|
| 37 |
+
"error": e.stderr
|
| 38 |
+
}
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return {
|
| 41 |
+
"success": False,
|
| 42 |
+
"message": f"β Installation error: {str(e)}",
|
| 43 |
+
"error": str(e)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
@staticmethod
|
| 47 |
+
def check_installation() -> Dict[str, Any]:
|
| 48 |
+
"""Check ARF package installation"""
|
| 49 |
+
try:
|
| 50 |
+
import agentic_reliability_framework as arf_oss
|
| 51 |
+
oss_version = getattr(arf_oss, '__version__', 'unknown')
|
| 52 |
+
oss_installed = True
|
| 53 |
+
except ImportError:
|
| 54 |
+
oss_installed = False
|
| 55 |
+
oss_version = None
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
import arf_enterprise
|
| 59 |
+
enterprise_version = getattr(arf_enterprise, '__version__', 'unknown')
|
| 60 |
+
enterprise_installed = True
|
| 61 |
+
except ImportError:
|
| 62 |
+
enterprise_installed = False
|
| 63 |
+
enterprise_version = None
|
| 64 |
+
|
| 65 |
+
return {
|
| 66 |
+
"oss_installed": oss_installed,
|
| 67 |
+
"oss_version": oss_version,
|
| 68 |
+
"enterprise_installed": enterprise_installed,
|
| 69 |
+
"enterprise_version": enterprise_version,
|
| 70 |
+
"recommendations": InstallationHelper.get_recommendations(oss_installed, enterprise_installed)
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
@staticmethod
|
| 74 |
+
def get_recommendations(oss_installed: bool, enterprise_installed: bool) -> List[str]:
|
| 75 |
+
"""Get installation recommendations"""
|
| 76 |
+
recommendations = []
|
| 77 |
+
|
| 78 |
+
if not oss_installed:
|
| 79 |
+
recommendations.append(
|
| 80 |
+
"Install ARF OSS: `pip install agentic-reliability-framework==3.3.7`"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
if not enterprise_installed:
|
| 84 |
+
recommendations.append(
|
| 85 |
+
"Install ARF Enterprise: `pip install agentic-reliability-enterprise` (requires license)"
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return recommendations
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def get_installation_html() -> str:
|
| 92 |
+
"""Get HTML for installation status display"""
|
| 93 |
+
status = InstallationHelper.check_installation()
|
| 94 |
+
|
| 95 |
+
if status["oss_installed"]:
|
| 96 |
+
oss_html = f"""
|
| 97 |
+
<div style="padding: 10px; background: #10b981; color: white; border-radius: 8px; margin: 5px 0;">
|
| 98 |
+
β
ARF OSS v{status['oss_version']} installed
|
| 99 |
+
</div>
|
| 100 |
+
"""
|
| 101 |
+
else:
|
| 102 |
+
oss_html = """
|
| 103 |
+
<div style="padding: 10px; background: #f59e0b; color: white; border-radius: 8px; margin: 5px 0;">
|
| 104 |
+
β οΈ ARF OSS not installed
|
| 105 |
+
</div>
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
if status["enterprise_installed"]:
|
| 109 |
+
enterprise_html = f"""
|
| 110 |
+
<div style="padding: 10px; background: #8b5cf6; color: white; border-radius: 8px; margin: 5px 0;">
|
| 111 |
+
π ARF Enterprise v{status['enterprise_version']} installed
|
| 112 |
+
</div>
|
| 113 |
+
"""
|
| 114 |
+
else:
|
| 115 |
+
enterprise_html = """
|
| 116 |
+
<div style="padding: 10px; background: #64748b; color: white; border-radius: 8px; margin: 5px 0;">
|
| 117 |
+
π ARF Enterprise not installed
|
| 118 |
+
</div>
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
recommendations_html = ""
|
| 122 |
+
if status["recommendations"]:
|
| 123 |
+
rec_list = "\n".join([f"<li>{rec}</li>" for rec in status["recommendations"]])
|
| 124 |
+
recommendations_html = f"""
|
| 125 |
+
<div style="margin-top: 15px; padding: 10px; background: #f1f5f9; border-radius: 8px;">
|
| 126 |
+
<strong>π‘ Recommendations:</strong>
|
| 127 |
+
<ul style="margin: 5px 0 0 0; padding-left: 20px;">
|
| 128 |
+
{rec_list}
|
| 129 |
+
</ul>
|
| 130 |
+
</div>
|
| 131 |
+
"""
|
| 132 |
+
|
| 133 |
+
return f"""
|
| 134 |
+
<div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 15px; background: white;">
|
| 135 |
+
<h4 style="margin: 0 0 10px 0; color: #1e293b;">π¦ ARF Installation Status</h4>
|
| 136 |
+
{oss_html}
|
| 137 |
+
{enterprise_html}
|
| 138 |
+
{recommendations_html}
|
| 139 |
+
</div>
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# Export singleton
|
| 144 |
+
installation_helper = InstallationHelper()
|