Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and melanieclarke committed Oct 14, 2024
1 parent bd17a90 commit 8ea3bde
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
26 changes: 18 additions & 8 deletions src/stpipe/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,21 @@ def run(self, *args, **kwargs):
self.log.info("Step %s running with args %s.", self.name, args)

# Check for explicit disable for CRDS parameters
if 'disable_crds_steppars' in kwargs:
if "disable_crds_steppars" in kwargs:
disable_crds_steppars = kwargs.pop("disable_crds_steppars")
else:
disable_crds_steppars = True
if self.parent is None and self._validate_kwds:
self.log.warning("CRDS parameter checks are currently disabled by default.")
self.log.warning("In future builds, they will be enabled by default.")
self.log.warning("To turn them on now, set 'disable_crds_steppars' to False "
"in the arguments to 'run'.")
self.log.warning(
"CRDS parameter checks are currently disabled by default."
)
self.log.warning(
"In future builds, they will be enabled by default."
)
self.log.warning(
"To turn them on now, set 'disable_crds_steppars' to False "
"in the arguments to 'run'."
)

# Get parameters from user
parameters = None
Expand All @@ -520,8 +526,10 @@ def run(self, *args, **kwargs):
# Catch steps that cannot build a config
# (e.g. post hooks created from local functions,
# missing input files)
raise ValueError(f"Cannot retrieve CRDS keywords for "
f"{self.name} with input {str(filename)}.")
raise ValueError(
f"Cannot retrieve CRDS keywords for "
f"{self.name} with input {str(filename)}."
)

# Update parameters from the retrieved config + keywords
if parameters:
Expand Down Expand Up @@ -631,7 +639,9 @@ def run(self, *args, **kwargs):

# Run the post hooks
for post_hook in self._post_hooks:
hook_results = post_hook.run(step_result, disable_crds_steppars=True)
hook_results = post_hook.run(
step_result, disable_crds_steppars=True
)
if hook_results is not None:
step_result = hook_results

Expand Down
9 changes: 6 additions & 3 deletions tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_step_run_crds_error(caplog, step_class):

# Call run with an incomplete step implementation, on a file that does
# not exist, without mocking the CRDS retrieval
with pytest.raises(ValueError, match='Cannot retrieve CRDS keywords'):
with pytest.raises(ValueError, match="Cannot retrieve CRDS keywords"):
step.run("science.fits", disable_crds_steppars=False)


Expand Down Expand Up @@ -644,8 +644,11 @@ def test_pipe_run_step_values_from_keywords():
assert pipe.step1._initialized["str1"] is False

# Parameters are set by user
pipe.run("science.fits", steps={"step1": {"str1": "from keywords"}},
disable_crds_steppars=False)
pipe.run(
"science.fits",
steps={"step1": {"str1": "from keywords"}},
disable_crds_steppars=False,
)
assert pipe.step1.str1 == "from keywords"
assert pipe.step1._initialized["str1"] is True

Expand Down

0 comments on commit 8ea3bde

Please sign in to comment.