This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cache_result(cache_file, param_in_suffix=None, root_dir=None): | |
""" | |
decorator function to cache function's return value (assume returned value can be pickled) | |
the cached file with be located to root_dir/[_param-key_param-value,]/cache_file.pkl | |
usage: | |
@cache_result(cache_file_name,param_in_suffix=[param_key],) | |
def function_to_create_cache(): | |
.... | |
:param root_dir: dir to store the cache if the wrapped function has root_dir as a param, the value will be used instead |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
a lazy wrapper to export python function directly as command line interface with one line of code | |
""" | |
import click | |
from functools import wraps, partial | |
import inspect | |
def get_prefix(key: str, prefix_set: set): |
OlderNewer