Skip to content
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

remove fits extension assumption for hooks #217

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/217.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow hooks to save to non-fits files.
1 change: 0 additions & 1 deletion src/stpipe/function_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class FunctionWrapper(Step):
"""

spec = """
output_ext = string(default="fits")
"""

def __init__(self, func, *args, **kwargs):
Expand Down
15 changes: 10 additions & 5 deletions src/stpipe/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def hook_from_string(step, hooktype, num, command):
step_class = None
step_func = None

# transfer output_ext to hooks
kwargs = dict(output_ext=step.output_ext)

# hook is a string of the fully-qualified name of a class or function
if isinstance(command, str):
try:
Expand All @@ -52,28 +55,30 @@ def hook_from_string(step, hooktype, num, command):
# Then convert rest of string to args and instantiate the class
kwargs_string = params.strip(")")
expr = ast.parse(f"dict({kwargs_string}\n)", mode="eval")
kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.body.keywords}
kwargs.update(
{kw.arg: ast.literal_eval(kw.value) for kw in expr.body.keywords}
)
return step_class(**kwargs)
except TypeError:
# String points to a function
step_func = utilities.import_func(command)
else:
if step_class.class_alias is not None:
name = step_class.class_alias
return step_class(name, parent=step, config_file=step.config_file)
return step_class(name, parent=step, config_file=step.config_file, **kwargs)

# hook is a string of the fully-qualified name of a function
if step_func is not None:
return function_wrapper.FunctionWrapper(
step_func, parent=step, config_file=step.config_file
step_func, parent=step, config_file=step.config_file, **kwargs
)

# hook is an already-imported Step subclass
if inspect.isclass(command) and issubclass(command, Step):
step_class = command
if step_class.class_alias is not None:
name = step_class.class_alias
return step_class(name, parent=step, config_file=step.config_file)
return step_class(name, parent=step, config_file=step.config_file, **kwargs)

# hook is an instance of a Step subclass
if isinstance(command, Step):
Expand All @@ -86,7 +91,7 @@ def hook_from_string(step, hooktype, num, command):
# hook is a command-line script or system call
from .subproc import SystemCall

return SystemCall(name, parent=step, command=command)
return SystemCall(name, parent=step, command=command, **kwargs)


def get_hook_objects(step, hooktype, hooks):
Expand Down
1 change: 0 additions & 1 deletion src/stpipe/subproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class SystemCall(Step):
log_stderr = boolean(default=True) # Do we want to log STDERR?
exitcode_as_exception = boolean(default=True) # Should a non-zero exit code be converted into an exception?
failure_as_exception = boolean(default=True) # If subprocess fails to run at all, should that be an exception?
output_ext = string(default="fits")
""" # noqa: E501

def process(self, *args):
Expand Down
Loading