Skip to content

Commit 1727175

Browse files
authored
devonfw#797: Azure CLI Python Integration (devonfw#873)
1 parent d47d9e6 commit 1727175

File tree

4 files changed

+59
-125
lines changed

4 files changed

+59
-125
lines changed

documentation/az.asciidoc

+7-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ toc::[]
33

44
= Azure CLI
55

6-
The Azure CLI commandlet allows to install and use https://github.com/Azure/azure-cli[Azure CLI]. Currently, the command works only for Windows.
6+
The Azure CLI commandlet allows to install and use https://github.com/Azure/azure-cli[Azure CLI].
7+
Call `devon az «args»` is more or less the same as calling `az «args»` but with some advanced features and ensuring that Azure CLI is properly set up for your project.
78

89
*ATTENTION:*
910
Currently this feature is new and therefore experimental.
@@ -16,30 +17,12 @@ The arguments (`devon az «args»`) are explained by the following table:
1617
.Usage of `devon az`
1718
[options="header"]
1819
|=======================
19-
|*Argument(s)* |*Meaning*
20-
|`setup` |setup Azure CLI (install and verify) as per above flow.
21-
|`«args»` |call Azure CLI with the specified arguments. Call `az help` for details or use `az` directly as preferred." (`«args»`)
20+
|*Argument(s)*|*Meaning*
21+
|`setup` |setup Azure CLI (install and verify) as per above flow.
22+
|`«args»` |call Azure CLI with the specified arguments. Call `az help` for details or use `az` directly as preferred." (`«args»`)
2223
|=======================
2324

24-
== Setup
25-
The `az` commandlet will install Azure CLI automatically. Windows user must confirm the User Access Control to run the installation as administrator.
26-
Please note that besides the sandbox concept of devonfw-ide this is a global installation on your system.
27-
When uninstalling Azure CLI, you may have to manually uninstall.
28-
29-
**Uninstall process instructions:**
30-
31-
- https://docs.microsoft.com/de-de/cli/azure/install-azure-cli-windows?tabs=azure-cli#uninstall[Windows]
32-
33-
== Requirements
34-
**Windows users requires the following software:**
35-
36-
- https://docs.microsoft.com/en-us/powershell//[Powershell]
37-
3825
== Configuration File
39-
The configuration file is located at `conf/.azure`. Don't forget to set the environment variables of your IDE with `devon` before setting new configurations for Azure.
40-
41-
== Usage
42-
After the installation is complete, you may need to restart the console. Run `az help` from any shell of your OS directly to get started and use the online documentations and resources on the web to get familiar with Azure CLI. It is not our intention to repeat this here.
43-
44-
Please note that the `az` commandlet is a link:cli.asciidoc#command-wrapper[command wrapper].
26+
The configuration file is located at `conf/.azure`.
27+
Don't forget to set the environment variables of your IDE with `devon` before setting new configurations for Azure.
4528

scripts/src/main/resources/scripts/command/az

+18-62
Original file line numberDiff line numberDiff line change
@@ -10,88 +10,44 @@ then
1010
exit
1111
fi
1212

13-
if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi
1413
# shellcheck source=scripts/functions
1514
source "$(dirname "${0}")"/../functions
1615

