Skip to content

Commit

Permalink
remove fits extension assumption for hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Jan 23, 2025
1 parent 02840fe commit 6f5cdb1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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

0 comments on commit 6f5cdb1

Please sign in to comment.