From 280137e496d135999a85e74efa69b86b6ade88f6 Mon Sep 17 00:00:00 2001 From: Michael McKinsey Date: Mon, 14 Jul 2025 10:19:00 -0700 Subject: [PATCH 1/5] print usage if 'benchpark' --- lib/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.py b/lib/main.py index 01d404292..576326db3 100755 --- a/lib/main.py +++ b/lib/main.py @@ -16,7 +16,7 @@ if "-V" in sys.argv or "--version" in sys.argv: print(__version__) exit() -helpstr = """usage: main.py [-h] [-V] {tags,system,experiment,setup,unit-test,audit,info,list} ... +helpstr = """usage: benchpark [-h] [-V] {tags,system,experiment,setup,unit-test,audit,info,list} ... Benchpark @@ -36,7 +36,7 @@ list List experiments, systems, benchmarks, and modifiers bootstrap Bootstrap benchpark or update an existing bootstrap analyze Perform pre-defined analysis on the performance data (caliper files) after 'ramble on'""" -if "-h" == sys.argv[1] or "--help" == sys.argv[1]: +if len(sys.argv) == 1 or "-h" == sys.argv[1] or "--help" == sys.argv[1]: print(helpstr) exit() From d8ab03839a651e446c955d46b0669ebd478a7b56 Mon Sep 17 00:00:00 2001 From: Michael McKinsey Date: Mon, 14 Jul 2025 10:50:02 -0700 Subject: [PATCH 2/5] Update help str --- lib/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/main.py b/lib/main.py index 576326db3..1d7273940 100755 --- a/lib/main.py +++ b/lib/main.py @@ -16,7 +16,7 @@ if "-V" in sys.argv or "--version" in sys.argv: print(__version__) exit() -helpstr = """usage: benchpark [-h] [-V] {tags,system,experiment,setup,unit-test,audit,info,list} ... +helpstr = """usage: main.py [-h] [-V] {tags,system,experiment,setup,unit-test,audit,mirror,info,show-build,list,bootstrap,analyze} ... Benchpark @@ -25,14 +25,16 @@ -V, --version show version number and exit Subcommands: - {tags,system,experiment,setup,unit-test,audit,info,list} + {tags,system,experiment,setup,unit-test,audit,mirror,info,show-build,list,bootstrap,analyze} tags Tags in Benchpark experiments system Initialize a system config experiment Interact with experiments setup Set up an experiment and prepare it to build/run unit-test Run benchpark unit tests audit Look for problems in System/Experiment repos + mirror Copy a benchpark workspace info Get information about Systems and Experiments + show-build Show how spack built a benchmark list List experiments, systems, benchmarks, and modifiers bootstrap Bootstrap benchpark or update an existing bootstrap analyze Perform pre-defined analysis on the performance data (caliper files) after 'ramble on'""" From 8ebb14576202ec216d25b23d686c19e92ab94003 Mon Sep 17 00:00:00 2001 From: Michael McKinsey Date: Mon, 14 Jul 2025 10:50:55 -0700 Subject: [PATCH 3/5] configure subcommands to print usage instead of potentially confusing error --- lib/benchpark/cmd/experiment.py | 8 +++----- lib/benchpark/cmd/info.py | 4 +--- lib/benchpark/cmd/list.py | 3 +-- lib/benchpark/cmd/mirror.py | 6 +++--- lib/benchpark/cmd/show_build.py | 8 +++----- lib/benchpark/cmd/system.py | 6 +++--- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/benchpark/cmd/experiment.py b/lib/benchpark/cmd/experiment.py index 007ff7ee1..ecf9d3555 100644 --- a/lib/benchpark/cmd/experiment.py +++ b/lib/benchpark/cmd/experiment.py @@ -39,7 +39,9 @@ def experiment_init(args): def setup_parser(root_parser): - system_subparser = root_parser.add_subparsers(dest="experiment_subcommand") + system_subparser = root_parser.add_subparsers( + dest="experiment_subcommand", required=True + ) init_parser = system_subparser.add_parser("init") init_parser.add_argument("--dest", help="Place all system files here directly") @@ -56,7 +58,3 @@ def command(args): } if args.experiment_subcommand in actions: actions[args.experiment_subcommand](args) - else: - raise ValueError( - f"Unknown subcommand for 'experiment': {args.experiment_subcommand}" - ) diff --git a/lib/benchpark/cmd/info.py b/lib/benchpark/cmd/info.py index 51adce7b7..0f092ee2c 100644 --- a/lib/benchpark/cmd/info.py +++ b/lib/benchpark/cmd/info.py @@ -188,7 +188,7 @@ def _info_ramble_name(experiment_class): def setup_parser(root_parser): - info_subparser = root_parser.add_subparsers(dest="info_subcommand") + info_subparser = root_parser.add_subparsers(dest="info_subcommand", required=True) system_parser = info_subparser.add_parser("system") system_parser.add_argument( @@ -227,5 +227,3 @@ def command(args): } if args.info_subcommand in actions: actions[args.info_subcommand](args) - else: - raise ValueError(f"Unknown subcommand for 'info': {args.info_subcommand}") diff --git a/lib/benchpark/cmd/list.py b/lib/benchpark/cmd/list.py index 12aaaf20c..9228356a0 100644 --- a/lib/benchpark/cmd/list.py +++ b/lib/benchpark/cmd/list.py @@ -81,6 +81,7 @@ def setup_parser(root_parser): list_subparser = root_parser.add_subparsers( dest="list_subcommand", help="List available experiments, systems, and modifiers", + required=True, ) # Add subcommands @@ -131,5 +132,3 @@ def command(args): } if args.list_subcommand in actions: actions[args.list_subcommand](args) - else: - raise ValueError(f"Unknown subcommand for 'list': {args.list_subcommand}") diff --git a/lib/benchpark/cmd/mirror.py b/lib/benchpark/cmd/mirror.py index 4014fe567..e31dd68cb 100644 --- a/lib/benchpark/cmd/mirror.py +++ b/lib/benchpark/cmd/mirror.py @@ -224,7 +224,9 @@ def _ignore(path, dir_list): def setup_parser(root_parser): - mirror_subparser = root_parser.add_subparsers(dest="system_subcommand") + mirror_subparser = root_parser.add_subparsers( + dest="system_subcommand", required=True + ) create_parser = mirror_subparser.add_parser("create") create_parser.add_argument( @@ -242,5 +244,3 @@ def command(args): } if args.system_subcommand in actions: actions[args.system_subcommand](args) - else: - raise ValueError(f"Unknown subcommand for 'system': {args.system_subcommand}") diff --git a/lib/benchpark/cmd/show_build.py b/lib/benchpark/cmd/show_build.py index 40435edf0..cc5d2a694 100644 --- a/lib/benchpark/cmd/show_build.py +++ b/lib/benchpark/cmd/show_build.py @@ -65,7 +65,9 @@ def show_build_dump(args): def setup_parser(root_parser): - show_build_subparser = root_parser.add_subparsers(dest="show_build_subcommand") + show_build_subparser = root_parser.add_subparsers( + dest="show_build_subcommand", required=True + ) dump_parser = show_build_subparser.add_parser("dump") dump_parser.add_argument( @@ -81,7 +83,3 @@ def command(args): } if args.show_build_subcommand in actions: actions[args.show_build_subcommand](args) - else: - raise ValueError( - f"Unknown subcommand for 'show-build': {args.show_build_subcommand}" - ) diff --git a/lib/benchpark/cmd/system.py b/lib/benchpark/cmd/system.py index 374b8c9d3..2d2b60514 100644 --- a/lib/benchpark/cmd/system.py +++ b/lib/benchpark/cmd/system.py @@ -110,7 +110,9 @@ def system_external(args): def setup_parser(root_parser): - system_subparser = root_parser.add_subparsers(dest="system_subcommand") + system_subparser = root_parser.add_subparsers( + dest="system_subcommand", required=True + ) init_parser = system_subparser.add_parser("init") init_parser.add_argument("--dest", help="Place all system files here directly") @@ -143,5 +145,3 @@ def command(args): } if args.system_subcommand in actions: actions[args.system_subcommand](args) - else: - raise ValueError(f"Unknown subcommand for 'system': {args.system_subcommand}") From 34c8339a9c48e3c2e35e12e8fe68b787d3a4a01c Mon Sep 17 00:00:00 2001 From: Michael McKinsey Date: Mon, 14 Jul 2025 11:15:48 -0700 Subject: [PATCH 4/5] Check already downstream in main.py --- bin/benchpark | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/benchpark b/bin/benchpark index 81fe2fd82..32b39a43d 100755 --- a/bin/benchpark +++ b/bin/benchpark @@ -12,8 +12,6 @@ import sys def main(): - if sys.version_info[0] < 3 or sys.version_info[1] < 8: - raise Exception("\n\nERR: Must be using Python 3.8 or later!\n") basedir = pathlib.Path(__file__).resolve().parents[1] main_py = basedir / "lib" / "main.py" subprocess.run([sys.executable, main_py] + sys.argv[1:], check=True) From 5bc3ec5abc5f1e0c4f6faceb70200417d7a592af Mon Sep 17 00:00:00 2001 From: Michael McKinsey Date: Mon, 14 Jul 2025 11:23:18 -0700 Subject: [PATCH 5/5] Run without subprocess --- bin/benchpark | 9 ++++----- lib/main.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/benchpark b/bin/benchpark index 32b39a43d..bc5c53f0f 100755 --- a/bin/benchpark +++ b/bin/benchpark @@ -11,11 +11,10 @@ import subprocess import sys -def main(): - basedir = pathlib.Path(__file__).resolve().parents[1] - main_py = basedir / "lib" / "main.py" - subprocess.run([sys.executable, main_py] + sys.argv[1:], check=True) +basedir = pathlib.Path(__file__).resolve().parents[1] +sys.path.insert(0, str(basedir) + "/lib") +from main import main if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/lib/main.py b/lib/main.py index 1d7273940..1318e1139 100755 --- a/lib/main.py +++ b/lib/main.py @@ -16,7 +16,7 @@ if "-V" in sys.argv or "--version" in sys.argv: print(__version__) exit() -helpstr = """usage: main.py [-h] [-V] {tags,system,experiment,setup,unit-test,audit,mirror,info,show-build,list,bootstrap,analyze} ... +helpstr = """usage: benchpark [-h] [-V] {tags,system,experiment,setup,unit-test,audit,mirror,info,show-build,list,bootstrap,analyze} ... Benchpark