Skip to content

Commit

Permalink
JP-3728: Deprecate Step.__call__ (#8761)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Sep 26, 2024
1 parent e8ba844 commit 163ad08
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions changes/8761.stpipe.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add warning that ``Step.__call__`` is deprecated.
6 changes: 3 additions & 3 deletions jwst/extract_2d/tests/test_grisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_create_box_fits():
# Add fake data to pass a shape to wfss_imaging_wcs
im.data = np.zeros((512, 512))
aswcs = AssignWcsStep()
imwcs = aswcs(im)
imwcs = aswcs.run(im)
imwcs.meta.source_catalog = source_catalog
refs = get_reference_files(im)
test_boxes = create_grism_bbox(imwcs, refs,
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_create_box_gwcs():
# The data array is not relevant
im.data = np.zeros((512, 512))
aswcs = AssignWcsStep()
imwcs = aswcs(im)
imwcs = aswcs.run(im)
imwcs.meta.source_catalog = source_catalog
refs = get_reference_files(im)
test_boxes = create_grism_bbox(imwcs, refs,
Expand All @@ -268,7 +268,7 @@ def setup_image_cat():
im.data = np.zeros((512, 512))
im.meta.source_catalog = source_catalog
aswcs = AssignWcsStep()
imwcs = aswcs(im)
imwcs = aswcs.run(im)
refs = get_reference_files(im)

return imwcs, refs
Expand Down
14 changes: 14 additions & 0 deletions jwst/stpipe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from functools import wraps
import logging
import warnings

from stdatamodels.jwst.datamodels import JwstDataModel
from stdatamodels.jwst import datamodels
Expand Down Expand Up @@ -102,6 +103,19 @@ def run(self, *args, **kwargs):
log.info(f"Results used jwst version: {__version__}")
return result

@wraps(Step.__call__)
def __call__(self, *args, **kwargs):
if not self.parent:
warnings.warn(
"Step.__call__ is deprecated. It is equivalent to Step.run "
"and is not recommended. See "
"https://jwst-pipeline.readthedocs.io/en/latest/jwst/"
"user_documentation/running_pipeline_python.html"
"#advanced-use-pipeline-run-vs-pipeline-call for more details.",
UserWarning
)
return super().__call__(*args, **kwargs)


# JwstPipeline needs to inherit from Pipeline, but also
# be a subclass of JwstStep so that it will pass checks
Expand Down
6 changes: 6 additions & 0 deletions jwst/stpipe/tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,9 @@ def test_finalize_logging(monkeypatch):
monkeypatch.setattr(logging.getLogger("jwst.stpipe.core"), "info", watcher)
pipeline.run(model)
assert watcher.seen


def test_dunder_call_warning():
pipeline = EmptyPipeline()
with pytest.warns(UserWarning, match="Step.__call__ is deprecated"):
pipeline(None)
8 changes: 4 additions & 4 deletions jwst/tweakreg/tests/test_tweakreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_tweakreg_step(example_input, with_shift):
step = tweakreg_step.TweakRegStep()

# run the step on the example input modified above
result = step(example_input)
result = step.run(example_input)

# check that step completed
with result:
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_src_confusion_pars(example_input, alignment_type):
"abs_refcat": REFCAT,
}
step = tweakreg_step.TweakRegStep(**pars)
result = step(example_input)
result = step.run(example_input)

# check that step was skipped
with result:
Expand Down Expand Up @@ -356,7 +356,7 @@ def patched_construct_wcs_corrector(wcs, wcsinfo, catalog, group_id, _seen=[]):
monkeypatch.setattr(twk, "construct_wcs_corrector", patched_construct_wcs_corrector)

with pytest.raises(ValueError, match="done testing"):
step(str(asn_path))
step.run(str(asn_path))


@pytest.mark.parametrize("with_shift", [True, False])
Expand Down Expand Up @@ -384,7 +384,7 @@ def test_sip_approx(example_input, with_shift):
step.sip_npoints = 12

# run the step on the example input modified above
result = step(example_input)
result = step.run(example_input)

with result:
r0 = result.borrow(0)
Expand Down

0 comments on commit 163ad08

Please sign in to comment.