diff --git a/CMakeLists.txt b/CMakeLists.txt index 47c67e1b45..ba796fc63a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/DEBIAN/postinst.in b/DEBIAN/postinst.in index c168fa4d75..6b558b2dd4 100755 --- a/DEBIAN/postinst.in +++ b/DEBIAN/postinst.in @@ -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" diff --git a/DEBIAN/prerm.in b/DEBIAN/prerm.in index 186593ce2e..7295b3a0ce 100755 --- a/DEBIAN/prerm.in +++ b/DEBIAN/prerm.in @@ -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 ;; diff --git a/README.md b/README.md index c4568921b9..b18de60af8 100755 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/RPM/post.in b/RPM/post.in index cf760e9d07..1f3d0ced42 100755 --- a/RPM/post.in +++ b/RPM/post.in @@ -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 diff --git a/RPM/preun.in b/RPM/preun.in index 00bd4d374c..f3ec8ed5d6 100755 --- a/RPM/preun.in +++ b/RPM/preun.in @@ -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 diff --git a/amdsmi_cli/README.md b/amdsmi_cli/README.md index 0be74e1c29..c7473a0e59 100644 --- a/amdsmi_cli/README.md +++ b/amdsmi_cli/README.md @@ -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 ``` diff --git a/py-interface/setup.cfg.in b/py-interface/setup.cfg.in index 3647feae6b..99ff944678 100644 --- a/py-interface/setup.cfg.in +++ b/py-interface/setup.cfg.in @@ -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 \ No newline at end of file