1716
function doSetup() {
18-
if command -v az &> /dev/null
17+
if [ "${1}" != "silent" ] || [[ ! $(command -v az) =~ ${DEVON_IDE_HOME}/software/ ]]
1918
then
20-
if [ "${1}" != "silent" ] && ! doIsQuiet
21-
then
22-
doEcho "Azure CLI is already installed at $(command -v az)"
23-
fi
24-
else
25-
doRequireNotBatch
26-
if doIsWindows
27-
then
28-
# Get leatest release
29-
if [ -z "${AZ_VERSION}" ]
30-
then
31-
doEcho "Getting latest release..."
32-
AZ_VERSION=$(curl -s https://api.github.com/repos/Azure/azure-cli/releases/latest | awk -F ":" '/tag_name/ {print $2}'| awk -F "\"" '{print $2}' | awk -F "-" '{print $3}')
33-
fi
34-
35-
doInstall "-" "${AZ_HOME}" "az" "${AZ_VERSION}"
36-
if [ "${?}" = 0 ]
37-
then
38-
doPackageInstall "${AZ_HOME}"
39-
fi
40-
fi
19+
doDevonCommand pip install azure-cli az
20+
setConfig
4121
fi
42-
}
43-
44-
function doPackageInstall() {
45-
local path_to_package="${1}"
46-
if doIsWindows
47-
then
48-
local winPath
49-
winPath=$(cygpath -w "${path_to_package}")
50-
powershell.exe -Command "Start-Process msiexec.exe -verb runas -Wait -ArgumentList '/I ${winPath}\az-${AZ_VERSION}-windows.msi /QB-!'" &> /dev/null
51-
if [ "${?}" = 0 ]
52-
then
53-
setConfigDir
54-
doSuccess "Azure CLI ist installed now. Great! \nTo get started you may need to restart your current shell."
55-
else
56-
doError "The setup was canceled or failed. Rerun the setup to install Azure CLI."
57-
fi
58-
else
59-
doFail "Sorry, Azure CLI installation support is not yet implemented for your OS. Please install manually or help devonfw-ide to support it for your OS by contributing a pull-request."
22+
if [ "${1}" != "silent" ] && ! doIsQuiet
23+
then
24+
doRunCommand "az -v" "verify installation of azure cli"
6025
fi
61-
doRunCommand "rm -rf ${path_to_package}"
6226
}
63-
64-
# Set directory for azure cli configuration file
65-
function setConfigDir() {
66-
azureconf_dir="${DEVON_IDE_HOME}/conf/.azure"
67-
azurecli_export="export AZURE_CONFIG_DIR=${azureconf_dir}"
68-
if ! grep -q "${azurecli_export}" "${DEVON_IDE_HOME}/conf/devon.properties"
69-
then
70-
doRunCommand "${azurecli_export}"
71-
echo -e "\n${azurecli_export}" >> "${DEVON_IDE_HOME}/conf/devon.properties"
72-
doEcho "Location of Azure's configuration file is set to ${azureconf_dir}"
27+
28+
function setConfig() {
29+
local az_config_dir="${DEVON_IDE_HOME}/conf/.azure"
30+
local az_config_export="export AZURE_CONFIG_DIR=${az_config_dir}"
31+
if ! grep -q "${az_config_export}" "${DEVON_IDE_HOME}/conf/devon.properties"
32+
then
33+
doRunCommand "${az_config_export}"
34+
echo -e "\n${az_config_export}" >> "${DEVON_IDE_HOME}/conf/devon.properties"
35+
doEcho "Location of Azure's configuration file is set to ${az_config_dir}"
7336
fi
7437
}
7538

7639
function doRun() {
7740
doSetup silent
78-
if command -v az &> /dev/null
79-
then
80-
doEcho "Running: Azure CLI ${*}"
81-
setConfigDir
82-
az "${@}"
83-
fi
41+
doEcho "Running: az ${*}"
42+
az "${@}"
8443
}
8544

86-
AZ_HOME="${DEVON_IDE_HOME}/updates/install/az"
87-
88-
# CLI
8945
case ${1} in
9046
"help" | "-h")
9147
echo "Install Azure CLI."
9248
echo
9349
echo "Arguments:"
94-
echo " setup install Azure CLI on your machine (global installation)."
50+
echo " setup install Azure CLI on your machine."
9551
echo " <<args>> call Azure CLI with the specified arguments. Call az --help for details or use Azure CLI directly as preferred."
9652
echo
9753
;;

scripts/src/main/resources/scripts/command/pip

+33-37
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,54 @@ function doSetup() {
5252
}
5353

5454
function doPipInstall() {
55+
local package="${1}"
56+
local package_folder="${2}"
57+
if [ -z "${package_folder}" ]
58+
then
59+
package_folder="${package}"
60+
fi
61+
local package_path="${DEVON_IDE_HOME}/software/${package_folder}"
5562
# If pywin32 is not installed in the python Lib directory, install it. (e.g. required for azure cli to work)
5663
if doIsWindows && [ ! -d "${PYTHON_HOME}/lib/site-packages/win32" ]
5764
then
5865
doRunPip "install pypiwin32"
5966
fi
60-
while [ -n "${1}" ]
61-
do
62-
local package="${1}"
63-
shift
64-
local package_path="${DEVON_IDE_HOME}/software/${package}"
65-
if [ ! -d "${package_path}" ]
66-
then
67-
mkdir -p "${package_path}"
68-
fi
69-
# Install package with pip
70-
doRunPip "install ${package}" "--target=${package_path}"
71-
# Write a new line to the modules.pth if the line doesn't exist
72-
if ! grep -q "../${package}" "${PYTHON_HOME}/modules.pth"
73-
then
74-
echo -e "../${package}\n" >> "${PYTHON_HOME}/modules.pth"
75-
fi
76-
doExtendPath "${package_path}"
77-
done
67+
if [ ! -d "${package_path}" ]
68+
then
69+
mkdir -p "${package_path}"
70+
fi
71+
# Install package with pip
72+
doRunPip "install ${package}" "--target=${package_path}"
73+
# Write a new line to the modules.pth if the line doesn't exist
74+
if ! grep -q "../${package_folder}" "${PYTHON_HOME}/modules.pth"
75+
then
76+
echo -e "../${package_folder}\n" >> "${PYTHON_HOME}/modules.pth"
77+
fi
78+
doExtendPath "${package_path}"
7879
}
7980

8081
function doPipRemove() {
81-
if [ -z "${1}" ]
82+
local package="${1}"
83+
local package_folder="${2}"
84+
if [ -z "${package}" ]
8285
then
8386
doAskToContinue "Do you want to remove pip?"
8487
rm -rf "${PIP_HOME}"
8588
doEcho "Pip removed."
8689
return
8790
fi
88-
8991
# Remove pip packages given as arguments
90-
while [ -n "${1}" ]
91-
do
92-
local package="${1}"
93-
shift
94-
doRunPip "uninstall ${package}"
95-
if [ -d "${DEVON_IDE_HOME}/software/${package}" ]
96-
then
97-
# If not silent
98-
if [ "${1}" != "silent" ]
99-
then
100-
doEcho "Removing ${package}..."
101-
fi
102-
103-
rm -rf "${DEVON_IDE_HOME}/software/${package}"
104-
fi
105-
doEcho "Package ${package} removed."
106-
done
92+
if [ -z "${package_folder}" ]
93+
then
94+
package_folder="${package}"
95+
fi
96+
local package_path="${DEVON_IDE_HOME}/software/${package_folder}"
97+
doRunPip "uninstall ${package}"
98+
if [ -d "${package_path}" ]
99+
then
100+
rm -rf "${package_path}"
101+
fi
102+
doEcho "Package ${package} removed."
107103
}
108104

109105
function doRunPip() {

scripts/src/main/resources/scripts/functions

+1-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ function doDevonCommand() {
329329
else
330330
exit ${result}
331331
fi
332-
elif [ "${2}" = "setup" ]
333-
then
332+
else
334333
doUpdatePath
335334
fi
336335
}

0 commit comments

Comments
 (0)