Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print default values for strun --help #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
==================

- Print out ``jwst`` or ``romancal`` versions from ``strun --version``. [#98]
- Print default parameter values for ``strun <step_alias> --help`` [#101]
- Move ``strun`` to entrypoints [#101]

0.5.0 (2023-04-19)
==================
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test = [

[project.scripts]
stpipe = 'stpipe.cli.main:main'
strun = 'stpipe.cli.strun:main'

[build-system]
requires = [
Expand Down
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 13 additions & 15 deletions scripts/strun → src/stpipe/cli/strun.py
Original file line number Diff line number Diff line change
@@ -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():

Check warning on line 8 in src/stpipe/cli/strun.py

View check run for this annotation

Codecov / codecov/patch

src/stpipe/cli/strun.py#L8

Added line #L8 was not covered by tests
"""
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:])

Check warning on line 24 in src/stpipe/cli/strun.py

View check run for this annotation

Codecov / codecov/patch

src/stpipe/cli/strun.py#L24

Added line #L24 was not covered by tests
except StpipeExitException as e:
sys.exit(e.exit_status)
except Exception:
Expand Down
8 changes: 7 additions & 1 deletion src/stpipe/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -98,7 +104,7 @@ def build_from_spec(subspec, parts=[]):
parser.add_argument(
"--" + ".".join(parts + [key]),
type=str,
help=comment,
help=help_string,
metavar="",
)

Expand Down
Empty file removed src/stpipe/tests/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from ..step import AbstractDataModel
from stpipe.datamodel import AbstractDataModel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been meaning to move this test module outside of src. Thanks



def test_roman_datamodel():
Expand Down