From 5e90a734465a0f1a5302ad1fdb84baa7912afb1a Mon Sep 17 00:00:00 2001 From: Patrick Mullen Date: Mon, 25 Nov 2024 13:16:59 -0700 Subject: [PATCH] Add --cwd option --- .gitignore | 2 ++ tst/run_tests.py | 63 +++++++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index c36f8b0..9dcf06d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,9 @@ doc/src/parameters.rst # CI files artemis_ci_*.out +tst/logs tst/figs +**/testing/ # Visualization package files .smhist diff --git a/tst/run_tests.py b/tst/run_tests.py index 3de1beb..94fdc17 100755 --- a/tst/run_tests.py +++ b/tst/run_tests.py @@ -283,7 +283,7 @@ def set_globals(args): out_dir = kwargs.pop("output_dir") out_dir = os.path.join(out_dir, "testing") if out_dir is not None else None exe_path = kwargs.pop("exe") - cwd = os.getcwd() + use_cwd = kwargs.pop("cwd") # Set the correct paths if exe_path is not None: @@ -291,6 +291,9 @@ def set_globals(args): out_dir = os.path.join(adir, "testing") if out_dir is None else out_dir reb_path = os.path.join(os.path.dirname(exe_path), "librebound.so") + if use_cwd: + raise TestError("--cwd and --exe=PATH cannot be passed together!") + if not (os.path.exists(exe_path) and os.access(exe_path, os.X_OK)): raise TestError(f'Provided exe "{exe_path}" not found or cannot be run!') @@ -302,25 +305,26 @@ def set_globals(args): artemis.set_paths(abs_exe_dir, abs_out_dir) artemis.set_supplied_exe(True) else: - # If we are in a directory with an executable, default to using that - local_path = os.path.join(cwd, "artemis") - if os.path.isfile(local_path) and os.access(local_path, os.X_OK): - exe_path = local_path - out_dir = os.path.join(cwd, "testing") if out_dir is None else out_dir - reb_path = os.path.join(os.path.dirname(exe_path), "librebound.so") + cwd = os.getcwd() + lpath_exe = os.path.join(cwd, "artemis") + lpath_cache = os.path.join(cwd, "CMakeCache.txt") + if use_cwd: + # If we are in a directory with an executable, default to using that + if os.path.isfile(lpath_exe) and os.access(lpath_exe, os.X_OK): + exe_path = lpath_exe + out_dir = os.path.join(cwd, "testing") if out_dir is None else out_dir + reb_path = os.path.join(os.path.dirname(exe_path), "librebound.so") - if not os.path.exists(reb_path): - raise TestError(f'librebound.so not found at "{reb_path}"!') + if not os.path.exists(reb_path): + raise TestError(f'librebound.so not found at "{reb_path}"!') - abs_out_dir = os.path.abspath(out_dir) - abs_exe_dir = os.path.abspath(os.path.dirname(exe_path)) - artemis.set_paths(abs_exe_dir, abs_out_dir) - artemis.set_supplied_exe(True) - else: - # Check if we are one level up from the executable - local_path = os.path.join(cwd, "CMakeCache.txt") - if os.path.exists(local_path) and os.access(local_path, os.R_OK): - exe_path = read_cmakecache(local_path) + abs_out_dir = os.path.abspath(out_dir) + abs_exe_dir = os.path.abspath(os.path.dirname(exe_path)) + artemis.set_paths(abs_exe_dir, abs_out_dir) + artemis.set_supplied_exe(True) + elif os.path.exists(lpath_cache) and os.access(lpath_cache, os.R_OK): + # Check if we are one level up from the executable + exe_path = read_cmakecache(lpath_cache) out_dir = os.path.join(cwd, "testing") if out_dir is None else out_dir reb_path = os.path.join(os.path.dirname(exe_path), "librebound.so") @@ -335,13 +339,15 @@ def set_globals(args): artemis.set_paths(abs_exe_dir, abs_out_dir) artemis.set_supplied_exe(True) else: - adir = os.path.join(artemis.get_artemis_dir(), "tst") - exe_path = os.path.join(adir, "build/src/artemis") - out_dir = os.path.join(adir, "testing") if out_dir is None else out_dir - abs_out_dir = os.path.abspath(out_dir) - abs_exe_dir = os.path.abspath(os.path.dirname(exe_path)) - artemis.set_paths(abs_exe_dir, abs_out_dir) - artemis.set_supplied_exe(False) + raise TestError("Unable to find executable via --cwd") + else: + adir = os.path.join(artemis.get_artemis_dir(), "tst") + exe_path = os.path.join(adir, "build/src/artemis") + out_dir = os.path.join(adir, "testing") if out_dir is None else out_dir + abs_out_dir = os.path.abspath(out_dir) + abs_exe_dir = os.path.abspath(os.path.dirname(exe_path)) + artemis.set_paths(abs_exe_dir, abs_out_dir) + artemis.set_supplied_exe(False) # Execute main function @@ -389,6 +395,7 @@ def set_globals(args): default=None, help="path to pre-built executable", ) + parser.add_argument( "--output_dir", type=str, @@ -396,6 +403,12 @@ def set_globals(args): help="path to output directory", ) + parser.add_argument( + "--cwd", + action="store_true", + help="search local path for preexisting executable", + ) + args = parser.parse_args() set_globals(args) log_init(args)