-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix pre- and post-hooks #133
Fix pre- and post-hooks #133
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #133 +/- ##
==========================================
+ Coverage 59.33% 68.76% +9.43%
==========================================
Files 24 24
Lines 1618 1652 +34
==========================================
+ Hits 960 1136 +176
+ Misses 658 516 -142 ☔ View full report in Codecov by Sentry. |
@hbushouse this is the promised PR to make pre- and post-hooks work within python instead of just with the
|
JWST regtests run at: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1148/ roman regtests ran with no errors: https://plwishmaster.stsci.edu:8081/job/RT/job/Roman-Developers-Pull-Requests/551/ |
604842f
to
4c0b1ad
Compare
I just tried out this PR and ran into a couple of issues; unknown if this is user error or a problem with the code itself. Defining a custom step 'XplyStep' this works ok if the code for the step is in a different file in the same directory as my notebook, but defining the step within the notebook itself still fails. 2024-02-26 10:13:37,678 - stpipe.Spec2Pipeline.assign_wcs.post_hook0 - INFO - Spawning 'xply.XplyStep' Looks like something isn't linking up quite right. |
Thanks for giving it a spin @drlaw1558. Could you show the cells of your code? If you define a step in one cell: class XplyStep(Step):
class_alias = "xply"
def process(self, input_data):
return input_data Then the way to use it later as a hook, is directly: steps = dict(
assign_wcs = dict(
post_hooks = [
XplyStep,
],
),
)
result = Spec2Pipeline.call(input_data, steps=steps) No need to pass it as |
Ah, that was it. I'd removed the xply., but I also needed to remove the quotes. I.e., dict = {"assign_wcs": {"post_hooks": ["XplyStep"]}} Looks good to me then, and the logging functionality is now working too. |
Yes, the quotes are what was originally needed if you have a module called |
fbe2ccf
to
8c50694
Compare
Any chance of this getting a review? From a user perspective, it would be really nice to have this improved |
from .step import Step | ||
|
||
|
||
def hook_from_string(step, type, num, command): # noqa: A002 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be deprecated instead of removed? It looks like it's been available for a long time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not removed, I've renamed the hook_from_string()
function to hook_from_string_or_class()
to better describe what it actually does. Happy to change the name back if you think this will affect the public API. Since this is all internal workings, I would rather make all this private, including the whole hooks.py
module, but happy to maintain backwards compat.
If not maintaining backwards compat, maybe "hook_from_object()` would be a better function name.
stpipe
suffers from a lot of its internal workings, such as Step.run()
, being public functions.
As far as I can tell, a search of Github doesn't turn up any uses of stpipe.hooks
outside of stpipe
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone ahead and changed the function name back to its original name, and just clarified in the docstring what it does. We can revisit moving public functions and methods to be private in a future refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! And I agree it's unlikely anyone uses it.
@jdavies-st I think this looks good - other than the one comment I have. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
8c50694
to
c2810ea
Compare
Once this is merged and stpipe 0.6.0 is released, I'll go ahead and update the docs in |
Regression tests pass again. |
from .step import Step | ||
|
||
|
||
def hook_from_string(step, type, num, command): # noqa: A002 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! And I agree it's unlikely anyone uses it.
@jdavies-st Please ping me on the JWST PR. |
Currently pre- and post-hooks only work as strings pointing to importable Step subclasses. This made sense back when the foreseen use case of the pipeline was with
strun
at the command line, where all args are strings.This PR fixes hooks to work with our current use cases. It adds the possibility of using a defined function or defined
Step
subclass as hook, or an instance with parameters set of aStep
subclass. And it tests all the cases.So now a hook can be a list of a number of useful things, not just a list of strings.
Hooks before:
With this PR, we can also now use the following as hooks:
Also added an extra CI job that runs the unit tests with some downstream dependencies. There's always been tests in this package that depend on
stdatamodels
androman_datamodels
, but these have been skipped since the recent-ish github actions workflow updates, and subsequently theroman_datamodels
test had a broken import. I've chosen to test the hooks withjwst
as an optional test dependency, as that's the lowest overhead way to do it without having to create a bunch of redundant test infrastructure.