Skip to content

Commit

Permalink
devonfw#797: Azure CLI Python Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Sep 9, 2022
1 parent 53edc79 commit e924a71
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 59 deletions.
21 changes: 1 addition & 20 deletions scripts/src/main/resources/scripts/command/az
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ source "$(dirname "${0}")"/../functions
function doSetup() {
if [ "${1}" != "silent" ] || [[ ! $(command -v az) =~ ${DEVON_IDE_HOME}/software/ ]]
then
doDevonCommand pip install azure-cli
doDevonCommand pip install azure-cli az
setConfig
setPth
doRunCommand "pip uninstall pywin32"
doRunCommand "pip install pywin32"
fi
if [ "${1}" != "silent" ] && ! doIsQuiet
then
Expand All @@ -39,22 +36,6 @@ function setConfig() {
fi
}

function setPth() {
local az_dir="${DEVON_IDE_HOME}/software/az"
local pth="${DEVON_IDE_HOME}/software/python/Lib/site-packages/software.pth"
if ! grep -q "${az_dir}" "${pth}"
then
if doIsWindows
then
local winPath
winPath=$(cygpath -m "${az_dir}")
echo -e "\n${winPath}" >> "${pth}"
else
echo -e "\n${az_dir}" >> "${pth}"
fi
fi
}

function doRun() {
doSetup silent
doEcho "Running: az ${*}"
Expand Down
70 changes: 33 additions & 37 deletions scripts/src/main/resources/scripts/command/pip
Original file line number Diff line number Diff line change
Expand Up @@ -52,58 +52,54 @@ function doSetup() {
}

function doPipInstall() {
local package="${1}"
local package_folder="${2}"
if [ -z "${package_folder}" ]
then
package_folder="${package}"
fi
local package_path="${DEVON_IDE_HOME}/software/${package_folder}"
# If pywin32 is not installed in the python Lib directory, install it. (e.g. required for azure cli to work)
if doIsWindows && [ ! -d "${PYTHON_HOME}/lib/site-packages/win32" ]
then
doRunPip "install pypiwin32"
fi
while [ -n "${1}" ]
do
local package="${1}"
shift
local package_path="${DEVON_IDE_HOME}/software/${package}"
if [ ! -d "${package_path}" ]
then
mkdir -p "${package_path}"
fi
# Install package with pip
doRunPip "install ${package}" "--target=${package_path}"
# Write a new line to the modules.pth if the line doesn't exist
if ! grep -q "../${package}" "${PYTHON_HOME}/modules.pth"
then
echo -e "../${package}\n" >> "${PYTHON_HOME}/modules.pth"
fi
doExtendPath "${package_path}"
done
if [ ! -d "${package_path}" ]
then
mkdir -p "${package_path}"
fi
# Install package with pip
doRunPip "install ${package}" "--target=${package_path}"
# Write a new line to the modules.pth if the line doesn't exist
if ! grep -q "../${package_folder}" "${PYTHON_HOME}/modules.pth"
then
echo -e "../${package_folder}\n" >> "${PYTHON_HOME}/modules.pth"
fi
doExtendPath "${package_path}"
}

function doPipRemove() {
if [ -z "${1}" ]
local package="${1}"
local package_folder="${2}"
if [ -z "${package}" ]
then
doAskToContinue "Do you want to remove pip?"
rm -rf "${PIP_HOME}"
doEcho "Pip removed."
return
fi

# Remove pip packages given as arguments
while [ -n "${1}" ]
do
local package="${1}"
shift
doRunPip "uninstall ${package}"
if [ -d "${DEVON_IDE_HOME}/software/${package}" ]
then
# If not silent
if [ "${1}" != "silent" ]
then
doEcho "Removing ${package}..."
fi

rm -rf "${DEVON_IDE_HOME}/software/${package}"
fi
doEcho "Package ${package} removed."
done
if [ -z "${package_folder}" ]
then
package_folder="${package}"
fi
local package_path="${DEVON_IDE_HOME}/software/${package_folder}"
doRunPip "uninstall ${package}"
if [ -d "${package_path}" ]
then
rm -rf "${package_path}"
fi
doEcho "Package ${package} removed."
}

function doRunPip() {
Expand Down
3 changes: 1 addition & 2 deletions scripts/src/main/resources/scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ function doDevonCommand() {
else
exit ${result}
fi
elif [ "${2}" = "setup" ]
then
else
doUpdatePath
fi
}
Expand Down

0 comments on commit e924a71

Please sign in to comment.