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 Oct 9, 2024
1 parent ecd5d16 commit 919e5a2
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:

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

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L480

Added line #L480 was not covered by tests

def set_skipped(model):
try:
setattr(

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

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L482-L484

Added lines #L482 - L484 were not covered by tests
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):

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

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L494-L496

Added lines #L494 - L496 were not covered by tests
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]]

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

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L498

Added line #L498 was not covered by tests
else:
set_skipped(args[0])

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

View check run for this annotation

Codecov / codecov/patch

src/stpipe/step.py#L500

Added line #L500 was not covered by tests
step_result = args[0]
else:
if self.prefetch_references:
Expand Down

0 comments on commit 919e5a2

Please sign in to comment.