From 7591eec971c162e87bcd411bbb81d8ee26f47b63 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Mon, 5 Aug 2024 11:22:11 -0700 Subject: [PATCH] SWDEV-469004 - Append additonal path to system path amd-smi is installed in /opt/rocm-ver/bin, but not as a soft link in wheel package For amd-smi to work from bin directory, it need the extra path to find the dependent python scripts in /opt/rocm-ver/libexec/amd_smi Change-Id: I4ff63a8f55949aaac51d85eae849ecc890f4c694 --- amdsmi_cli/amdsmi_cli.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/amdsmi_cli/amdsmi_cli.py b/amdsmi_cli/amdsmi_cli.py index a5eeded872..0cf7aaa80b 100755 --- a/amdsmi_cli/amdsmi_cli.py +++ b/amdsmi_cli/amdsmi_cli.py @@ -24,19 +24,43 @@ import logging import sys +import os try: import argcomplete except ImportError: logging.debug("argcomplete module not found. Autocomplete will not work.") - -from amdsmi_commands import AMDSMICommands -from amdsmi_parser import AMDSMIParser -from amdsmi_logger import AMDSMILogger -import amdsmi_cli_exceptions -from amdsmi import amdsmi_interface -from amdsmi import amdsmi_exception - +from typing import TYPE_CHECKING +# only used for type checking +# pyright trips up and cannot find amdsmi scripts without it +if TYPE_CHECKING: + from amdsmi_commands import AMDSMICommands + from amdsmi_parser import AMDSMIParser + from amdsmi_logger import AMDSMILogger + import amdsmi_cli_exceptions + from amdsmi import amdsmi_interface + from amdsmi import amdsmi_exception +try: + from amdsmi_commands import AMDSMICommands + from amdsmi_parser import AMDSMIParser + from amdsmi_logger import AMDSMILogger + import amdsmi_cli_exceptions + from amdsmi import amdsmi_interface + from amdsmi import amdsmi_exception +except ImportError: + current_path = os.path.dirname(os.path.abspath(__file__)) + additional_path = f"{current_path}/../libexec/amdsmi_cli" + sys.path.append(additional_path) + try: + from amdsmi_commands import AMDSMICommands + from amdsmi_parser import AMDSMIParser + from amdsmi_logger import AMDSMILogger + import amdsmi_cli_exceptions + from amdsmi import amdsmi_interface + from amdsmi import amdsmi_exception + except ImportError: + print(f"Still couldn't import 'amdsmi related scripts'. Make sure it's installed in {additional_path}") + sys.exit(1) def _print_error(e, destination): if destination in ['stdout', 'json', 'csv']: