Skip to content

Commit ed79383

Browse files
committed
Python-Site Packages changes
Signed-off-by: Justin Williams <Justin.Williams@amd.com>
1 parent 78e8a39 commit ed79383

File tree

4 files changed

+208
-200
lines changed

4 files changed

+208
-200
lines changed

.github/workflows/amdsmi-build.yml

Lines changed: 116 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,29 @@ jobs:
165165
echo "Installation successful on attempt $i"
166166
ln -s /opt/rocm/bin/amd-smi /usr/local/bin
167167
168-
# Install the wheel
169-
echo 'Installing wheel package...'
170-
PYTHON_CMD=python3
171-
$PYTHON_CMD -m pip install --force-reinstall ${{ env.PROJECT_DIR }}/build/py-interface/python_package/*.whl
172-
173168
# Verify Installation
174169
echo 'Verifying installation:'
175170
if ! amd-smi version; then echo "amd-smi version failed with $?" ; exit 1; fi
176-
if ! python3 -m pip list | grep amd; then echo "pip list | grep amd failed with $?" ; exit 1; fi
171+
172+
# Verify .pth file created by postinst (pip list will NOT show
173+
# amdsmi — the .pth approach adds to sys.path without registering
174+
# pip metadata, which is by design).
175+
python3 -c "
176+
import site, pathlib
177+
pth = pathlib.Path(site.getsitepackages()[0]) / 'amdsmi.pth'
178+
assert pth.exists(), f'amdsmi.pth not found at {pth}'
179+
print(f'✓ .pth file found: {pth}')
180+
print(f' contents: {pth.read_text().strip()}')
181+
"
182+
177183
if ! python3 -m pip list | grep pip; then echo "pip list | grep pip failed with $?" ; exit 1; fi
178184
if ! python3 -m pip list | grep setuptools; then echo "pip list | grep setuptools failed with $?" ; exit 1; fi
179185
echo 'Completed installation on ${{ matrix.os }}'
180186
181-
# Verify wheel installation
182-
echo 'Verifying wheel installation...'
183-
cd /tmp && $PYTHON_CMD -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
184-
echo 'Python wheel build and install completed on ${{ matrix.os }}'
187+
# Verify Python package import
188+
echo 'Verifying Python package...'
189+
cd /tmp && python3 -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Package working!')"
190+
echo 'Python package verification completed on ${{ matrix.os }}'
185191
break
186192
else
187193
echo "Installation failed on attempt $i"
@@ -419,6 +425,29 @@ jobs:
419425
echo "Unit tests passed"
420426
fi
421427
428+
429+
echo "Running CLI unit tests..."
430+
if ! ./cli_unit_test.py -v > /tmp/test-results-${{ matrix.os }}/cli_unit_test_output.txt 2>&1; then
431+
echo "CLI Unit tests failed!"
432+
echo "=============== CLI UNIT TEST OUTPUT ==============="
433+
tail -100 /tmp/test-results-${{ matrix.os }}/cli_unit_test_output.txt
434+
echo "===================================================="
435+
exit 1
436+
else
437+
echo "CLI Unit tests passed"
438+
fi
439+
440+
echo "Running perf tests..."
441+
if ! ./perf_tests.py -v > /tmp/test-results-${{ matrix.os }}/perf_test_output.txt 2>&1; then
442+
echo "Perf tests failed!"
443+
echo "=============== PERF TEST OUTPUT ==============="
444+
tail -100 /tmp/test-results-${{ matrix.os }}/perf_test_output.txt
445+
echo "================================================="
446+
exit 1
447+
else
448+
echo "Perf tests passed"
449+
fi
450+
422451
echo "Python tests done"
423452
424453
# Example Tests
@@ -450,6 +479,18 @@ jobs:
450479
echo "Displaying Unit Test Results for ${{ matrix.os }}"
451480
cat /tmp/test-results-${{ matrix.os }}/unit_test_output.txt || echo "No unit test results found for ${{ matrix.os }}"
452481
482+
- name: CLI Unit Test Results
483+
if: always()
484+
run: |
485+
echo "Displaying CLI Unit Test Results for ${{ matrix.os }}"
486+
cat /tmp/test-results-${{ matrix.os }}/cli_unit_test_output.txt || echo "No CLI unit test results found for ${{ matrix.os }}"
487+
488+
- name: Perf Test Results
489+
if: always()
490+
run: |
491+
echo "Displaying Perf Test Results for ${{ matrix.os }}"
492+
cat /tmp/test-results-${{ matrix.os }}/perf_test_output.txt || echo "No perf test results found for ${{ matrix.os }}"
493+
453494
- name: Example DRM Test Results
454495
if: always()
455496
run: |
@@ -661,23 +702,26 @@ jobs:
661702
echo "Installation successful on attempt $i"
662703
ln -s /opt/rocm/bin/amd-smi /usr/local/bin
663704
664-
665-
# Install the wheel
666-
echo 'Installing wheel package...'
667-
PYTHON_CMD=python3
668-
$PYTHON_CMD -m pip install --force-reinstall ${{ env.PROJECT_DIR }}/build/py-interface/python_package/*.whl
669-
670705
echo 'Verifying installation:'
671706
if ! amd-smi version; then echo "amd-smi version failed with $?" ; exit 1; fi
672-
if ! python3 -m pip list | grep amd; then echo "pip list | grep amd failed with $?" ; exit 1; fi
707+
708+
# Verify .pth file created by postinst
709+
python3 -c "
710+
import site, pathlib
711+
pth = pathlib.Path(site.getsitepackages()[0]) / 'amdsmi.pth'
712+
assert pth.exists(), f'amdsmi.pth not found at {pth}'
713+
print(f'✓ .pth file found: {pth}')
714+
print(f' contents: {pth.read_text().strip()}')
715+
"
716+
673717
if ! python3 -m pip list | grep pip; then echo "pip list | grep pip failed with $?" ; exit 1; fi
674718
if ! python3 -m pip list | grep setuptools; then echo "pip list | grep setuptools failed with $?" ; exit 1; fi
675719
echo 'Completed installation on RHEL10'
676720
677-
# Verify wheel installation
678-
echo 'Verifying wheel installation...'
679-
cd /tmp && $PYTHON_CMD -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
680-
echo 'Python wheel build and install completed on ${{ matrix.os }}'
721+
# Verify Python package import
722+
echo 'Verifying Python package...'
723+
cd /tmp && python3 -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Package working!')"
724+
echo 'Python package verification completed on ${{ matrix.os }}'
681725
break
682726
else
683727
echo "Installation failed on attempt $i"
@@ -724,23 +768,27 @@ jobs:
724768
esac
725769
ln -s /opt/rocm/bin/amd-smi /usr/local/bin
726770
727-
# Install the wheel
728-
echo 'Installing wheel package...'
729-
PYTHON_CMD=python3
730-
$PYTHON_CMD -m pip install --force-reinstall ${{ env.PROJECT_DIR }}/build/py-interface/python_package/*.whl
731-
732771
# Verify Installation
733772
echo 'Verifying installation:'
734773
if ! amd-smi version; then echo "amd-smi version failed with $?" ; exit 1; fi
735-
if ! python3 -m pip list | grep amd; then echo "pip list | grep amd failed with $?" ; exit 1; fi
774+
775+
# Verify .pth file created by postinst
776+
python3 -c "
777+
import site, pathlib
778+
pth = pathlib.Path(site.getsitepackages()[0]) / 'amdsmi.pth'
779+
assert pth.exists(), f'amdsmi.pth not found at {pth}'
780+
print(f'✓ .pth file found: {pth}')
781+
print(f' contents: {pth.read_text().strip()}')
782+
"
783+
736784
if ! python3 -m pip list | grep pip; then echo "pip list | grep pip failed with $?" ; exit 1; fi
737785
if ! python3 -m pip list | grep setuptools; then echo "pip list | grep setuptools failed with $?" ; exit 1; fi
738786
echo 'Completed installation on ${{ matrix.os }}'
739787
740-
# Verify wheel installation
741-
echo 'Verifying wheel installation...'
742-
cd /tmp && $PYTHON_CMD -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
743-
echo 'Python wheel build and install completed on ${{ matrix.os }}'
788+
# Verify Python package import
789+
echo 'Verifying Python package...'
790+
cd /tmp && python3 -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Package working!')"
791+
echo 'Python package verification completed on ${{ matrix.os }}'
744792
745793
- name: Uninstall
746794
if: always()
@@ -880,14 +928,9 @@ jobs:
880928
ln -s /opt/rocm/bin/amd-smi /usr/local/bin
881929
echo 'Install done for test on RHEL10/AlmaLinux8'
882930
883-
# Install the wheel
884-
echo 'Installing wheel package for tests...'
885-
PYTHON_CMD=python3
886-
$PYTHON_CMD -m pip install --force-reinstall ${{ env.PROJECT_DIR }}/build/py-interface/python_package/*.whl
887-
888931
# Verify wheel installation
889932
echo 'Verifying wheel installation (tests)...'
890-
cd /tmp && $PYTHON_CMD -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
933+
cd /tmp && python3 -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
891934
echo 'Python wheel build and install completed for tests on ${{ matrix.os }}'
892935
break
893936
else
@@ -945,14 +988,9 @@ jobs:
945988
ln -s /opt/rocm/bin/amd-smi /usr/local/bin
946989
echo 'Install done for test on ${{ matrix.os }}'
947990
948-
# Install the wheel
949-
echo 'Installing wheel package for tests...'
950-
PYTHON_CMD=python3
951-
$PYTHON_CMD -m pip install --force-reinstall ${{ env.PROJECT_DIR }}/build/py-interface/python_package/*.whl
952-
953991
# Verify wheel installation
954992
echo 'Verifying wheel installation (tests)...'
955-
cd /tmp && $PYTHON_CMD -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
993+
cd /tmp && python3 -c "import amdsmi; print('✓ Import successful'); amdsmi.amdsmi_init(); print('✓ Library loaded'); amdsmi.amdsmi_shut_down(); print('✓ Wheel working!')"
956994
echo 'Python wheel build and install completed for tests on ${{ matrix.os }}'
957995
958996
- name: AMDSMI Command Tests
@@ -1059,6 +1097,29 @@ jobs:
10591097
echo "Unit tests passed"
10601098
fi
10611099
1100+
1101+
echo "Running CLI unit tests..."
1102+
if ! ./cli_unit_test.py -v > /tmp/test-results-${{ matrix.os }}/cli_unit_test_output.txt 2>&1; then
1103+
echo "CLI Unit tests failed!"
1104+
echo "=============== CLI UNIT TEST OUTPUT ==============="
1105+
tail -100 /tmp/test-results-${{ matrix.os }}/cli_unit_test_output.txt
1106+
echo "===================================================="
1107+
exit 1
1108+
else
1109+
echo "CLI Unit tests passed"
1110+
fi
1111+
1112+
echo "Running perf tests..."
1113+
if ! ./perf_tests.py -v > /tmp/test-results-${{ matrix.os }}/perf_test_output.txt 2>&1; then
1114+
echo "Perf tests failed!"
1115+
echo "=============== PERF TEST OUTPUT ==============="
1116+
tail -100 /tmp/test-results-${{ matrix.os }}/perf_test_output.txt
1117+
echo "================================================="
1118+
exit 1
1119+
else
1120+
echo "Perf tests passed"
1121+
fi
1122+
10621123
echo "Python tests done"
10631124
10641125
# Example Tests
@@ -1090,6 +1151,18 @@ jobs:
10901151
echo "Displaying Unit Test Results for ${{ matrix.os }}"
10911152
cat /tmp/test-results-${{ matrix.os }}/unit_test_output.txt || echo "No unit test results found for ${{ matrix.os }}"
10921153
1154+
- name: CLI Unit Test Results
1155+
if: always()
1156+
run: |
1157+
echo "Displaying CLI Unit Test Results for ${{ matrix.os }}"
1158+
cat /tmp/test-results-${{ matrix.os }}/cli_unit_test_output.txt || echo "No CLI unit test results found for ${{ matrix.os }}"
1159+
1160+
- name: Perf Test Results
1161+
if: always()
1162+
run: |
1163+
echo "Displaying Perf Test Results for ${{ matrix.os }}"
1164+
cat /tmp/test-results-${{ matrix.os }}/perf_test_output.txt || echo "No perf test results found for ${{ matrix.os }}"
1165+
10931166
- name: Example DRM Test Results
10941167
if: always()
10951168
run: |

projects/amdsmi/DEBIAN/postinst.in

Lines changed: 31 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -105,98 +105,52 @@ do_ldconfig() {
105105
}
106106

107107
do_install_amdsmi_python_lib() {
108-
# get python version
109-
local python3_minor_version
110-
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
111-
if [ $? -ne 0 ]; then
112-
echo "[WARNING] Could not determine python version. "\
113-
"AMD-SMI python library will not be installed."
114-
return
115-
fi
108+
# Drop a .pth file into the system site-packages so that
109+
# "import amdsmi" finds the package installed under
110+
# @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@
111+
# without requiring pip. The .pth approach is version-agnostic:
112+
# it works with any Python 3.x without needing pip or setuptools.
116113

117-
# check if python version is supported
118-
if [ "$python3_minor_version" -lt 6 ]; then
119-
echo "[WARNING] AMD-SMI python library is not "\
120-
"supported on python version 3.$python3_minor_version. "\
121-
"AMD-SMI python library will not be installed."
122-
return
123-
fi
114+
local python_lib_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@
124115

125-
local PREVIOUS_PIP_ROOT_USER_ACTION="$PIP_ROOT_USER_ACTION"
126-
export PIP_ROOT_USER_ACTION=ignore
127-
# python3.11 requires --break-system-packages
128-
local PREVIOUS_PIP_BREAK_SYSTEM_PACKAGES="$PIP_BREAK_SYSTEM_PACKAGES"
129-
export PIP_BREAK_SYSTEM_PACKAGES=1
130-
131-
# Remove old python library
132-
local amdsmi_pip_list_output
133-
amdsmi_pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check)
134-
# check pip list output for amdsmi
135-
if [[ $amdsmi_pip_list_output == *"amdsmi"* ]]; then
136-
echo "Detected old AMD-SMI python library (amdsmi)..."
137-
python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check
138-
echo "Removed old AMD-SMI python library (amdsmi)..."
139-
fi
116+
# Remove stale SWIG-based Python extension (now uses ctypes)
117+
rm -f "${python_lib_path}/amdsmi/libamd_smi_python.so" 2>/dev/null || true
140118

141-
# static builds don't include python lib
142-
if [ "@BUILD_SHARED_LIBS@" != "ON" ]; then
143-
return
119+
# Remove any previously pip-installed amdsmi to avoid conflicts
120+
if python3 -m pip list --format=columns --disable-pip-version-check 2>/dev/null | grep -q amdsmi; then
121+
echo "Removing previously pip-installed amdsmi..."
122+
PIP_BREAK_SYSTEM_PACKAGES=1 python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check 2>/dev/null || true
144123
fi
145124

146-
check_and_install_amdsmi() {
147-
local setuptools_version
148-
setuptools_version=$(python3 -c 'import setuptools; print(setuptools.__version__)')
149-
if [ $? -ne 0 ]; then
150-
echo "[WARNING] Could not determine setuptools version. "\
151-
"AMD-SMI python library will not be installed."
152-
return
125+
# Determine site-packages directory
126+
local site_packages
127+
site_packages=$(python3 -c 'import site; print(site.getsitepackages()[0])' 2>/dev/null)
128+
if [ -z "$site_packages" ]; then
129+
echo "[WARNING] Could not determine site-packages directory. Trying dist-packages fallback..."
130+
site_packages=$(python3 -c 'import sysconfig; print(sysconfig.get_path("purelib"))' 2>/dev/null)
153131
fi
154132

155-
# install python library at @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi
156-
local python_lib_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@
157-
local amdsmi_python_lib_path="$python_lib_path"
158-
local amdsmi_setup_py_path="$python_lib_path/setup.py"
159-
160-
# Remove stale SWIG-based Python extension; the package now uses ctypes
161-
# and libamd_smi_python.so is no longer shipped. A leftover copy baked
162-
# into the container image references symbols removed from libamd_smi.so
163-
# and causes "undefined symbol" errors when importing the amdsmi package.
164-
rm -f "${amdsmi_python_lib_path}/amdsmi/libamd_smi_python.so" 2>/dev/null || true
165-
166-
# Decide installation method based on setuptools version
167-
if [[ "$(printf '%s\n' "$setuptools_version" "28.5" | sort -V | head -n1)" == "$setuptools_version" ]]; then
168-
echo "[WARNING] Setuptools version is less than 28.5. AMD-SMI will not be installed."
169-
elif [[ "$(printf '%s\n' "$setuptools_version" "41.0.1" | sort -V | head -n1)" != "41.0.1" ]]; then
170-
echo "Using setup.py for installation due to setuptools version $setuptools_version"
171-
python3 "$amdsmi_setup_py_path" install
172-
else
173-
echo "Using pyproject.toml for installation due to setuptools version $setuptools_version"
174-
python3 -m pip install "$amdsmi_python_lib_path" --quiet --disable-pip-version-check --no-build-isolation --no-index
133+
if [ -z "$site_packages" ] || [ ! -d "$site_packages" ]; then
134+
echo "[WARNING] Could not locate Python site-packages. AMD-SMI .pth file will not be installed."
135+
return
175136
fi
176-
}
177137

178-
# Call the function
179-
check_and_install_amdsmi
138+
# Write the .pth file — Python adds this path to sys.path on startup
139+
echo "$python_lib_path" > "$site_packages/amdsmi.pth"
140+
echo "Installed amdsmi.pth -> $site_packages/amdsmi.pth (points to $python_lib_path)"
180141

181-
export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_USER_ACTION"
182-
export PIP_BREAK_SYSTEM_PACKAGES="$PREVIOUS_PIP_BREAK_SYSTEM_PACKAGES"
183-
184-
# only try to activate argcomplete if such command exists
185-
# python3-argcomplete is recommended but optional, we handle its absence gracefully
142+
# Activate argcomplete if available
186143
if command -v activate-global-python-argcomplete &>/dev/null; then
187144
activate-global-python-argcomplete 2>/dev/null || {
188145
echo "[INFO] Bash completion activation skipped. You can manually enable it with: activate-global-python-argcomplete"
189146
}
147+
elif command -v activate-global-python-argcomplete3 &>/dev/null; then
148+
activate-global-python-argcomplete3 2>/dev/null || {
149+
echo "[INFO] Bash completion activation skipped. You can manually enable it with: activate-global-python-argcomplete3"
150+
}
190151
else
191-
# try older argcomplete3 version
192-
if command -v activate-global-python-argcomplete3 &>/dev/null; then
193-
activate-global-python-argcomplete3 2>/dev/null || {
194-
echo "[INFO] Bash completion activation skipped. You can manually enable it with: activate-global-python-argcomplete3"
195-
}
196-
else
197-
echo "[WARNING] Could not find argcomplete activation command. "\
198-
"Argument completion will not work. Install python3-argcomplete package to enable it."
199-
fi
152+
echo "[WARNING] Could not find argcomplete activation command. "\
153+
"Argument completion will not work. Install python3-argcomplete package to enable it."
200154
fi
201155
}
202156

0 commit comments

Comments
 (0)