From 35161b17b6e710d6cb9e1f161b129076da925523 Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 2 Aug 2023 11:54:01 +0200 Subject: [PATCH 1/8] Move strun script to entry_points --- pyproject.toml | 1 + setup.py | 9 +-------- scripts/strun => src/stpipe/cli/strun.py | 0 3 files changed, 2 insertions(+), 8 deletions(-) rename scripts/strun => src/stpipe/cli/strun.py (100%) diff --git a/pyproject.toml b/pyproject.toml index e95e3e0b..25937350 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ test = [ [project.scripts] stpipe = 'stpipe.cli.main:main' +strun = 'stpipe.cli.strun' [build-system] requires = [ diff --git a/setup.py b/setup.py index 65b6db10..b024da80 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,4 @@ -from pathlib import Path - from setuptools import setup -scripts = [ - str(filename) - for filename in Path("./scripts").glob("**/*") - if filename.is_file() and filename.name != "__pycache__" -] -setup(scripts=scripts) +setup() diff --git a/scripts/strun b/src/stpipe/cli/strun.py similarity index 100% rename from scripts/strun rename to src/stpipe/cli/strun.py From 32e8df3487f7387b327c40a119f5a8c35f15454d Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 23 Aug 2023 11:45:54 +0200 Subject: [PATCH 2/8] Move strun script to entrypoints --- pyproject.toml | 2 +- src/stpipe/cli/strun.py | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 25937350..1dbbdda8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ test = [ [project.scripts] stpipe = 'stpipe.cli.main:main' -strun = 'stpipe.cli.strun' +strun = 'stpipe.cli.strun:main' [build-system] requires = [ diff --git a/src/stpipe/cli/strun.py b/src/stpipe/cli/strun.py index 1d48c160..6ba31fbb 100755 --- a/src/stpipe/cli/strun.py +++ b/src/stpipe/cli/strun.py @@ -1,29 +1,27 @@ -#!/usr/bin/env python - -""" -Run Steps from the command line - -Exit Status ------------ - 0: Step completed satisfactorily - 1: General error occurred - -Other status codes are Step implementation-specific. -""" - import sys from stpipe import Step from stpipe.cli.main import _print_versions from stpipe.exceptions import StpipeExitException -if __name__ == "__main__": + +def main(): + """ + Run Steps from the command line + + Exit Status + ----------- + 0: Step completed satisfactorily + 1: General error occurred + + Other status codes are Step implementation-specific. + """ if "--version" in sys.argv: _print_versions() sys.exit(0) try: - step = Step.from_cmdline(sys.argv[1:]) + Step.from_cmdline(sys.argv[1:]) except StpipeExitException as e: sys.exit(e.exit_status) except Exception: From 9ed44ff8141f0cf1fd32432d6f30da7ed63462b8 Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 23 Aug 2023 11:48:08 +0200 Subject: [PATCH 3/8] Print param default values for strun --help --- src/stpipe/cmdline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stpipe/cmdline.py b/src/stpipe/cmdline.py index 747f995c..d154857d 100644 --- a/src/stpipe/cmdline.py +++ b/src/stpipe/cmdline.py @@ -89,6 +89,7 @@ def build_from_spec(subspec, parts=[]): else: comment = subspec.inline_comments.get(key) or "" comment = comment.lstrip("#").strip() + default_value_string = val.split("(")[1].rstrip(")") argument = "--" + ".".join(parts + [key]) if argument[2:] in built_in_configuration_parameters: raise ValueError( @@ -98,7 +99,7 @@ def build_from_spec(subspec, parts=[]): parser.add_argument( "--" + ".".join(parts + [key]), type=str, - help=comment, + help=f"{comment} [{default_value_string}]", metavar="", ) From 994f257dc0948bf742d5d9f20877e2afef61d037 Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 23 Aug 2023 12:21:10 +0200 Subject: [PATCH 4/8] Only print default value if not None or '' --- src/stpipe/cmdline.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stpipe/cmdline.py b/src/stpipe/cmdline.py index d154857d..5e7c2ebe 100644 --- a/src/stpipe/cmdline.py +++ b/src/stpipe/cmdline.py @@ -89,7 +89,12 @@ def build_from_spec(subspec, parts=[]): else: comment = subspec.inline_comments.get(key) or "" comment = comment.lstrip("#").strip() - default_value_string = val.split("(")[1].rstrip(")") + # Only show default value if it is not None or the empty string + default_value_string = val.split("(")[1].rstrip(")").strip() + if default_value_string.lstrip("default=") in ["None", "''", '""']: + help_string = "" + else: + help_string = f"{comment} [{default_value_string}]" argument = "--" + ".".join(parts + [key]) if argument[2:] in built_in_configuration_parameters: raise ValueError( @@ -99,7 +104,7 @@ def build_from_spec(subspec, parts=[]): parser.add_argument( "--" + ".".join(parts + [key]), type=str, - help=f"{comment} [{default_value_string}]", + help=help_string, metavar="", ) From 4e7157c3d779f86fd38dc03bc6b1b41322dfde53 Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 23 Aug 2023 12:26:26 +0200 Subject: [PATCH 5/8] Move AbstractDataModel test to proper location --- src/stpipe/tests/__init__.py | 0 {src/stpipe/tests => tests}/test_abstract_datamodel.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 src/stpipe/tests/__init__.py rename {src/stpipe/tests => tests}/test_abstract_datamodel.py (96%) diff --git a/src/stpipe/tests/__init__.py b/src/stpipe/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/stpipe/tests/test_abstract_datamodel.py b/tests/test_abstract_datamodel.py similarity index 96% rename from src/stpipe/tests/test_abstract_datamodel.py rename to tests/test_abstract_datamodel.py index 6303ca66..803cf62c 100644 --- a/src/stpipe/tests/test_abstract_datamodel.py +++ b/tests/test_abstract_datamodel.py @@ -4,7 +4,7 @@ import pytest -from ..step import AbstractDataModel +from stpipe.datamodel import AbstractDataModel def test_roman_datamodel(): From ff19d1c5d57db31b694a9215c135ae07ea8a51ae Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 23 Aug 2023 12:39:59 +0200 Subject: [PATCH 6/8] Add back param comment for defaults with None --- src/stpipe/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stpipe/cmdline.py b/src/stpipe/cmdline.py index 5e7c2ebe..34fe9e30 100644 --- a/src/stpipe/cmdline.py +++ b/src/stpipe/cmdline.py @@ -92,7 +92,7 @@ def build_from_spec(subspec, parts=[]): # Only show default value if it is not None or the empty string default_value_string = val.split("(")[1].rstrip(")").strip() if default_value_string.lstrip("default=") in ["None", "''", '""']: - help_string = "" + help_string = comment else: help_string = f"{comment} [{default_value_string}]" argument = "--" + ".".join(parts + [key]) From d8cda74d41eb3ddcf357c4dc6660d5f83b549e95 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:42:29 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index b024da80..60684932 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ from setuptools import setup - setup() From a0b9463798368606717de76ee0569af956b5a344 Mon Sep 17 00:00:00 2001 From: James Davies Date: Wed, 23 Aug 2023 13:07:08 +0200 Subject: [PATCH 8/8] Update changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index bcac8582..36523ef3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,8 @@ ================== - Print out ``jwst`` or ``romancal`` versions from ``strun --version``. [#98] +- Print default parameter values for ``strun --help`` [#101] +- Move ``strun`` to entrypoints [#101] 0.5.0 (2023-04-19) ==================