Skip to content

Commit

Permalink
9pm.rc: add parent project concept
Browse files Browse the repository at this point in the history
Add the ability to specify info about the parent project. I.e. the
project being tested by 9pm. It's called "parent" because 9pm is
normally included as a submodule to the project it's testing.

Signed-off-by: Richard Alpe <[email protected]>
  • Loading branch information
rical committed Dec 17, 2024
1 parent ce2d0cd commit fda3ab4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
35 changes: 25 additions & 10 deletions 9pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand All @@ -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')
Expand Down
10 changes: 10 additions & 0 deletions etc/9pm.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"

0 comments on commit fda3ab4

Please sign in to comment.