From d1ee2ec8709b21f2e72536cc14dba8ac2f8621ab Mon Sep 17 00:00:00 2001 From: "Karl W. Schulz" Date: Fri, 3 May 2024 12:21:22 -0500 Subject: [PATCH] Adding a top-level runtime python dependency checker. Goal is to provide a kinder error message in the case where python dependencies are not available locally. This is motivated for future execution by users who are running from rocm-based binary packaging instead of using normal cmake build system which would have verified the dependencies. Signed-off-by: Karl W. Schulz --- src/omniperf | 61 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/omniperf b/src/omniperf index 3cd3f2f840..be272a21fb 100755 --- a/src/omniperf +++ b/src/omniperf @@ -24,13 +24,67 @@ # SOFTWARE. ##############################################################################el -import sys import logging -from omniperf_base import Omniperf -from utils.utils import console_error +import os +import sys +import pkg_resources +from pathlib import Path +from pkg_resources import DistributionNotFound, VersionConflict +from distutils import text_file + +try: + from omniperf_base import Omniperf + from utils.utils import console_error +except: + pass + + +def verify_deps(): + + bindir = Path(__file__).resolve().parent + depsLocation = ["requirements.txt", "../requirements.txt"] + + for location in depsLocation: + checkFile = os.path.join(bindir, location) + if os.path.exists(checkFile): + + dependencies = text_file.TextFile(checkFile).readlines() + error = False + + try: + pkg_resources.require(dependencies) + except DistributionNotFound as e: + print( + "[ERROR] The '%s' distribution was not found in the current execution environment." + % e.req.key + ) + error = True + + except VersionConflict as e: + print( + "[ERROR] the '%s' distribution does not meet version requirements to use omniperf." + % e.req.key + ) + print(" --> version installed :", e.dist) + print(" --> version required :", e.req) + error = True + + if error: + print("") + print( + "Please verify all of the python dependencies called out in the requirements file" + ) + print("are installed locally prior to running omniperf.") + print("") + print("See: %s" % checkFile) + sys.exit(1) + return def main(): + # verify required python dependencies + verify_deps() + omniperf = Omniperf() mode = omniperf.get_mode() @@ -47,5 +101,6 @@ def main(): sys.exit(0) + if __name__ == "__main__": main()