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) ================== diff --git a/pyproject.toml b/pyproject.toml index e95e3e0b..1dbbdda8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ test = [ [project.scripts] stpipe = 'stpipe.cli.main:main' +strun = 'stpipe.cli.strun:main' [build-system] requires = [ diff --git a/setup.py b/setup.py index 65b6db10..60684932 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,3 @@ -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 57% rename from scripts/strun rename to src/stpipe/cli/strun.py index 1d48c160..6ba31fbb 100755 --- a/scripts/strun +++ 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: diff --git a/src/stpipe/cmdline.py b/src/stpipe/cmdline.py index 747f995c..34fe9e30 100644 --- a/src/stpipe/cmdline.py +++ b/src/stpipe/cmdline.py @@ -89,6 +89,12 @@ def build_from_spec(subspec, parts=[]): else: comment = subspec.inline_comments.get(key) or "" comment = comment.lstrip("#").strip() + # 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 = comment + else: + help_string = f"{comment} [{default_value_string}]" argument = "--" + ".".join(parts + [key]) if argument[2:] in built_in_configuration_parameters: raise ValueError( @@ -98,7 +104,7 @@ def build_from_spec(subspec, parts=[]): parser.add_argument( "--" + ".".join(parts + [key]), type=str, - help=comment, + help=help_string, metavar="", ) 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():