From 3c562588ff30bc76836fcb3b8faa4da144a03faf Mon Sep 17 00:00:00 2001 From: Karl W Schulz Date: Tue, 16 Apr 2024 15:07:49 -0500 Subject: [PATCH] update logic to detect VERSION file to accommodate rocm packaging; check two locations to cover case where user is running within local git clone directly or alternatively, from package install. Signed-off-by: Karl W Schulz --- src/utils/utils.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index 7d5ffe2320..6fdb6f5b6a 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -89,13 +89,25 @@ def trace_logger(message, *args, **kwargs): def get_version(omniperf_home) -> dict: """Return Omniperf versioning info""" - # symantic version info - version = os.path.join(omniperf_home.parent, "VERSION") - try: - with open(version, "r") as file: - VER = file.read().replace("\n", "") - except EnvironmentError: - logging.critical("ERROR: Cannot find VERSION file at {}".format(version)) + + # symantic version info - note that version file(s) can reside in + # two locations depending on development vs formal install + searchDirs = [omniperf_home, omniperf_home.parent] + found = False + versionDir = None + + for dir in searchDirs: + version = os.path.join(dir, "VERSION") + try: + with open(version, "r") as file: + VER = file.read().replace("\n", "") + found = True + versionDir = dir + break + except: + pass + if not found: + logging.error("Cannot find VERSION file at {}".format(searchDirs)) sys.exit(1) # git version info @@ -113,7 +125,7 @@ def get_version(omniperf_home) -> dict: SHA = gitQuery.stdout.decode("utf-8") MODE = "dev" else: - shaFile = os.path.join(omniperf_home.parent, "VERSION.sha") + shaFile = os.path.join(versionDir, "VERSION.sha") try: with open(shaFile, "r") as file: SHA = file.read().replace("\n", "")