Skip to content

Commit

Permalink
standardize setattr use in skip (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Dec 4, 2024
2 parents 37245d7 + a2a8d46 commit cc174e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
1 change: 1 addition & 0 deletions changes/195.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix cal_step setting when a step is skipped for roman datamodels.
60 changes: 21 additions & 39 deletions src/stpipe/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,46 +477,28 @@ def run(self, *args):
# Run the Step-specific code.
if self.skip:
self.log.info("Step skipped.")
if isinstance(args[0], AbstractModelLibrary):
library = args[0]
with library:
for i, model in enumerate(library):
try:
setattr(
model.meta.cal_step, self.class_alias, "SKIPPED"
)
except AttributeError as e:
self.log.info(
"Could not record skip into DataModel "
"header: %s",
e,
)
library.shelve(model, i)
elif isinstance(args[0], AbstractDataModel):
if self.class_alias is not None:

if self.class_alias is not None:

def set_skipped(model):
try:
setattr(
model.meta.cal_step, self.class_alias, "SKIPPED"
)
except AttributeError as e:
self.log.info(
"Could not record skip into DataModel "
"header: %s",
e,
)

if isinstance(args[0], AbstractModelLibrary):
list(args[0].map_function(lambda m, i: set_skipped(m)))
elif isinstance(args[0], AbstractDataModel):
if isinstance(args[0], Sequence):
for model in args[0]:
try:
model[f"meta.cal_step.{self.class_alias}"] = (
"SKIPPED"
)
except AttributeError as e: # noqa: PERF203
self.log.info(
"Could not record skip into DataModel "
"header: %s",
e,
)
elif isinstance(args[0], AbstractDataModel):
try:
args[0][
f"meta.cal_step.{self.class_alias}"
] = "SKIPPED"
except AttributeError as e:
self.log.info(
"Could not record skip into DataModel"
" header: %s",
e,
)
[set_skipped(m) for m in args[0]]
else:
set_skipped(args[0])
step_result = args[0]
else:
if self.prefetch_references:
Expand Down

0 comments on commit cc174e4

Please sign in to comment.