| 1 |
Metadata-Version: 2.1 |
| 2 |
Name: fscacher |
| 3 |
Version: 0.4.3 |
| 4 |
Summary: Caching results of operations on heavy file trees |
| 5 |
Home-page: https://github.com/con/fscacher |
| 6 |
Author: Center for Open Neuroscience |
| 7 |
Author-email: [email protected] |
| 8 |
Maintainer: John T. Wodder II |
| 9 |
Maintainer-email: [email protected] |
| 10 |
License: MIT |
| 11 |
Project-URL: Source Code, https://github.com/con/fscacher |
| 12 |
Project-URL: Bug Tracker, https://github.com/con/fscacher/issues |
| 13 |
Keywords: caching,file cache |
| 14 |
Classifier: Development Status :: 4 - Beta |
| 15 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 16 |
Classifier: Programming Language :: Python :: 3 |
| 17 |
Classifier: Programming Language :: Python :: 3.9 |
| 18 |
Classifier: Programming Language :: Python :: 3.10 |
| 19 |
Classifier: Programming Language :: Python :: 3.11 |
| 20 |
Classifier: Programming Language :: Python :: 3.12 |
| 21 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 22 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 23 |
Classifier: License :: OSI Approved :: MIT License |
| 24 |
Classifier: Intended Audience :: Developers |
| 25 |
Classifier: Topic :: System :: Filesystems |
| 26 |
Requires-Python: >=3.9 |
| 27 |
Description-Content-Type: text/x-rst |
| 28 |
License-File: LICENSE |
| 29 |
Requires-Dist: joblib~=1.1 |
| 30 |
Requires-Dist: platformdirs |
| 31 |
Provides-Extra: benchmarks |
| 32 |
Requires-Dist: asv[virtualenv]<0.6.2,~=0.6.0; extra == "benchmarks" |
| 33 |
Provides-Extra: devel |
| 34 |
Requires-Dist: asv[virtualenv]<0.6.2,~=0.6.0; extra == "devel" |
| 35 |
Requires-Dist: pre-commit; extra == "devel" |
| 36 |
Provides-Extra: all |
| 37 |
Requires-Dist: asv[virtualenv]<0.6.2,~=0.6.0; extra == "all" |
| 38 |
Requires-Dist: pre-commit; extra == "all" |
| 39 |
|
| 40 |
.. image:: https://github.com/con/fscacher/workflows/Test/badge.svg?branch=master |
| 41 |
:target: https://github.com/con/fscacher/actions?workflow=Test |
| 42 |
:alt: CI Status |
| 43 |
|
| 44 |
.. image:: https://codecov.io/gh/con/fscacher/branch/master/graph/badge.svg |
| 45 |
:target: https://codecov.io/gh/con/fscacher |
| 46 |
|
| 47 |
.. image:: https://img.shields.io/pypi/pyversions/fscacher.svg |
| 48 |
:target: https://pypi.org/project/fscacher/ |
| 49 |
|
| 50 |
.. image:: https://img.shields.io/github/license/con/fscacher.svg |
| 51 |
:target: https://opensource.org/licenses/MIT |
| 52 |
:alt: MIT License |
| 53 |
|
| 54 |
`GitHub <https://github.com/con/fscacher>`_ |
| 55 |
| `PyPI <https://pypi.org/project/fscacher/>`_ |
| 56 |
| `Issues <https://github.com/con/fscacher/issues>`_ |
| 57 |
| `Changelog <https://github.com/con/fscacher/blob/master/CHANGELOG.md>`_ |
| 58 |
|
| 59 |
``fscacher`` provides a cache & decorator for memoizing functions whose outputs |
| 60 |
depend upon the contents of a file argument. |
| 61 |
|
| 62 |
If you have a function ``foo()`` that takes a file path as its first argument, |
| 63 |
and if the behavior of ``foo()`` is pure in the *contents* of the path and the |
| 64 |
values of its other arguments, ``fscacher`` can help cache that function, like |
| 65 |
so: |
| 66 |
|
| 67 |
.. code:: python |
| 68 |
|
| 69 |
from fscacher import PersistentCache |
| 70 |
|
| 71 |
cache = PersistentCache("insert_name_for_cache_here") |
| 72 |
|
| 73 |
@cache.memoize_path |
| 74 |
def foo(path, ...): |
| 75 |
... |
| 76 |
|
| 77 |
Now the outputs of ``foo()`` will be cached for each set of input arguments and |
| 78 |
for a "fingerprint" (timestamps & size) of each ``path``. If ``foo()`` is |
| 79 |
called twice with the same set of arguments, the result from the first call |
| 80 |
will be reused for the second, unless the file pointed to by ``path`` changes, |
| 81 |
in which case the function will be run again. If ``foo()`` is called with a |
| 82 |
non-`path-like object |
| 83 |
<https://docs.python.org/3/glossary.html#term-path-like-object>`_ as the value |
| 84 |
of ``path``, the cache is ignored. |
| 85 |
|
| 86 |
``memoize_path()`` optionally takes an ``exclude_kwargs`` argument, which must |
| 87 |
be a sequence of names of arguments of the decorated function that will be |
| 88 |
ignored for caching purposes. |
| 89 |
|
| 90 |
Caches are stored on-disk and thus persist between Python runs. To clear a |
| 91 |
given ``PersistentCache`` and erase its data store, call the ``clear()`` |
| 92 |
method. |
| 93 |
|
| 94 |
By default, caches are stored in the user-wide cache directory, under an |
| 95 |
fscacher-specific folder, with each one identified by the name passed to the |
| 96 |
constructor (which defaults to "cache" if not specified). To specify a |
| 97 |
different location, use the ``path`` argument to the constructor instead of |
| 98 |
passing a name: |
| 99 |
|
| 100 |
.. code:: python |
| 101 |
|
| 102 |
cache = PersistentCache(path="/my/custom/location") |
| 103 |
|
| 104 |
If your code runs in an environment where different sets of libraries or the |
| 105 |
like could be used in different runs, and these make a difference to the output |
| 106 |
of your function, you can make the caching take them into account by passing a |
| 107 |
list of library version strings or other identifiers for the current run as the |
| 108 |
``token`` argument to the ``PersistentCache`` constructor. |
| 109 |
|
| 110 |
Finally, ``PersistentCache``'s constructor also optionally takes an ``envvar`` |
| 111 |
argument giving the name of an environment variable. If that environment |
| 112 |
variable is set to "``clear``" when the cache is constructed, the cache's |
| 113 |
``clear()`` method will be called at the end of initialization. If the |
| 114 |
environment variable is set to "``ignore``" instead, then caching will be |
| 115 |
disabled, and the cache's ``memoize_path`` method will be a no-op. If the |
| 116 |
given environment variable is not set, or if ``envvar`` is not specified, then |
| 117 |
``PersistentCache`` will query the ``FSCACHER_CACHE`` environment variable |
| 118 |
instead. |
| 119 |
|
| 120 |
|
| 121 |
Installation |
| 122 |
============ |
| 123 |
``fscacher`` requires Python 3.7 or higher. Just use `pip |
| 124 |
<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install it and |
| 125 |
its dependencies:: |
| 126 |
|
| 127 |
python3 -m pip install fscacher |