From 2e5b164c4364b5b5531abeca9bf930fa6840cc5e Mon Sep 17 00:00:00 2001 From: Justin Williams Date: Wed, 25 Sep 2024 18:20:23 -0500 Subject: [PATCH] [SWDEV-482058 / SWDEV-482971] Added setup.py install Signed-off-by: Justin Williams Change-Id: Ibad07d34dfb455043ce307fe036289f1d5c20a9a --- DEBIAN/postinst.in | 35 +++++++++++++++++++++++++++------ RPM/post.in | 36 ++++++++++++++++++++++++++++------ py-interface/CMakeLists.txt | 3 +++ py-interface/pyproject.toml.in | 2 +- py-interface/setup.cfg.in | 2 +- py-interface/setup.py.in | 25 +++++++++++++++++++++++ 6 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 py-interface/setup.py.in diff --git a/DEBIAN/postinst.in b/DEBIAN/postinst.in index 929de884b4..87c2e67229 100755 --- a/DEBIAN/postinst.in +++ b/DEBIAN/postinst.in @@ -134,10 +134,10 @@ do_install_amdsmi_python_lib() { export PIP_BREAK_SYSTEM_PACKAGES=1 # Remove old python library - local pip_list_output - pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check) + local amdsmi_pip_list_output + amdsmi_pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check) # check pip list output for amdsmi - if [[ $pip_list_output == *"amdsmi"* ]]; then + if [[ $amdsmi_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)..." @@ -148,9 +148,32 @@ do_install_amdsmi_python_lib() { return 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" --quiet --disable-pip-version-check --no-build-isolation --no-index + check_and_install_amdsmi() { + local setuptools_version + setuptools_version=$(python3 -c 'import setuptools; print(setuptools.__version__)') + if [ $? -ne 0 ]; then + echo "[WARNING] Could not determine setuptools version. "\ + "AMD-SMI python library will not be installed." + return + fi + + local amdsmi_python_lib_path="/opt/rocm/share/amd_smi" + local amdsmi_setup_py_path="/opt/rocm/share/amd_smi/setup.py" + + # Decide installation method based on setuptools version + if [[ "$(printf '%s\n' "$setuptools_version" "28.5" | sort -V | head -n1)" == "$setuptools_version" ]]; then + echo "[WARNING] Setuptools version is less than 28.5. AMD-SMI will not be installed." + elif [[ "$(printf '%s\n' "$setuptools_version" "41.0.1" | sort -V | head -n1)" != "41.0.1" ]]; then + echo "Using setup.py for installation due to setuptools version $setuptools_version" + python3 "$amdsmi_setup_py_path" install + else + echo "Using pyproject.toml for installation due to setuptools version $setuptools_version" + python3 -m pip install "$amdsmi_python_lib_path" --quiet --disable-pip-version-check --no-build-isolation --no-index + fi +} + + # Call the function + check_and_install_amdsmi export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_USER_ACTION" export PIP_BREAK_SYSTEM_PACKAGES="$PREVIOUS_PIP_BREAK_SYSTEM_PACKAGES" diff --git a/RPM/post.in b/RPM/post.in index 315e67cc0a..5f4d3ed864 100755 --- a/RPM/post.in +++ b/RPM/post.in @@ -134,10 +134,10 @@ do_install_amdsmi_python_lib() { # Remove old python library - local pip_list_output - pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check) + local amdsmi_pip_list_output + amdsmi_pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check) # check pip list output for amdsmi - if [[ $pip_list_output == *"amdsmi"* ]]; then + if [[ $amdsmi_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)..." @@ -148,9 +148,33 @@ do_install_amdsmi_python_lib() { return 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" --quiet --disable-pip-version-check --no-build-isolation --no-index + check_and_install_amdsmi() { + local setuptools_version + setuptools_version=$(python3 -c 'import setuptools; print(setuptools.__version__)') + if [ $? -ne 0 ]; then + echo "[WARNING] Could not determine setuptools version. "\ + "AMD-SMI python library will not be installed." + return + fi + + local amdsmi_python_lib_path="/opt/rocm/share/amd_smi" + local amdsmi_setup_py_path="/opt/rocm/share/amd_smi/setup.py" + + # Decide installation method based on setuptools version + if [[ "$(printf '%s\n' "$setuptools_version" "28.5" | sort -V | head -n1)" == "$setuptools_version" ]]; then + echo "[WARNING] Setuptools version is less than 28.5. AMD-SMI will not be installed." + elif [[ "$(printf '%s\n' "$setuptools_version" "41.0.1" | sort -V | head -n1)" != "41.0.1" ]]; then + echo "Using setup.py for installation due to setuptools version $setuptools_version" + python3 "$amdsmi_setup_py_path" install + else + echo "Using pyproject.toml for installation due to setuptools version $setuptools_version" + python3 -m pip install "$amdsmi_python_lib_path" --quiet --disable-pip-version-check --no-build-isolation --no-index + fi +} + + # Call the function + check_and_install_amdsmi + export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_USER_ACTION" export PIP_BREAK_SYSTEM_PACKAGES="$PREVIOUS_PIP_BREAK_SYSTEM_PACKAGES" diff --git a/py-interface/CMakeLists.txt b/py-interface/CMakeLists.txt index b9e44ec9e6..09d01a54e8 100644 --- a/py-interface/CMakeLists.txt +++ b/py-interface/CMakeLists.txt @@ -70,6 +70,7 @@ endif() configure_file(pyproject.toml.in ${PY_BUILD_DIR}/pyproject.toml @ONLY) configure_file(setup.cfg.in ${PY_BUILD_DIR}/setup.cfg @ONLY) configure_file(_version.py.in ${PY_PACKAGE_DIR}/_version.py @ONLY) +configure_file(setup.py.in ${PY_BUILD_DIR}/setup.py @ONLY) add_custom_target( python_wrapper @@ -103,6 +104,7 @@ add_custom_target( python_package ALL DEPENDS ${PY_BUILD_DIR}/pyproject.toml ${PY_BUILD_DIR}/setup.cfg + ${PY_BUILD_DIR}/setup.py ${PY_PACKAGE_DIR}/_version.py ${PY_PACKAGE_DIR}/__init__.py ${PY_PACKAGE_DIR}/amdsmi_exception.py @@ -116,6 +118,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PY_BUILD_DIR}/pyproject.toml ${CMAKE_CURRENT_BINARY_DIR}/${PY_BUILD_DIR}/setup.cfg + ${CMAKE_CURRENT_BINARY_DIR}/${PY_BUILD_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR}/${PY_PACKAGE_DIR}/_version.py DESTINATION ${PY_WRAPPER_INSTALL_DIR} COMPONENT dev) diff --git a/py-interface/pyproject.toml.in b/py-interface/pyproject.toml.in index e4d451aa82..b4852782e3 100644 --- a/py-interface/pyproject.toml.in +++ b/py-interface/pyproject.toml.in @@ -16,7 +16,7 @@ readme = {file = "amdsmi/README.md", content-type = "text/markdown"} description = "AMDSMI Python LIB - AMD GPU Monitoring Library" requires-python = ">=3.6" dependencies = [ - "PyYAML >= 3.12", + "PyYAML >= 3.0", ] [project.urls] diff --git a/py-interface/setup.cfg.in b/py-interface/setup.cfg.in index ba56f2ac05..ab89a00f53 100644 --- a/py-interface/setup.cfg.in +++ b/py-interface/setup.cfg.in @@ -18,7 +18,7 @@ include_package_data = True packages = find: python_requires = >=3.6 install_requires= - PyYAML >= 3.12 + PyYAML >= 3.0 [options.package_data] * = *.so diff --git a/py-interface/setup.py.in b/py-interface/setup.py.in new file mode 100644 index 0000000000..8aa2091a78 --- /dev/null +++ b/py-interface/setup.py.in @@ -0,0 +1,25 @@ +from setuptools import setup, find_packages +import os + +setup( + name="amdsmi", + version="@amd_smi_libraries_VERSION_STRING@", + author="AMD", + author_email="amd-smi.support@amd.com", + description="AMDSMI Python LIB - AMD GPU Monitoring Library", + url="https://github.com/ROCm/amdsmi", + packages=find_packages(), + install_requires=[ + "PyYAML>=3.0", + ], + classifiers=[ + "Programming Language :: Python :: 3", + ], + python_requires=">=3.6", + include_package_data=True, + package_data={ + '': ['*.so'], + }, + zip_safe=False, + license='amdsmi/LICENSE', +)