<commit_before>import os
import functools
import inspect
import codecs
import pickle

from . import utils


class Memozo(object):

    def __init__(self, path='./'):
        self.base_path = path

    def __call__(self, name=None, ext='file'):

        def wrapper(func):
            _name = func.__name__ if name is None else name

            @functools.wraps(func)
            def _wrapper(*args, **kwargs):
                args = utils.get_bound_args(func, *args, **kwargs)
                args_str = utils.get_args_str(args)
                sha1 = utils.get_hash(_name, func.__name__, args_str)
                file_path = os.path.join(self.base_path, "{}_{}.{}".format(_name, sha1, ext))

                if os.path.exists(file_path):
                    with open(file_path, 'r') as f:
                        obj = f.readlines()
                    return obj

                obj = func(*args, **kwargs)

                with open(file_path, 'w') as f:
                    f.writelines(obj)

                return obj

            return _wrapper

        return wrapper<commit_msg>write log to .memozo<commit_after>import os
import functools
import inspect
import codecs
import pickle

from . import utils


class Memozo(object):

    def __init__(self, path='./'):
        self.base_path = path

    def __call__(self, name=None, ext='file'):

        def wrapper(func):
            _name = func.__name__ if name is None else name

            @functools.wraps(func)
            def _wrapper(*args, **kwargs):
                args = utils.get_bound_args(func, *args, **kwargs)
                args_str = utils.get_args_str(args)
                sha1 = utils.get_hash(_name, func.__name__, args_str)
                file_path = os.path.join(self.base_path, "{}_{}.{}".format(_name, sha1, ext))

                if os.path.exists(file_path):
                    with open(file_path, 'r') as f:
                        obj = f.readlines()
                    return obj

                obj = func(*args, **kwargs)

                with open(file_path, 'w') as f:
                    f.writelines(obj)
                utils.write(self.base_path, _name, func.__name__, args_str)

                return obj

            return _wrapper

        return wrapper
{'fraction_non_alphanumeric': 0.10542567269519189, 'fraction_numerical': 0.00176444640494045, 'mean_word_length': 1.668235294117647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3660635', 'n_tokens_mistral': 679, 'n_tokens_neox': 638, 'n_words': 164}