@@ -45,6 +45,38 @@ def safe_import(*args):
4545 return mod
4646
4747
48+ def check_dependency (dep , name ):
49+ """Decorator that checks if an optional dependency is available.
50+
51+ Parameters
52+ ----------
53+ dep : module or False
54+ Module, if successfully imported, or boolean (False) if not.
55+ name : str
56+ Full name of the module, to be printed in message.
57+
58+ Returns
59+ -------
60+ wrap : callable
61+ The decorated function.
62+
63+ Raises
64+ ------
65+ ImportError
66+ If the requested dependency is not available.
67+ """
68+
69+ def wrap (func ):
70+ @wraps (func )
71+ def wrapped_func (* args , ** kwargs ):
72+ if not dep :
73+ raise ImportError ("Optional FOOOF dependency " + name + \
74+ " is required for this functionality." )
75+ return func (* args , ** kwargs )
76+ return wrapped_func
77+ return wrap
78+
79+
4880def docs_drop_param (docstring ):
4981 """Drop the first parameter description for a string representation of a docstring.
5082
@@ -148,35 +180,3 @@ def wrapper(func):
148180 return func
149181
150182 return wrapper
151-
152-
153- def check_dependency (dep , name ):
154- """Decorator that checks if an optional dependency is available.
155-
156- Parameters
157- ----------
158- dep : module or False
159- Module, if successfully imported, or boolean (False) if not.
160- name : str
161- Full name of the module, to be printed in message.
162-
163- Returns
164- -------
165- wrap : callable
166- The decorated function.
167-
168- Raises
169- ------
170- ImportError
171- If the requested dependency is not available.
172- """
173-
174- def wrap (func ):
175- @wraps (func )
176- def wrapped_func (* args , ** kwargs ):
177- if not dep :
178- raise ImportError ("Optional FOOOF dependency " + name + \
179- " is required for this functionality." )
180- return func (* args , ** kwargs )
181- return wrapped_func
182- return wrap
0 commit comments