From c9002a2d17b74d91f27c6b221b7143fadc6c547f Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:30:22 +0000 Subject: [PATCH] allow symbolic link to run_metplus.py to run by getting the real path of the script before trying to find the directory above the script to import metplus and produtil --- ush/run_metplus.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ush/run_metplus.py b/ush/run_metplus.py index 482c67e81f..9886e1119b 100755 --- a/ush/run_metplus.py +++ b/ush/run_metplus.py @@ -16,13 +16,14 @@ f-string instead of the useful error message. """ -import os +from os.path import abspath, join, dirname, realpath, basename +from os import pardir import sys import traceback +################################################################################ # add metplus directory to path so the wrappers and utilities can be found -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), - os.pardir))) +sys.path.insert(0, abspath(join(dirname(realpath(__file__)), pardir))) import produtil.setup @@ -44,8 +45,7 @@ def main(): return False # warn if calling master_metplus.py - script_name = os.path.basename(__file__) - if script_name == 'master_metplus.py': + if basename(__file__) == 'master_metplus.py': msg = ("master_metplus.py has been renamed to run_metplus.py. " "This script name will be removed in a future version.") config.logger.warning(msg) @@ -56,11 +56,7 @@ def main(): def usage(): - """! How to call this script. - """ - - filename = os.path.basename(__file__) - + """!How to call this script.""" print (''' Usage: %s arg1 arg2 arg3 -h|--help Display this usage statement @@ -69,7 +65,7 @@ def usage(): /path/to/parmfile.conf -- Specify custom configuration file to use section.option=value -- override conf options on the command line -'''%(filename)) +'''%(basename(__file__))) sys.exit(2)