Skip to content

Commit

Permalink
standardize setattr use in skip
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Nov 12, 2024
1 parent 677f6a4 commit a3ff55e
Showing 1 changed file with 21 additions and 39 deletions.
60 changes: 21 additions & 39 deletions src/stpipe/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,46 +476,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(

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

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L487-L488

Added lines #L487 - L488 were not covered by tests
"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 a3ff55e

Please sign in to comment.