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

WIP: more cleanup #155

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 5 additions & 44 deletions src/stpipe/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

import yaml

try:
from astropy.io import fits

DISCOURAGED_TYPES = (fits.HDUList,)
except ImportError:
DISCOURAGED_TYPES = None

from . import config, config_parser, crds_client, log, utilities
from .datamodel import AbstractDataModel
from .format_template import FormatTemplate
Expand Down Expand Up @@ -387,21 +380,6 @@
self._pre_hooks = []
self._post_hooks = []

def _check_args(self, args, discouraged_types, msg):
if discouraged_types is None:
return

if type(args) not in (list, tuple):
args = [args]

for i, arg in enumerate(args):
if isinstance(arg, discouraged_types):
self.log.error(
"%s %s object. Use an instance of AbstractDataModel instead.",
msg,
i,
)

@property
def log_records(self):
"""
Expand Down Expand Up @@ -469,10 +447,6 @@

self._reference_files_used = []

# Warn if passing in objects that should be
# discouraged.
self._check_args(args, DISCOURAGED_TYPES, "Passed")

# Run the Step-specific code.
if self.skip:
self.log.info("Step skipped.")
Expand Down Expand Up @@ -529,9 +503,6 @@
) from e
raise

# Warn if returning a discouraged object
self._check_args(step_result, DISCOURAGED_TYPES, "Returned")

# Run the post hooks
for post_hook in self._post_hooks:
hook_results = post_hook.run(step_result)
Expand Down Expand Up @@ -570,22 +541,12 @@
result, (AbstractDataModel | AbstractModelLibrary)
):
self.save_model(result, idx=idx)
elif hasattr(result, "save"):
try:
output_path = self.make_output_path(idx=idx)
except AttributeError:
self.log.warning(
"`save_results` has been requested, but cannot"
" determine filename."
else:
if hasattr(result, "save"):
raise Exception(

Check warning on line 546 in src/stpipe/step.py

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L545-L546

Added lines #L545 - L546 were not covered by tests
f"non-datamodel result with a save: {result}"
)
self.log.warning(
"Specify an output file with `--output_file` or set"
" `--save_results=false`"
)
else:
self.log.info("Saving file %s", output_path)
result.save(output_path, overwrite=True)

# what has "save"? Does anything ever reach this code
if not self.skip:
self.log.info("Step %s done", self.name)
finally:
Expand Down
Loading