Skip to content
Snippets Groups Projects
Commit 1ade3a6e authored by Martin Bauer's avatar Martin Bauer
Browse files

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
parent ce63537a
Branches
Tags
No related merge requests found
......@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment