From 024932fa20e35899039ad27f15d226c423ffd03d Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Mon, 11 Jan 2021 17:34:22 -0500 Subject: [PATCH 1/2] Add mockup of idea for CLI --- cli-mockup/stpipe | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 cli-mockup/stpipe diff --git a/cli-mockup/stpipe b/cli-mockup/stpipe new file mode 100755 index 00000000..140eea04 --- /dev/null +++ b/cli-mockup/stpipe @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import argparse + + +def parse_args(): + parser = argparse.ArgumentParser("stpipe", description="stpipe CLI") + parser.add_argument("-v", "--version", help="print version information and exit", action="store_true") + + subparsers = parser.add_subparsers(dest="command", title="commands", required=True) + + pipeline_parser = subparsers.add_parser("pipeline", help="operate on pipelines", description="operate on pipelines") + pipeline_subparsers = pipeline_parser.add_subparsers(dest="subcommand", title="command", required=True) + + pipeline_describe_parser = pipeline_subparsers.add_parser("describe", help="describe a pipeline", description="describe a pipeline") + pipeline_describe_parser.add_argument("pipeline-class", help="pipeline class name") + + pipeline_list_parser = pipeline_subparsers.add_parser("list", help="list available pipelines", description="list available pipelines") + pipeline_list_parser.add_argument("pattern", help="(optional) restrict pipelines to glob pattern", nargs="?") + + pipeline_run_parser = pipeline_subparsers.add_parser("run", help="run a pipeline", description="run a pipeline") + pipeline_run_parser.add_argument("pipeline-class", help="pipeline class name") + + step_parser = subparsers.add_parser("step", help="operate on steps", description="operate on steps") + step_subparsers = step_parser.add_subparsers(dest="subcommand", title="command", required=True) + + step_describe_parser = step_subparsers.add_parser("describe", help="describe a step", description="describe a step") + + step_list_parser = step_subparsers.add_parser("list", help="list available steps", description="list available steps") + step_list_parser.add_argument("pattern", help="(optional) restrict steps to glob pattern", nargs="?") + + step_run_parser = step_subparsers.add_parser("run", help="run a step", description="run a step") + step_run_parser.add_argument("step-class", help="step class name") + + return parser.parse_args() + + +def main(): + args = parse_args() + + +if __name__ == "__main__": + main() From dd66feb9807542d44565c0459c2525c5b67f9c18 Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Mon, 25 Jan 2021 16:56:21 -0500 Subject: [PATCH 2/2] Merge step and pipeline subcommands and flesh out argument lists --- cli-mockup/stpipe | 117 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 23 deletions(-) diff --git a/cli-mockup/stpipe b/cli-mockup/stpipe index 140eea04..5156763d 100755 --- a/cli-mockup/stpipe +++ b/cli-mockup/stpipe @@ -4,32 +4,103 @@ import argparse def parse_args(): parser = argparse.ArgumentParser("stpipe", description="stpipe CLI") - parser.add_argument("-v", "--version", help="print version information and exit", action="store_true") + parser.add_argument("-V", "--version", help="print version information and exit", action="store_true") subparsers = parser.add_subparsers(dest="command", title="commands", required=True) - pipeline_parser = subparsers.add_parser("pipeline", help="operate on pipelines", description="operate on pipelines") - pipeline_subparsers = pipeline_parser.add_subparsers(dest="subcommand", title="command", required=True) - - pipeline_describe_parser = pipeline_subparsers.add_parser("describe", help="describe a pipeline", description="describe a pipeline") - pipeline_describe_parser.add_argument("pipeline-class", help="pipeline class name") - - pipeline_list_parser = pipeline_subparsers.add_parser("list", help="list available pipelines", description="list available pipelines") - pipeline_list_parser.add_argument("pattern", help="(optional) restrict pipelines to glob pattern", nargs="?") - - pipeline_run_parser = pipeline_subparsers.add_parser("run", help="run a pipeline", description="run a pipeline") - pipeline_run_parser.add_argument("pipeline-class", help="pipeline class name") - - step_parser = subparsers.add_parser("step", help="operate on steps", description="operate on steps") - step_subparsers = step_parser.add_subparsers(dest="subcommand", title="command", required=True) - - step_describe_parser = step_subparsers.add_parser("describe", help="describe a step", description="describe a step") - - step_list_parser = step_subparsers.add_parser("list", help="list available steps", description="list available steps") - step_list_parser.add_argument("pattern", help="(optional) restrict steps to glob pattern", nargs="?") - - step_run_parser = step_subparsers.add_parser("run", help="run a step", description="run a step") - step_run_parser.add_argument("step-class", help="step class name") + describe_epilog = """ +examples: + print step description and parameters: + + stpipe describe jwst.step.RampFitStep + + increase verbosity to include parameters for nested steps: + + stpipe describe --verbose jwst.pipeline.Detector1Pipeline + """.strip() + + describe_parser = subparsers.add_parser( + "describe", + description="describe a step or pipeline", + epilog=describe_epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + help="describe a step or pipeline", + ) + describe_parser.add_argument("class", metavar="", help="step or pipeline class name (case-insensitive, module path may be omitted for unique class names)") + describe_parser.add_argument("-v", "--verbose", action="store_true", default=False, help="verbose output") + + list_epilog = """ +examples: + list available pipeline classes: + + stpipe list + + list pipelines and steps: + + stpipe list --all + + list steps in the jwst package: + + stpipe list --steps-only jwst.* + """.strip() + list_parser = subparsers.add_parser( + "list", + epilog=list_epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + description="list available classes", + help="list available classes", + ) + list_parser.add_argument("pattern", metavar="", help="restrict classes to glob pattern (case-insensitive)", nargs="?") + list_parser.add_argument("--all", help="list both step and pipeline classes", action="store_true", default=False) + list_parser.add_argument("--steps-only", help="list only step classes", action="store_true", default=False) + + print_epilog = """ +examples: + save a pipeline config to a local file: + + stpipe print-config jwst.pipeline.Detector1Pipeline dataset.fits > config.asdf + """.strip() + print_parser = subparsers.add_parser( + "print-config", + description="print step or pipeline config to stdout", + epilog=print_epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + help="print step or pipeline config to stdout", + ) + print_parser.add_argument("class", metavar="", help="step or pipeline class name (case-insensitive, module path may be omitted for unique class names)") + print_parser.add_argument("input-file", metavar="", help="input dataset or association (used to fetch parameters from CRDS)") + + run_epilog = """ +examples: + run a pipeline with default parameters recommended by CRDS: + + stpipe run jwst.pipeline.Detector1Pipeline dataset.fits + + run a pipeline with parameters specified in a local config: + + stpipe run --config config.asdf jwst.pipeline.Detector1Pipeline dataset.fits + + override an individual pipeline parameter: + + stpipe run -p save_calibrated_ramp=true jwst.pipeline.Detector1Pipeline dataset.fits + + override an individual step parameter: + + stpipe run -p jump.rejection_threshold=3.0 jwst.pipeline.Detector1Pipeline dataset.fits + """ + run_parser = subparsers.add_parser( + "run", + description="run a step or pipeline", + epilog=run_epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + help="run a step or pipeline", + ) + run_parser.add_argument("class", metavar="", help="step or pipeline class name (case-insensitive, module path may be omitted for unique class names)") + run_parser.add_argument("input-file", metavar="", help="input dataset or association") + run_parser.add_argument("--config", metavar="", help="config file (use 'stpipe print-config' to save and edit the default config)") + run_parser.add_argument("-d", "--debug", action="store_true", help="debug logging (DEBUG level)") + run_parser.add_argument("-p", metavar="=", help="override an individual step or pipeline parameter (use 'stpipe describe' to list available parameters)") + run_parser.add_argument("-v", "--verbose", action="store_true", help="verbose logging (INFO level)") return parser.parse_args()