From 1ade3a6ea6f976cf017373c27d3d74c3c1f41949 Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Thu, 11 Jan 2018 12:37:52 +0100 Subject: [PATCH] Removed joblib.cached-sphinx workaround / Caching fix - sphinx detection is not reliable, e.g. jupyter notebooks have sphinx imported at startup -> no caching from notebooks - explicitly added cached functions via autofunction to docs - some functions do not support memory cache, because memory cache can't handle non-hashable parameters -> introduced diskcacheNoFallback decorator for these functions --- cache.py | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/cache.py b/cache.py index 78a7c56a8..261e76231 100644 --- a/cache.py +++ b/cache.py @@ -15,36 +15,9 @@ try: else: cacheDir = user_cache_dir('pystencils') diskcache = Memory(cachedir=cacheDir, verbose=False).cache + diskcacheNoFallback = diskcache except ImportError: # fallback to in-memory caching if joblib is not available diskcache = memorycache(maxsize=64) + diskcacheNoFallback = lambda o: o - -# joblibs Memory decorator does not play nicely with sphinx autodoc (decorated functions do not occur in autodoc) -# -> if this script is imported by sphinx we use functools instead -import sys -calledBySphinx = 'sphinx' in sys.modules -if calledBySphinx: - diskcache = memorycache(maxsize=64) - - -# ------------------------ Helper classes to JSON serialize sympy objects ---------------------------------------------- - - -class SympyJSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, sp.Basic): - return {"_type": "sp", "str": str(obj)} - else: - super(SympyJSONEncoder, self).default(obj) - - -class SympyJSONDecoder(json.JSONDecoder): - def __init__(self, *args, **kwargs): - json.JSONDecoder.__init__(self, object_hook=self.object_hook, *args, **kwargs) - - def object_hook(self, obj): - if '_type' in obj: - return sp.sympify(obj['str']) - else: - return obj \ No newline at end of file -- GitLab