Skip to content

Instantly share code, notes, and snippets.

@breiter
Created October 10, 2024 10:16
Show Gist options
  • Save breiter/88f1ce78bf424c256558c2709e272ba5 to your computer and use it in GitHub Desktop.
Save breiter/88f1ce78bf424c256558c2709e272ba5 to your computer and use it in GitHub Desktop.
Azure CLI install script is broken on macOS

With MacPorts on macOS 15, install python312. Install py-pip. Install py-virtualenv.

sudo port select --set pip3 pip312   
sudo port select --set python3 python312 
sudo port select --set python python312 
sudo port select --set virtualenv virtualenv312
curl -L -O https://aka.ms/InstallAzureCli 

Edit the InstallAzureCli script to remove the last part of the script that runs the python script the bash script downloads.

# python_cmd=python3
# if ! command -v python3 >/dev/null 2>&1
# then
#   if command -v python >/dev/null 2>&1
#   then
#     python_cmd=python
#   else
#     echo "ERROR: python3 or python not found."
#     echo "If python is available on the system, add it to PATH."
#     exit 1
#   fi
# fi
#
# chmod 775 $install_script
# echo "Running install script."
# $python_cmd $install_script < $_TTY

Edit install.py to change the create_virtualenv(temp_dir, install_dir) function to use the system virtualenv.

def create_virtualenv(tmp_dir, install_dir):
    # download_location = os.path.join(tmp_dir, VIRTUALENV_ARCHIVE)
    # print_status('Downloading virtualenv package from {}.'.format(VIRTUALENV_DOWNLOAD_URL))
    # response = urlopen(VIRTUALENV_DOWNLOAD_URL)
    # with open(download_location, 'wb') as f: f.write(response.read())
    # print_status("Downloaded virtualenv package to {}.".format(download_location))
    # if is_valid_sha256sum(download_location, VIRTUALENV_ARCHIVE_SHA256):
    #     print_status("Checksum of {} OK.".format(download_location))
    # else:
    #     raise CLIInstallError("The checksum of the downloaded virtualenv package does not match.")
    # print_status("Extracting '{}' to '{}'.".format(download_location, tmp_dir))
    # package_tar = tarfile.open(download_location)
    # package_tar.extractall(path=tmp_dir)
    # package_tar.close()
    # virtualenv_dir_name = 'virtualenv-'+VIRTUALENV_VERSION
    # working_dir = os.path.join(tmp_dir, virtualenv_dir_name)
    # cmd = [sys.executable, 'virtualenv.py', '--python', sys.executable, install_dir]
    # exec_command(cmd, cwd=working_dir)
    cmd = ["virtualenv", "--python", sys.executable, install_dir]
    exec_command(cmd)

Now the script will work:

python3 ./install.py

If you are using zsh and you want completions you need to turn on bashcompint.

autoload -Uz bashcompinit
bashcompinit #bash completion support (required for az)

#enable command-line completion for az cli
if [ -f "$HOME"/lib/azure-cli/az.completion ]; then
  #requires bash autocompletion: bashcompinit
   . "$HOME"/lib/azure-cli/az.completion
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment