@@ -13,15 +13,24 @@ echo -e "🚀 APIM Samples environment starting...\n"
1313# CONFIGURATION
1414# ------------------------------
1515
16- echo -e " 1/5) Setting environment variables...\n"
16+ echo -e " 1/5) Detecting & setting environment variables...\n"
1717
1818WORKSPACE_ROOT=" /workspaces/Apim-Samples"
1919VENV_PATH=" $WORKSPACE_ROOT /.venv"
2020PYTHON_EXECUTABLE=" $VENV_PATH /bin/python"
2121
22+ # Activate virtual environment to get the correct Python version
23+ source " $VENV_PATH /bin/activate" 2> /dev/null || true
24+ PYTHON_VERSION=$( python --version)
25+
26+ # Extract Azure CLI version (suppress warnings and get just the version number)
27+ AZ_CLI_VERSION=$( az --version 2> /dev/null | grep " azure-cli" | awk ' {print $2}' | head -1)
28+
2229echo " Workspace : $WORKSPACE_ROOT "
2330echo " Virtual Environment : $VENV_PATH "
2431echo " Python Executable : $PYTHON_EXECUTABLE "
32+ echo " Python Version : $PYTHON_VERSION "
33+ echo " Azure CLI Version : $AZ_CLI_VERSION "
2534echo " "
2635
2736# ------------------------------
@@ -37,7 +46,7 @@ if [ -d "$VENV_PATH" ]; then
3746 echo " ✅ Python executable available"
3847 # Activate and verify
3948 source " $VENV_PATH /bin/activate"
40- echo " ✅ Python version: $( python --version ) "
49+ echo " ✅ Python version : $PYTHON_VERSION "
4150 # Commenting out the number of packages installed as this does take some time to run. When the setup was verified, a count of 125 packages was printed.
4251 # echo " ✅ Packages installed: $(pip list | wc -l)"
4352 else
8089
8190echo -e " \n4/5) Configuring Azure CLI...\n"
8291
92+ # We need to have a device code-based login experience within Codespaces. Redirect error output to /dev/null to avoid cluttering the output and ensure
93+ # that the script continues (|| true) even if this command fails.
94+ echo -e " \nSetting Azure CLI login experience to device code...(needed for Codespaces)"
8395az config set core.login_experience_v2=off 2> /dev/null || true
8496
8597# Install extensions used by infrastructure samples
@@ -97,40 +109,35 @@ echo " \n✅ Azure CLI configured"
97109
98110echo -e " \n5/5) Environment Summary\n"
99111echo " Virtual Environment : $VIRTUAL_ENV "
100- echo " Python : $( python --version ) at $( which python) "
112+ echo " Python : $PYTHON_VERSION at $( which python) "
101113# Commenting out the number of packages installed as this does take some time to run. When the setup was verified, a count of 125 packages was printed.
102114# echo " Packages: $(pip list | wc -l) installed"
103- echo " .env File : $( [ -f .env ] && echo " ✅" || echo " ❌" ) "
104- echo " Azure CLI :"
105- echo " $( az --version | head -1) "
115+ echo " .env File exists? : $( [ -f .env ] && echo " ✅" || echo " ❌" ) "
116+ echo " Azure CLI Version : $AZ_CLI_VERSION "
106117
107118# Verify Jupyter kernel registration
108- echo " Jupyter Kernels: $( jupyter kernelspec list --json | python -c " import sys, json; data=json.load(sys.stdin); print(len(data['kernelspecs'])) if 'kernelspecs' in data else print('0')" 2> /dev/null || echo " unknown" ) "
119+ echo " Jupyter Kernels : $( jupyter kernelspec list --json | python -c " import sys, json; data=json.load(sys.stdin); print(len(data['kernelspecs'])) if 'kernelspecs' in data else print('0')" 2> /dev/null || echo " unknown" ) "
120+
109121if jupyter kernelspec list | grep -q " apim-samples" 2> /dev/null; then
110- echo " APIM Samples Kernel: ✅"
122+ echo " APIM Samples Kernel : ✅"
111123else
112- echo " APIM Samples Kernel: ❌ (registering...)"
124+ echo " APIM Samples Kernel : ❌ (registering...)"
113125 python -m ipykernel install --user --name=apim-samples --display-name=" APIM Samples Python 3.12" 2> /dev/null && echo " ✅ Kernel registered successfully" || echo " ⚠️ Failed to register kernel"
114126fi
115127
116128# Test core imports
117129python -c "
118130try:
119131 import requests, jwt, pandas, matplotlib, azure.identity
120- print(' ✅ Core packages working')
132+ print(f ' ✅ Core packages working')
121133except ImportError as e:
122134 print(f' ❌ Package issue: {e}')
123135"
124136
125137# Calculate total duration using Python
126138end=$( date +%s.%N)
127139duration=$( python3 -c " print(f'{float('$end ') - float('$start '):.2f}')" )
128- printf " ⏱️ Total duration in %s seconds\n\n" " $duration "
129140
130141echo " 🎉 Environment ready!"
131- printf " ⏱️ Total setup time: %s seconds\n" " $total_duration "
132- echo " "
133- echo " 💡 The virtual environment is at: $VENV_PATH "
134- echo " 💡 It should be auto-selected in VS Code"
135- echo " 💡 All packages are pre-installed and ready to use"
136- echo " "
142+ printf " ⏱️ Total setup time: %s seconds\n" " $duration "
143+ echo -e " \n💡 The virtual environment is at: $VENV_PATH . All requiredments are already pre-installed and ready to use.\n\n"
0 commit comments