Fixed python3 lib install for DEB & RPM

Upgraded python3-yaml into a dependency; needed for cli
	Added checks before uninstalling amdsmi system
	Made argcomplete activation only for installing user
	Corrected returns outside of function to exit
	Removed returns if python3 library install fails

Signed-off-by: Maisam Arif <maisarif@amd.com>
Change-Id: I299dc01e07029b255a3469fd63fdc8ffec943828
This commit is contained in:
Maisam Arif
2023-11-05 01:22:20 -06:00
والد 18d6484c67
کامیت e0a1a6ca96
8فایلهای تغییر یافته به همراه150 افزوده شده و 34 حذف شده
+3 -3
مشاهده پرونده
@@ -245,12 +245,12 @@ install(
#Debian package specific variables
set(CPACK_DEBIAN_PACKAGE_PROVIDES "amd-smi")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "sudo, libdrm-dev, python3-yaml, python3-argcomplete")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "sudo, python3-argcomplete, libdrm-dev")
set(CPACK_DEBIAN_ASAN_PACKAGE_RECOMMENDS ${CPACK_DEBIAN_PACKAGE_RECOMMENDS})
set(CPACK_DEBIAN_DEV_PACKAGE_RECOMMENDS ${CPACK_DEBIAN_PACKAGE_RECOMMENDS})
set(CPACK_DEBIAN_ASAN_PACKAGE_PROVIDES "${AMD_SMI_PACKAGE}-asan")
set(CPACK_DEBIAN_DEV_PACKAGE_PROVIDES "${AMD_SMI_PACKAGE}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python3 (>= 3.6.8), python3-pip")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python3 (>= 3.6.8), python3-pip, python3-yaml")
set(CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS})
set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS})
@@ -273,7 +273,7 @@ set(CPACK_RPM_PACKAGE_SUGGESTS "python3-argcomplete")
set(CPACK_RPM_DEV_PACKAGE_SUGGESTS ${CPACK_RPM_PACKAGE_SUGGESTS})
set(CPACK_RPM_ASAN_PACKAGE_SUGGESTS ${CPACK_RPM_PACKAGE_SUGGESTS})
# python version gated by rhel8 :(
set(CPACK_RPM_PACKAGE_REQUIRES "python3 >= 3.6.8, python3-pip")
set(CPACK_RPM_PACKAGE_REQUIRES "python3 >= 3.6.8, python3-pip, python3-yaml")
set(CPACK_RPM_DEV_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES})
set(CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES})
+30 -7
مشاهده پرونده
@@ -105,6 +105,7 @@ do_ldconfig() {
}
do_install_amdsmi_python_lib() {
echo "Installing AMD-SMI python library (amdsmi)..."
# get python version
local python3_minor_version
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
@@ -122,23 +123,45 @@ do_install_amdsmi_python_lib() {
return
fi
local PREVIOUS_PIP_ROOT_ACTION="$PIP_ROOT_USER_ACTION"
export PIP_ROOT_USER_ACTION=ignore
# Remove old python library
python3 -m pip uninstall amdsmi --yes --quiet
local pip_list_output
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for amdsmi
if [[ $pip_list_output == *"amdsmi"* ]]; then
echo "Detected old AMD-SMI python library (amdsmi)..."
python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check
echo "Removed old AMD-SMI python library (amdsmi)..."
fi
# install python library at @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi
local python_lib_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@
python3 -m pip install "$python_lib_path"
python3 -m pip show argcomplete
if [ $? -ne 1 ]; then
activate-global-python-argcomplete
python3 -m pip install "$python_lib_path" --quiet --disable-pip-version-check
unset PIP_ROOT_USER_ACTION
export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_ACTION"
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for argcomplete
if [[ $pip_list_output == *"argcomplete"* ]]; then
activate-global-python-argcomplete3
# Newer versions of argcomplete do not have the 3 at the end
if [ $? -ne 0 ]; then
echo "[WARNING] Could not find activate-global-python-argcomplete3. "\
"Trying newer activate-global-python-argcomplete..."
activate-global-python-argcomplete
fi
fi
echo "Installed AMD-SMI python library (amdsmi)..."
}
case "$1" in
( configure )
do_install_amdsmi_python_lib || return 0
do_install_amdsmi_python_lib
do_ldconfig
do_configureLogrotate || return 0
do_configureLogrotate || exit 0
;;
( abort-upgrade | abort-remove | abort-deconfigure )
echo "$1"
+34 -7
مشاهده پرونده
@@ -8,10 +8,17 @@ rm_ldconfig() {
fi
}
rm_pyc() {
rm_leftovers() {
# remove pyc files generated by python
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/__pycache__
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi/__pycache__
# remove leftover doc files
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/../doc/amd_smi*
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/
# remove leftover libs
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libamd_smi.so*
}
rm_logFolder() {
@@ -34,6 +41,7 @@ return_logrotateToOrigConfig() {
}
rm_python_lib() {
echo "Removing AMD-SMI python library (amdsmi)..."
# get python version
local python3_minor_version
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
@@ -50,22 +58,41 @@ rm_python_lib() {
return
fi
python3 -m pip uninstall amdsmi --yes
python3 -m pip show amdsmi
if [ $? -ne 1 ]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed. "\
# Remove old python library
local pip_list_output
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for amdsmi
if [[ $pip_list_output == *"amdsmi"* ]]; then
local PREVIOUS_PIP_ROOT_ACTION="$PIP_ROOT_USER_ACTION"
export PIP_ROOT_USER_ACTION=ignore
echo "Detected AMD-SMI python library (amdsmi)..."
python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check
echo "Removed AMD-SMI python library (amdsmi)..."
unset PIP_ROOT_USER_ACTION
export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_ACTION"
fi
local pip_list_output
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for amdsmi
if [[ $pip_list_output == *"amdsmi"* ]]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed in pip. "\
"Check post install to ensure version is correct"
return
fi
echo "Removed AMD-SMI python library (amdsmi)..."
}
case "$1" in
( remove | upgrade)
# remove old gpuv-smi symlink
rm -f @CPACK_PACKAGING_INSTALL_PREFIX@/bin/gpuv-smi &> /dev/null
rm_python_lib || return 0
rm_python_lib
rm_ldconfig
rm_pyc
rm_leftovers
rm_logFolder
return_logrotateToOrigConfig
;;
+1 -1
مشاهده پرونده
@@ -45,7 +45,7 @@ amd-smi --help
```bash
python3 -m pip install argcomplete
activate-global-python-argcomplete
activate-global-python-argcomplete --user
# restart shell to enable
```
+30 -7
مشاهده پرونده
@@ -105,6 +105,7 @@ do_ldconfig() {
}
do_install_amdsmi_python_lib() {
echo "Installing AMD-SMI python library (amdsmi)..."
# get python version
local python3_minor_version
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
@@ -122,21 +123,43 @@ do_install_amdsmi_python_lib() {
return
fi
local PREVIOUS_PIP_ROOT_ACTION="$PIP_ROOT_USER_ACTION"
export PIP_ROOT_USER_ACTION=ignore
# Remove old python library
python3 -m pip uninstall amdsmi --yes --quiet
local pip_list_output
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for amdsmi
if [[ $pip_list_output == *"amdsmi"* ]]; then
echo "Detected old AMD-SMI python library (amdsmi)..."
python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check
echo "Removed old AMD-SMI python library (amdsmi)..."
fi
# install python library at @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi
local python_lib_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@
python3 -m pip install "$python_lib_path"
python3 -m pip show argcomplete
if [ $? -ne 1 ]; then
activate-global-python-argcomplete
python3 -m pip install "$python_lib_path" --quiet --disable-pip-version-check
unset PIP_ROOT_USER_ACTION
export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_ACTION"
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for argcomplete
if [[ $pip_list_output == *"argcomplete"* ]]; then
activate-global-python-argcomplete3
# Newer versions of argcomplete do not have the 3 at the end
if [ $? -ne 0 ]; then
echo "[WARNING] Could not find activate-global-python-argcomplete3. "\
"Trying newer activate-global-python-argcomplete..."
activate-global-python-argcomplete
fi
fi
echo "Installed AMD-SMI python library (amdsmi)..."
}
# post install or upgrade, $i is 1 or 2 -> do these actions
if [ "$1" -ge 1 ]; then
do_install_amdsmi_python_lib || return 0
do_install_amdsmi_python_lib
do_ldconfig
do_configureLogrotate || return 0
do_configureLogrotate || exit 0
fi
+34 -7
مشاهده پرونده
@@ -1,9 +1,16 @@
#!/bin/bash
rm_pyc() {
rm_leftovers() {
# remove pyc files generated by python
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/__pycache__
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi/__pycache__
# remove leftover doc files
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/../doc/amd_smi*
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/
# remove leftover libs
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libamd_smi.so*
}
rm_logFolder() {
@@ -26,6 +33,7 @@ return_logrotateToOrigConfig() {
}
rm_python_lib() {
echo "Removing AMD-SMI python library (amdsmi)..."
# get python version
local python3_minor_version
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
@@ -42,21 +50,40 @@ rm_python_lib() {
return
fi
python3 -m pip uninstall amdsmi --yes
python3 -m pip show amdsmi
if [ $? -ne 1 ]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed. "\
# Remove old python library
local pip_list_output
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for amdsmi
if [[ $pip_list_output == *"amdsmi"* ]]; then
local PREVIOUS_PIP_ROOT_ACTION="$PIP_ROOT_USER_ACTION"
export PIP_ROOT_USER_ACTION=ignore
echo "Detected AMD-SMI python library (amdsmi)..."
python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check
echo "Removed AMD-SMI python library (amdsmi)..."
unset PIP_ROOT_USER_ACTION
export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_ACTION"
fi
local pip_list_output
pip_list_output=$(python3 -m pip list --disable-pip-version-check)
# check pip list output for amdsmi
if [[ $pip_list_output == *"amdsmi"* ]]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed in pip. "\
"Check post install to ensure version is correct"
return
fi
echo "Removed AMD-SMI python library (amdsmi)..."
}
if [ "$1" -le 1 ]; then
# perform the below actions for rpm remove($1=0) or upgrade($1=1) operations
# remove old gpuv-smi symlink
rm -f @CPACK_PACKAGING_INSTALL_PREFIX@/bin/gpuv-smi &> /dev/null
rm_python_lib || return 0
rm_pyc
rm_python_lib
rm_leftovers
rm_logFolder
return_logrotateToOrigConfig
fi
+1 -1
مشاهده پرونده
@@ -32,7 +32,7 @@ amd-smi --help
```bash
python3 -m pip install argcomplete
activate-global-python-argcomplete
activate-global-python-argcomplete --user
# restart shell to enable
```
+17 -1
مشاهده پرونده
@@ -3,7 +3,23 @@
[metadata]
name = amdsmi
author = AMD
author_email = amd-smi.support@amd.com
url = https://github.com/RadeonOpenCompute/amdsmi
description = AMDSMI Python LIB - AMD GPU Monitoring Library
version = @amd_smi_libraries_VERSION_STRING@
license_file = amdsmi/LICENSE
classifiers =
Programming Language :: Python :: 3
[options]
zip_safe = False
include_package_data = True
packages = find:
python_requires = >=3.6
install_requires=
PyYAML >= 5.0
clang >= 14.0
[options.package_data]
amdsmi = *.so
* = *.so