joblib/joblib — pull request #129 by gcr (2014-04-14 12:58:41+00:00)
Title: Optionally key functions by a hash of their source code (includes docs,tests)

Joblib's default behavior is to delete all of the cached results of a function when its source code or line number changes. Further, two identical functions that appear in different source files are considered to be different. This behavior is annoying if a function is under active development, or if multiple machines have the same function checked out in different filesystem paths.

This patch adds an optional argument to the `Memory()` constructor, `func_key_mode`, which allows the user to select alternate behavior. When `func_key_mode="code"`, functions are **keyed by a hash of their source code**, instead of just their name and filesystem path.

Benefits:
========
- If a function changes, results are now saved to a different place, but the old results are still available if the function's definition changes back.
- Avoids aliasing issues and better handles name conflicts
- Filesystem-agnostic. Compute clusters can run `/opt/experiment/run.py` while the developer runs `/home/gcr/experiment/run.py`, but the developer can reuse the cluster's cached results.

What's included?
==============
- This optional behavior, turned off by default (so it doesn't interfere with existing joblib users)
- Docs (I don't know how to build them though) and docstrings
- Unit tests

This patch is extremely useful to me. I hope it can be included in mainline! :)

I hereby assign copyright of this patch to the joblib developers.