|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Verification script for the APIM Samples dev container setup. |
| 4 | +Run this script to verify that all dependencies are properly installed. |
| 5 | +""" |
| 6 | + |
| 7 | +import sys |
| 8 | +import subprocess |
| 9 | +import importlib.util |
| 10 | + |
| 11 | +# ------------------------------ |
| 12 | +# CONSTANTS |
| 13 | +# ------------------------------ |
| 14 | + |
| 15 | +REQUIRED_PACKAGES = [ |
| 16 | + 'requests', |
| 17 | + 'pandas', |
| 18 | + 'matplotlib', |
| 19 | + 'jwt', |
| 20 | + 'pytest', |
| 21 | + 'azure.storage.blob', |
| 22 | + 'azure.identity', |
| 23 | + 'jupyter', |
| 24 | + 'ipykernel' |
| 25 | +] |
| 26 | + |
| 27 | +REQUIRED_COMMANDS = [ |
| 28 | + 'az', |
| 29 | + 'python', |
| 30 | + 'pip', |
| 31 | + 'jupyter' |
| 32 | +] |
| 33 | + |
| 34 | +# ------------------------------ |
| 35 | +# VERIFICATION FUNCTIONS |
| 36 | +# ------------------------------ |
| 37 | + |
| 38 | +def check_python_packages(): |
| 39 | + """Check if all required Python packages are installed.""" |
| 40 | + print("🐍 Checking Python packages...") |
| 41 | + missing_packages = [] |
| 42 | + |
| 43 | + for package in REQUIRED_PACKAGES: |
| 44 | + if importlib.util.find_spec(package) is None: |
| 45 | + missing_packages.append(package) |
| 46 | + else: |
| 47 | + print(f" ✅ {package}") |
| 48 | + |
| 49 | + if missing_packages: |
| 50 | + print(f" ❌ Missing packages: {', '.join(missing_packages)}") |
| 51 | + return False |
| 52 | + |
| 53 | + return True |
| 54 | + |
| 55 | + |
| 56 | +def check_commands(): |
| 57 | + """Check if required command-line tools are available.""" |
| 58 | + print("\n🔧 Checking command-line tools...") |
| 59 | + missing_commands = [] |
| 60 | + |
| 61 | + for command in REQUIRED_COMMANDS: |
| 62 | + try: |
| 63 | + subprocess.run([command, '--version'], |
| 64 | + capture_output=True, |
| 65 | + check=True, |
| 66 | + timeout=10) |
| 67 | + print(f" ✅ {command}") |
| 68 | + except (subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired): |
| 69 | + missing_commands.append(command) |
| 70 | + print(f" ❌ {command}") |
| 71 | + |
| 72 | + if missing_commands: |
| 73 | + print(f" ❌ Missing commands: {', '.join(missing_commands)}") |
| 74 | + return False |
| 75 | + |
| 76 | + return True |
| 77 | + |
| 78 | + |
| 79 | +def check_jupyter_kernel(): |
| 80 | + """Check if the custom Jupyter kernel is installed.""" |
| 81 | + print("\n📓 Checking Jupyter kernel...") |
| 82 | + try: |
| 83 | + result = subprocess.run(['jupyter', 'kernelspec', 'list'], |
| 84 | + capture_output=True, |
| 85 | + text=True, |
| 86 | + check=True, |
| 87 | + timeout=10) |
| 88 | + |
| 89 | + if 'apim-samples' in result.stdout: |
| 90 | + print(" ✅ APIM Samples kernel found") |
| 91 | + return True |
| 92 | + else: |
| 93 | + print(" ❌ APIM Samples kernel not found") |
| 94 | + return False |
| 95 | + |
| 96 | + except (subprocess.CalledProcessError, subprocess.TimeoutExpired): |
| 97 | + print(" ❌ Failed to check Jupyter kernels") |
| 98 | + return False |
| 99 | + |
| 100 | + |
| 101 | +def check_azure_cli(): |
| 102 | + """Check Azure CLI installation and extensions.""" |
| 103 | + print("\n☁️ Checking Azure CLI...") |
| 104 | + try: |
| 105 | + # Check Azure CLI |
| 106 | + result = subprocess.run(['az', '--version'], |
| 107 | + capture_output=True, |
| 108 | + text=True, |
| 109 | + check=True, |
| 110 | + timeout=10) |
| 111 | + |
| 112 | + print(" ✅ Azure CLI installed") |
| 113 | + |
| 114 | + # Check for useful extensions |
| 115 | + extensions = ['containerapp', 'front-door'] |
| 116 | + for ext in extensions: |
| 117 | + if ext in result.stdout: |
| 118 | + print(f" ✅ Extension {ext} installed") |
| 119 | + else: |
| 120 | + print(f" ⚠️ Extension {ext} not found (optional)") |
| 121 | + |
| 122 | + return True |
| 123 | + |
| 124 | + except (subprocess.CalledProcessError, subprocess.TimeoutExpired): |
| 125 | + print(" ❌ Azure CLI not working properly") |
| 126 | + return False |
| 127 | + |
| 128 | + |
| 129 | +def main(): |
| 130 | + """Main verification function.""" |
| 131 | + print("🔍 Verifying APIM Samples dev container setup...\n") |
| 132 | + |
| 133 | + checks = [ |
| 134 | + check_python_packages(), |
| 135 | + check_commands(), |
| 136 | + check_jupyter_kernel(), |
| 137 | + check_azure_cli() |
| 138 | + ] |
| 139 | + |
| 140 | + print("\n" + "="*50) |
| 141 | + |
| 142 | + if all(checks): |
| 143 | + print("🎉 All checks passed! Your dev container is ready to use.") |
| 144 | + print("\n📋 Next steps:") |
| 145 | + print("1. Sign in to Azure: az login") |
| 146 | + print("2. Execute shared/jupyter/verify-az-account.ipynb") |
| 147 | + print("3. Explore the samples and infrastructure folders") |
| 148 | + return 0 |
| 149 | + else: |
| 150 | + print("❌ Some checks failed. Please review the output above.") |
| 151 | + print("\n🔧 Try these troubleshooting steps:") |
| 152 | + print("1. Rebuild the container: Dev Containers: Rebuild Container") |
| 153 | + print("2. Manually run: pip install -r requirements.txt") |
| 154 | + print("3. Check the .devcontainer/README.md for more help") |
| 155 | + return 1 |
| 156 | + |
| 157 | + |
| 158 | +# ------------------------------ |
| 159 | +# MAIN EXECUTION |
| 160 | +# ------------------------------ |
| 161 | + |
| 162 | +if __name__ == "__main__": |
| 163 | + sys.exit(main()) |
0 commit comments