22
33# This script will eventually be replaced with `databricks labs install ucx` command.
44
5- # Initialize an empty array to store Python 3 binary paths
6- python3_binaries =()
5+ # Initialize an empty array to store Python binary paths
6+ python_binaries =()
77
88# Split the $PATH variable into an array using ':' as the delimiter
99IFS=' :' read -ra path_dirs <<< " $PATH"
1010
1111# Iterate over each directory in the $PATH
1212for dir in " ${path_dirs[@]} " ; do
13- # Construct the full path to the python3 binary in the current directory
13+ # Construct the full path to the python binaries in the current directory
14+ python2_path=" ${dir} /python"
1415 python3_path=" ${dir} /python3"
1516
16- # Check if the python3 binary exists and is executable
17+ # Check if the python binary exists and is executable
1718 if [ -x " $python3_path " ]; then
18- python3_binaries+=(" $python3_path " )
19+ python_binaries+=(" $python3_path " )
20+ elif [ -x " $python2_path " ]; then
21+ python_binaries+=(" $python2_path " )
1922 fi
2023done
2124
22- if [ -z " ${python3_binaries [*]} " ]; then
25+ if [ -z " ${python_binaries [*]} " ]; then
2326 echo " [!] No Python binaries detected"
2427 exit 1
2528fi
2629
2730# Check versions for all Python binaries found
2831python_versions=()
29- for python_binary in " ${python3_binaries[@]} " ; do
30- python_version=$( " $python_binary " --version | awk ' {print $2}' )
31- python_versions+=(" $python_version -> $( realpath " $python_binary " ) " )
32+ for python_binary in " ${python_binaries[@]} " ; do
33+ python_version=$( " $python_binary " --version)
34+ IFS=" " read -ra parts <<< " $python_version"
35+ if [ " ${# parts[@]} " -eq " 2" ]; then
36+ python_versions+=(" ${parts[1]} -> $( realpath " $python_binary " ) " )
37+ else
38+ echo " [!] Found bad version string, skipping binary"
39+ fi
3240done
3341
3442IFS=$' \n ' python_versions=($( printf " %s\n" " ${python_versions[@]} " | sort -V) )
@@ -37,7 +45,7 @@ py="/dev/null"
3745for version_and_binary in " ${python_versions[@]} " ; do
3846 echo " [i] found Python $version_and_binary "
3947 IFS=" -> " read -ra parts <<< " $version_and_binary"
40- py=" ${parts[2] } "
48+ IFS= " " py=" ${parts[@] : 2 } "
4149done
4250
4351echo " [i] latest python is $py "
@@ -46,12 +54,20 @@ tmp_dir=$(mktemp -d)
4654
4755# Create isolated Virtualenv with the latest Python version
4856# in the ephemeral temporary directory
57+ echo " [i] installing venv into: $tmp_dir "
4958$py -m venv " $tmp_dir "
5059
51- . " $tmp_dir /bin/activate"
52-
53- # Use the Python from Virtualenv
54- py=" $tmp_dir /bin/python"
60+ # Detect which venv this is, activate and reset Python binary
61+ if [ -f " $tmp_dir /bin/activate" ]; then
62+ . " $tmp_dir /bin/activate"
63+ py=" $tmp_dir /bin/python"
64+ elif [ -f " $tmp_dir /Scripts/activate" ]; then
65+ . " $tmp_dir /Scripts/activate"
66+ py=" $tmp_dir /Scripts/python"
67+ else
68+ echo " [!] Creating Python virtual environment failed"
69+ exit 1
70+ fi
5571
5672echo " [+] making sure we have the latest pip version"
5773# Always upgrade pip, so that the hatchling build backend works. Hinted by errors like
@@ -68,4 +84,4 @@ $py -m pip install --quiet -e .
6884# without console_scripts entrypoint
6985$py -m databricks.labs.ucx.install
7086
71- rm -r " $tmp_dir "
87+ rm -r " $tmp_dir "
0 commit comments