Python wrapper for running instances of trisurf-ng
Samo Penic
2017-02-21 29660ca63ce9cc5f38a6a99666f0d6fa4f16cd5c
Modified decorator to allow calling a decorator without an argument
1 files modified
11 ■■■■ changed files
trisurf/analyses.py 11 ●●●● patch | view | raw | blame | history
trisurf/analyses.py
@@ -1,17 +1,22 @@
from . import trisurf
def analysis(analysis_name='unnamed_analysis'):
def analysis(*args):
    """Decorator for adding the analysis functions to function lists"""
    def analysis_decorator(analysis_function):
        trisurf._analysis_list[analysis_name]=analysis_function
        def wrapper(*args, **kwargs):
            analysis_function(*args,**kwargs)
        return wrapper
    return analysis_decorator
    if len(args) == 1 and callable(args[0]): #no arguments
        analysis_name=args[0].__name__
        return analysis_decorator(args[0])
    else:
        analysis_name=args[0]
        return analysis_decorator
@analysis('demo')
@analysis
def demo(run, **kwargs):
    host=kwargs.get('host', None)
    print("Demo analysis")