From 457619bfad5f2ccfb2b8a804f2f005133455de59 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Fri, 20 Sep 2024 15:55:32 -0500 Subject: [PATCH] [SWDEV-469278] - Lowered PyYAML dependency Signed-off-by: Maisam Arif Change-Id: Icfee09b84cf1071ec82b65fc2877be69e0283489 [ROCm/amdsmi commit: 09c95744547c01ed0121c6337a7f98a747017fb7] --- projects/amdsmi/CHANGELOG.md | 2 ++ projects/amdsmi/DEBIAN/postinst.in | 11 +++++------ projects/amdsmi/RPM/post.in | 10 +++++----- projects/amdsmi/amdsmi_cli/amdsmi_logger.py | 19 +++++++++++++++++-- .../amdsmi/py-interface/pyproject.toml.in | 2 +- projects/amdsmi/py-interface/setup.cfg.in | 2 +- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/projects/amdsmi/CHANGELOG.md b/projects/amdsmi/CHANGELOG.md index f9b898cf90..f09568d169 100644 --- a/projects/amdsmi/CHANGELOG.md +++ b/projects/amdsmi/CHANGELOG.md @@ -305,6 +305,8 @@ GPU: 1 ### Resolved issues +- **Improved Offline install process & lowered dependency for PyYAML**. + - **Fixed CPX not showing total number of logical GPUs**. - Updates were made to `amdsmi_init()` and `amdsmi_get_gpu_bdf_id(..)`. In order to display all logical devices, we needed a way to provide order to GPU's enumerated. This was done by adding a partition_id within the BDF optional pci_id bits. - Due to driver changes in KFD, some devices may report bits [31:28] or [2:0]. With the newly added `amdsmi_get_gpu_bdf_id(..)`, we provided this fallback to properly retreive partition ID. We diff --git a/projects/amdsmi/DEBIAN/postinst.in b/projects/amdsmi/DEBIAN/postinst.in index 45443b55a1..8312a77830 100755 --- a/projects/amdsmi/DEBIAN/postinst.in +++ b/projects/amdsmi/DEBIAN/postinst.in @@ -149,7 +149,7 @@ do_install_amdsmi_python_lib() { return fi - # upgrade pip if it's an ancient version + # upgrade pip if it's an ancient version, typically should not execute # otherwise the amdsmi install will fail local pip_version pip_version=$(python3 -m pip --version | grep -Eo '^[^\ ]+ ([0-9]+)' | grep -Eo '[0-9]+$') @@ -159,10 +159,9 @@ do_install_amdsmi_python_lib() { fi unset pip_version - # Check PyYAML dependency - local pyyaml_version - pyyaml_version=$(pip show pyyaml | grep -Po '(?<=Version: )[0-9]') - if [[ "$pyyaml_version" -lt 5 ]]; then + # Check PyYAML dependency, typically should not execute + pyyaml_version=$(python3 -m pip show pyyaml | grep -Po '(?<=Version: )[0-9]') + if [[ "$pyyaml_version" -lt 3 ]]; then echo "Detected ancient pyyaml version ($pyyaml_version)... Upgrading..." python3 -m pip install 'PyYAML>=5.1' --quiet --disable-pip-version-check --ignore-installed fi @@ -170,7 +169,7 @@ do_install_amdsmi_python_lib() { # 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 + python3 -m pip install "$python_lib_path" --quiet --disable-pip-version-check --no-build-isolation export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_USER_ACTION" export PIP_BREAK_SYSTEM_PACKAGES="$PREVIOUS_PIP_BREAK_SYSTEM_PACKAGES" diff --git a/projects/amdsmi/RPM/post.in b/projects/amdsmi/RPM/post.in index e33e9c0de7..fd182ef414 100755 --- a/projects/amdsmi/RPM/post.in +++ b/projects/amdsmi/RPM/post.in @@ -149,7 +149,7 @@ do_install_amdsmi_python_lib() { fi # upgrade pip if it's an ancient version - # otherwise the amdsmi install will fail + # otherwise amdsmi install will fail local pip_version pip_version=$(python3 -m pip --version | grep -Eo '^[^\ ]+ ([0-9]+)' | grep -Eo '[0-9]+$') if [[ "$pip_version" -lt 19 ]]; then @@ -158,10 +158,10 @@ do_install_amdsmi_python_lib() { fi unset pip_version - # Check PyYAML dependency + # Check PyYAML dependency, typically should not execute local pyyaml_version - pyyaml_version=$(pip show pyyaml | grep -Po '(?<=Version: )[0-9]') - if [[ "$pyyaml_version" -lt 5 ]]; then + pyyaml_version=$(python3 -m pip show pyyaml | grep -Po '(?<=Version: )[0-9]') + if [[ "$pyyaml_version" -lt 3 ]]; then echo "Detected ancient pyyaml version ($pyyaml_version)... Upgrading..." python3 -m pip install 'PyYAML>=5.1' --quiet --disable-pip-version-check --ignore-installed fi @@ -169,7 +169,7 @@ do_install_amdsmi_python_lib() { # 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 + python3 -m pip install "$python_lib_path" --quiet --disable-pip-version-check --no-build-isolation export PIP_ROOT_USER_ACTION="$PREVIOUS_PIP_ROOT_USER_ACTION" export PIP_BREAK_SYSTEM_PACKAGES="$PREVIOUS_PIP_BREAK_SYSTEM_PACKAGES" diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py index a3122124a6..8234f99eac 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py @@ -27,10 +27,19 @@ import time from typing import Dict from enum import Enum import yaml +import inspect from amdsmi_helpers import AMDSMIHelpers import amdsmi_cli_exceptions +### Custom YAML Functions +# Dumper class to preserve order of yaml.dump +class CustomDumper(yaml.Dumper): + def represent_dict_preserve_order(self, data): + return self.represent_dict(data.items()) +def has_sort_keys_option(): # to check if sort_keys is available + return 'sort_keys' in inspect.signature(yaml.dump).parameters + class AMDSMILogger(): def __init__(self, format='human_readable', destination='stdout') -> None: self.output = {} @@ -202,8 +211,14 @@ class AMDSMILogger(): capitalized_json["AMDSMI_SPACING_REMOVAL"] = tabbed_dictionary json_string = json.dumps(capitalized_json, indent=4) - yaml_data = yaml.safe_load(json_string) - yaml_output = yaml.dump(yaml_data, sort_keys=False, allow_unicode=True) + + if has_sort_keys_option(): + yaml_data = yaml.safe_load(json_string) + yaml_output = yaml.dump(yaml_data, sort_keys=False, allow_unicode=True) + else: + CustomDumper.add_representer(dict, CustomDumper.represent_dict_preserve_order) + yaml_data = yaml.safe_load(json_string) + yaml_output = yaml.dump(yaml_data, Dumper=CustomDumper, allow_unicode=True, default_flow_style=False) # Remove a key line if it is a spacer yaml_output = yaml_output.replace("AMDSMI_SPACING_REMOVAL:\n", "") diff --git a/projects/amdsmi/py-interface/pyproject.toml.in b/projects/amdsmi/py-interface/pyproject.toml.in index 149fc21a1b..e4d451aa82 100644 --- a/projects/amdsmi/py-interface/pyproject.toml.in +++ b/projects/amdsmi/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 >= 5.0", + "PyYAML >= 3.12", ] [project.urls] diff --git a/projects/amdsmi/py-interface/setup.cfg.in b/projects/amdsmi/py-interface/setup.cfg.in index 3e8b8c8732..ba56f2ac05 100644 --- a/projects/amdsmi/py-interface/setup.cfg.in +++ b/projects/amdsmi/py-interface/setup.cfg.in @@ -18,7 +18,7 @@ include_package_data = True packages = find: python_requires = >=3.6 install_requires= - PyYAML >= 5.0 + PyYAML >= 3.12 [options.package_data] * = *.so