Skip to content

Commit e97a078

Browse files
committed
9pm.py: increase verbosity when looking for configs
Debugging what configs are used is typically time consuming in large projects. This aims to speed up the process. Signed-off-by: Richard Alpe <[email protected]>
1 parent d307c5e commit e97a078

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

9pm.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,15 @@ def run_suite(args, data, skip_suite):
566566

567567
return skip, err
568568

569+
def get_first_existing_file(list, name):
570+
for f in list:
571+
if os.path.exists(os.path.expanduser(f)):
572+
return f
573+
vcprint(pcolor.faint, f"({name} not found: {f})")
574+
575+
print("error, can't find any {name} to use")
576+
sys.exit(1)
577+
569578
def parse_proj_config(root_path, args):
570579
files = [
571580
os.path.join(root_path, '..', '9pm-proj.yaml'),
@@ -575,21 +584,12 @@ def parse_proj_config(root_path, args):
575584
if "NINEPM_PROJ_CONFIG" in os.environ:
576585
files.insert(0, os.environ["NINEPM_PROJ_CONFIG"])
577586

578-
path = next((os.path.expanduser(f) for f in files if os.path.exists(os.path.expanduser(f))), None)
579-
580587
if args.proj:
581-
if not os.path.exists(args.proj):
582-
print(f"error, config file \"{args.proj}\" not found.")
583-
sys.exit(1)
588+
files.insert(0, args.proj)
584589

585-
path = args.proj
586-
587-
if path:
588-
vcprint(pcolor.faint, f"Using project config: {path}")
589-
os.environ["NINEPM_PROJ_CONFIG"] = path
590-
else:
591-
print("error, can't find any 9pm project config")
592-
sys.exit(1)
590+
path = get_first_existing_file(files, "Project Config")
591+
vcprint(pcolor.faint, f"Using project config: {path}")
592+
os.environ["NINEPM_PROJ_CONFIG"] = path
593593

594594
try:
595595
with open(path, 'r') as f:
@@ -616,13 +616,9 @@ def parse_rc(root_path, args):
616616
os.path.join("~/.9pm.rc"),
617617
os.path.join(root_path, 'etc', '9pm.rc')
618618
]
619-
path = next((os.path.expanduser(f) for f in files if os.path.exists(os.path.expanduser(f))), None)
620619

621-
if path:
622-
vcprint(pcolor.faint, f"Using RC: {path}")
623-
else:
624-
print("error, can't find any 9pm.rc file")
625-
sys.exit(1)
620+
path = get_first_existing_file(files, "Running Config")
621+
vcprint(pcolor.faint, f"Using RC: {path}")
626622

627623
try:
628624
with open(path, 'r') as f:

0 commit comments

Comments
 (0)