diff --git a/9pm.py b/9pm.py index 84f644a..a3d9b02 100755 --- a/9pm.py +++ b/9pm.py @@ -516,6 +516,10 @@ def run_suite(cmdline, data, skip_suite): def parse_rc(root_path): rc = {} required_keys = ["LOG_PATH"] + voluntary_keys = [ + "PARENT_PROJECT_NAME", + "PARENT_PROJECT_ROOT", + ] files = [ os.path.join(root_path, '..', '9pm.rc'), @@ -543,6 +547,11 @@ def parse_rc(root_path): print(f"error, 9pm.rc is missing required keys: {', '.join(missing_keys)}") sys.exit(1) + allowed_keys = set(required_keys + voluntary_keys) + unsupported_keys = [key for key in data if key not in allowed_keys] + if unsupported_keys: + print(f"warning, 9pm.rc contains unsupported keys: {', '.join(unsupported_keys)}") + return data def parse_cmdline(): @@ -595,17 +604,17 @@ def setup_env(cmdline): if cmdline.config: os.environ["NINEPM_CONFIG"] = cmdline.config -def get_git_sha(): - if not os.path.isdir(os.path.join(ROOT_PATH, '.git')): +def run_git_cmd(path, command): + if not os.path.isdir(os.path.join(path, '.git')): return "" try: - sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], - stderr=subprocess.STDOUT).decode('utf-8').strip() - return sha - except FileNotFoundError: - return "" - except subprocess.CalledProcessError: + result = subprocess.check_output( + ['git', '-C', path] + command, + stderr=subprocess.STDOUT + ).decode('utf-8').strip() + return result + except (FileNotFoundError, subprocess.CalledProcessError): return "" def main(): @@ -614,14 +623,20 @@ def main(): global LOGDIR sha = "" - if (sha := get_git_sha()): - sha = "({})" . format(sha[:10]) + if (sha := run_git_cmd(ROOT_PATH, ['rev-parse', 'HEAD'])): + sha = f"({sha[:10]})" cprint(pcolor.yellow, "9PM - Simplicity is the ultimate sophistication {}" . format(sha)) rc = parse_rc(ROOT_PATH) LOGDIR = setup_log_dir(rc['LOG_PATH']) + if 'PARENT_PROJECT_NAME' in rc: + str = f"\nTesting {rc['PARENT_PROJECT_NAME']}" + if 'PARENT_PROJECT_ROOT' in rc: + str += f" ({run_git_cmd(rc['PARENT_PROJECT_ROOT'], ['rev-parse', 'HEAD'])[:12]})" + cprint(pcolor.yellow, str) + args = parse_cmdline() scratch = tempfile.mkdtemp(suffix='', prefix='9pm_', dir='/tmp') diff --git a/etc/9pm.rc b/etc/9pm.rc index 800ba27..6f293c2 100644 --- a/etc/9pm.rc +++ b/etc/9pm.rc @@ -8,3 +8,13 @@ # Default log base path LOG_PATH: "~/.local/share/9pm/logs" + +## Parent Project Settings +# +# Typically 9pm is included as a submodule of a parent project which it tests. + +# Name of the parent project +#PARENT_PROJECT_NAME: "Foobar" + +# The root directory if the parent project, relative to 9pm root. +#PARENT_PROJECT_ROOT: "../"