neurotools.jobs.ndecorator module
- Robust decorators are provided by the decorator package
- neurotools.jobs.ndecorator.listit(t)[source]
Converts nested tuple to nested list
- Parameters:
t (tuple, list, or object) – If tuple or list, will recursively apply listit
- neurotools.jobs.ndecorator.tupleit(t)[source]
Recursively convert nested iteable to nested tuple.
- Parameters:
t (iterable)
- Returns:
result
- Return type:
tuple
- neurotools.jobs.ndecorator.sanitize(sig, mode='liberal')[source]
Recursively convert an argument signature into a standard format. Lists will be converted to tuples. Non-hashable types will cause an error.
“strict” mode requires data be numeric primitives or strings containing “very safe” chracters
a-zA-Z0-9
and space.- Parameters:
sig (nested tuple) – Result of calling argument_signature(),
- Returns:
sig
- Return type:
nested tuple
- neurotools.jobs.ndecorator.summarize_function(f)[source]
Prints function information, Used for debugging decorators.
- Parameters:
f (function)
- neurotools.jobs.ndecorator.argument_signature(function, *args, **kwargs)[source]
Convert the function arguments and values to a unique tuple. Throws ValueError if the provided arguments cannot match the function’s argspec.
- Parameters:
function (function) – Function fo create signature for
*args (iterable) – Arguments for function
**kwwargs (dict) – Keyword arguments for function
- Returns:
sig
- Return type:
tuple
- neurotools.jobs.ndecorator.print_signature(sig)[source]
Formats the argument signature for printing.
- Parameters:
sig (tuple) – Tuple returned by argument_signature()
- Return type:
str
- neurotools.jobs.ndecorator.timed(f, *args, **kwargs)[source]
Timer decorator: Modifies a function to reutrn a tuple of (runtime, result).
- Parameters:
f (function)
*args (iterable) – Arguments for f
**kwargs (dict) – Keyword arguments for f
- Returns:
time_taken (int) – Time taken for the function call, in milliseconds
result – Return value of f(*args,**kwargs)
- neurotools.jobs.ndecorator.clear_memoized(verbose=False)[source]
Clear the caches of all memoized functions
- Parameters:
verbose (boolean; default False) – Print extra debugging information?
- neurotools.jobs.ndecorator.memoize(f)[source]
Memoization decorator
- Parameters:
f (function)
- Returns:
Memoize-decorated function
- Return type:
function
- neurotools.jobs.ndecorator.unwrap(f)[source]
Strips decorators from a decorated function, provided that the decorators were so kind as to set the .__wrapped__ attribute
- Parameters:
f (function) – Decorated function to unpack
- Returns:
g – Base function obtained by recursively looking for the attribute __wrapped__ in function f, which stores the original (undecorated) function for functions modified by the decorators in ndecorator.
- Return type:
function