Skip to content

Commit 67ee789

Browse files
committed
Add wrapper for pydra tasks, in order to eliminate pydra requirement
1 parent 6c9a6d2 commit 67ee789

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

physutils/tasks.py

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
11
import logging
2+
from functools import wraps
23

3-
import pydra
4+
from loguru import logger
45

56
from physutils.io import load_from_bids, load_physio
67
from physutils.physio import Physio
78

89
LGR = logging.getLogger(__name__)
910
LGR.setLevel(logging.DEBUG)
1011

12+
try:
13+
import pydra
1114

12-
@pydra.mark.task
15+
pydra_imported = True
16+
except ImportError:
17+
logger.warning(
18+
"Pydra is not installed, so the physutils tasks are not available as pydra tasks"
19+
)
20+
LGR.warning(
21+
"Pydra is not installed, so the physutils tasks are not available as pydra tasks"
22+
)
23+
pydra_imported = False
24+
25+
26+
def mark_task(pydra_imported=pydra_imported):
27+
def decorator(func):
28+
if pydra_imported:
29+
# If the decorator exists, apply it
30+
@wraps(func)
31+
def wrapped_func(*args, **kwargs):
32+
return pydra.mark.task(func)(*args, **kwargs)
33+
34+
return wrapped_func
35+
# Otherwise, return the original function
36+
logger.warning(
37+
"Pydra is not installed, so {} is not available as a pydra task".format(
38+
func.__name__
39+
)
40+
)
41+
LGR.warning(
42+
"Pydra is not installed, so {} is not available as a pydra task".format(
43+
func.__name__
44+
)
45+
)
46+
return func
47+
48+
return decorator
49+
50+
51+
@mark_task(pydra_imported=pydra_imported)
1352
def transform_to_physio(
1453
input_file: str, mode="physio", fs=None, bids_parameters=dict(), bids_channel=None
1554
) -> Physio:

0 commit comments

Comments
 (0)