Skip to content

Commit

Permalink
Add wrapper for pydra tasks, in order to eliminate pydra requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
maestroque committed Sep 3, 2024
1 parent 6c9a6d2 commit 67ee789
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions physutils/tasks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
import logging
from functools import wraps

import pydra
from loguru import logger

from physutils.io import load_from_bids, load_physio
from physutils.physio import Physio

LGR = logging.getLogger(__name__)
LGR.setLevel(logging.DEBUG)

try:
import pydra

@pydra.mark.task
pydra_imported = True
except ImportError:
logger.warning(
"Pydra is not installed, so the physutils tasks are not available as pydra tasks"
)
LGR.warning(
"Pydra is not installed, so the physutils tasks are not available as pydra tasks"
)
pydra_imported = False


def mark_task(pydra_imported=pydra_imported):
def decorator(func):
if pydra_imported:
# If the decorator exists, apply it
@wraps(func)
def wrapped_func(*args, **kwargs):
return pydra.mark.task(func)(*args, **kwargs)

return wrapped_func
# Otherwise, return the original function
logger.warning(
"Pydra is not installed, so {} is not available as a pydra task".format(
func.__name__
)
)
LGR.warning(
"Pydra is not installed, so {} is not available as a pydra task".format(
func.__name__
)
)
return func

return decorator


@mark_task(pydra_imported=pydra_imported)
def transform_to_physio(
input_file: str, mode="physio", fs=None, bids_parameters=dict(), bids_channel=None
) -> Physio:
Expand Down

0 comments on commit 67ee789

Please sign in to comment.