diff --git a/arfx/core.py b/arfx/core.py index 4828263..741f6e7 100644 --- a/arfx/core.py +++ b/arfx/core.py @@ -20,6 +20,7 @@ import logging import os import sys +from functools import cache import arf import h5py as h5 @@ -367,10 +368,8 @@ def copy_entries(tgt, files, **options): from h5py import Group - from .tools import memoized - ebase = options.get("template", None) - acache = memoized(arf.open_file) + acache = cache(arf.open_file) with arf.open_file(tgt, "a") as arfp: arf.check_file_version(arfp) @@ -381,8 +380,8 @@ def copy_entries(tgt, files, **options): # on windows, dir\file.arf/entry is an entry pn, fn = pp.split(f) if os.path.isfile(f): - it = ((f, entry) for ename, entry in acache(f).items()) - elif os.path.isfile(pn): + it = ((f, entry) for ename, entry in acache(f, mode="r").items()) + elif os.path.isfile(pn, mode="r"): fp = acache(pn) if fn in fp: it = ((pn, fp[fn]),) diff --git a/arfx/tools.py b/arfx/tools.py deleted file mode 100644 index 018dcd0..0000000 --- a/arfx/tools.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# -*- mode: python -*- -""" General programming tools """ -import collections -import functools - - -class memoized(object): - """Memoizing decorator. Caches a function's return value each time it is called. - If called later with the same arguments, the cached value is returned - instead of evaluating the function. - """ - - def __init__(self, func): - self.func = func - self.cache = {} - functools.update_wrapper(self, func) - - def __call__(self, *args): - if not isinstance(args, collections.Hashable): - # uncacheable. a list, for instance. - # better to not cache than blow up. - return self.func(*args) - if args in self.cache: - return self.cache[args] - else: - value = self.func(*args) - self.cache[args] = value - return value - - def __repr__(self): - """Return the function's docstring.""" - return self.func.__doc__ - - def __get__(self, obj, objtype): - """Support instance methods.""" - return functools.partial(self.__call__, obj) diff --git a/uv.lock b/uv.lock index 7e0bde2..fd09169 100644 --- a/uv.lock +++ b/uv.lock @@ -27,7 +27,7 @@ wheels = [ [[package]] name = "arfx" -version = "2.7.0" +version = "2.7.1" source = { editable = "." } dependencies = [ { name = "arf" },