cachier 3.0.0__py3-none-any.whl → 3.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cachier/__main__.py CHANGED
@@ -7,7 +7,7 @@ from cachier.core import _set_max_workers
7
7
 
8
8
  @click.group()
9
9
  def cli():
10
- """A command-line interface for cachier."""
10
+ """A command-line interface for cachier.""" # noqa: D401
11
11
 
12
12
 
13
13
  @cli.command("Limits the number of worker threads used by cachier.")
cachier/config.py CHANGED
@@ -17,6 +17,8 @@ def _default_hash_func(args, kwds):
17
17
 
18
18
 
19
19
  class Params(TypedDict):
20
+ """Type definition for cachier parameters."""
21
+
20
22
  caching_enabled: bool
21
23
  hash_func: HashFunc
22
24
  backend: Backend
cachier/core.py CHANGED
@@ -118,7 +118,7 @@ def cachier(
118
118
  wait_for_calc_timeout: Optional[int] = None,
119
119
  allow_none: Optional[bool] = None,
120
120
  ):
121
- """A persistent, stale-free memoization decorator.
121
+ """Wrap as a persistent, stale-free memoization decorator.
122
122
 
123
123
  The positional and keyword arguments to the wrapped function must be
124
124
  hashable (i.e. Python's immutable built-in objects, not mutable
@@ -127,13 +127,14 @@ def cachier(
127
127
  value is their id), equal objects across different sessions will not yield
128
128
  identical keys.
129
129
 
130
- Arguments
130
+ Arguments:
131
131
  ---------
132
132
  hash_func : callable, optional
133
133
  A callable that gets the args and kwargs from the decorated function
134
134
  and returns a hash key for them. This parameter can be used to enable
135
135
  the use of cachier with functions that get arguments that are not
136
136
  automatically hashable by Python.
137
+ hash_params : callable, optional
137
138
  backend : str, optional
138
139
  The name of the backend to use. Valid options currently include
139
140
  'pickle', 'mongo' and 'memory'. If not provided, defaults to
@@ -244,8 +245,12 @@ def cachier(
244
245
  if verbose:
245
246
  _print = print
246
247
  if ignore_cache or not _default_params["caching_enabled"]:
247
- return func(**kwargs)
248
- key, entry = core.get_entry(tuple(), kwargs)
248
+ return (
249
+ func(args[0], **kwargs)
250
+ if core.func_is_method
251
+ else func(**kwargs)
252
+ )
253
+ key, entry = core.get_entry((), kwargs)
249
254
  if overwrite_cache:
250
255
  return _calc_entry(core, key, func, args, kwds)
251
256
  if entry is None:
@@ -294,17 +299,17 @@ def cachier(
294
299
  core.clear_cache()
295
300
 
296
301
  def _clear_being_calculated():
297
- """Marks all entries in this cache as not being calculated."""
302
+ """Mark all entries in this cache as not being calculated."""
298
303
  core.clear_being_calculated()
299
304
 
300
305
  def _cache_dpath():
301
- """Returns the path to the cache dir, if exists; None if not."""
306
+ """Return the path to the cache dir, if exists; None if not."""
302
307
  return getattr(core, "cache_dir", None)
303
308
 
304
- def _precache_value(*args, value_to_cache, **kwds):
309
+ def _precache_value(*args, value_to_cache, **kwds): # noqa: D417
305
310
  """Add an initial value to the cache.
306
311
 
307
- Arguments
312
+ Arguments:
308
313
  ---------
309
314
  value_to_cache : any
310
315
  entry to be written into the cache
@@ -314,7 +319,7 @@ def cachier(
314
319
  kwargs = _convert_args_kwargs(
315
320
  func, _is_method=core.func_is_method, args=args, kwds=kwds
316
321
  )
317
- return core.precache_value(tuple(), kwargs, value_to_cache)
322
+ return core.precache_value((), kwargs, value_to_cache)
318
323
 
319
324
  func_wrapper.clear_cache = _clear_cache
320
325
  func_wrapper.clear_being_calculated = _clear_being_calculated
cachier/cores/base.py CHANGED
@@ -16,6 +16,8 @@ from ..config import _update_with_defaults
16
16
 
17
17
 
18
18
  class RecalculationNeeded(Exception):
19
+ """Exception raised when a recalculation is needed."""
20
+
19
21
  pass
20
22
 
21
23
 
@@ -32,7 +34,7 @@ class _BaseCore:
32
34
  self.lock = threading.RLock()
33
35
 
34
36
  def set_func(self, func):
35
- """Sets the function this core will use.
37
+ """Set the function this core will use.
36
38
 
37
39
  This has to be set before any method is called. Also determine if the
38
40
  function is an object method.
@@ -46,17 +48,21 @@ class _BaseCore:
46
48
  self.func = func
47
49
 
48
50
  def get_key(self, args, kwds):
49
- """Returns a unique key based on the arguments provided."""
51
+ """Return a unique key based on the arguments provided."""
50
52
  return self.hash_func(args, kwds)
51
53
 
52
54
  def get_entry(self, args, kwds):
53
- """Returns the result mapped to the given arguments in this core's
54
- cache, if such a mapping exists."""
55
+ """Get entry based on given arguments.
56
+
57
+ Return the result mapped to the given arguments in this core's cache,
58
+ if such a mapping exists.
59
+
60
+ """
55
61
  key = self.get_key(args, kwds)
56
62
  return self.get_entry_by_key(key)
57
63
 
58
64
  def precache_value(self, args, kwds, value_to_cache):
59
- """Writes a precomputed value into the cache."""
65
+ """Write a precomputed value into the cache."""
60
66
  key = self.get_key(args, kwds)
61
67
  self.set_entry(key, value_to_cache)
62
68
  return value_to_cache
@@ -71,30 +77,33 @@ class _BaseCore:
71
77
 
72
78
  @abc.abstractmethod
73
79
  def get_entry_by_key(self, key):
74
- """Returns the result mapped to the given key in this core's cache, if
75
- such a mapping exists."""
80
+ """Get entry based on given key.
81
+
82
+ Return the result mapped to the given key in this core's cache, if such
83
+ a mapping exists.
84
+
85
+ """
76
86
 
77
87
  @abc.abstractmethod
78
88
  def set_entry(self, key, func_res):
79
- """Maps the given result to the given key in this core's cache."""
89
+ """Map the given result to the given key in this core's cache."""
80
90
 
81
91
  @abc.abstractmethod
82
92
  def mark_entry_being_calculated(self, key):
83
- """Marks the entry mapped by the given key as being calculated."""
93
+ """Mark the entry mapped by the given key as being calculated."""
84
94
 
85
95
  @abc.abstractmethod
86
96
  def mark_entry_not_calculated(self, key):
87
- """Marks the entry mapped by the given key as not being calculated."""
97
+ """Mark the entry mapped by the given key as not being calculated."""
88
98
 
89
99
  @abc.abstractmethod
90
100
  def wait_on_entry_calc(self, key):
91
- """Waits on the entry mapped by key being calculated and returns
92
- result."""
101
+ """Wait on the entry with keys being calculated and returns result."""
93
102
 
94
103
  @abc.abstractmethod
95
104
  def clear_cache(self):
96
- """Clears the cache of this core."""
105
+ """Clear the cache of this core."""
97
106
 
98
107
  @abc.abstractmethod
99
108
  def clear_being_calculated(self):
100
- """Marks all entries in this cache as not being calculated."""
109
+ """Mark all entries in this cache as not being calculated."""
cachier/cores/mongo.py CHANGED
@@ -41,8 +41,9 @@ class _MongoCore(_BaseCore):
41
41
  ):
42
42
  if "pymongo" not in sys.modules:
43
43
  warnings.warn(
44
- "Cachier warning: pymongo was not found. "
45
- "MongoDB cores will not function."
44
+ "`pymongo` was not found. MongoDB cores will not function.",
45
+ ImportWarning,
46
+ stacklevel=2,
46
47
  ) # pragma: no cover
47
48
 
48
49
  super().__init__(hash_func, wait_for_calc_timeout)
cachier/cores/pickle.py CHANGED
@@ -62,11 +62,11 @@ class _PickleCore(_BaseCore):
62
62
  self.observer.stop()
63
63
 
64
64
  def on_created(self, event):
65
- """A Watchdog Event Handler method."""
65
+ """A Watchdog Event Handler method.""" # noqa: D401
66
66
  self._check_calculation() # pragma: no cover
67
67
 
68
68
  def on_modified(self, event):
69
- """A Watchdog Event Handler method."""
69
+ """A Watchdog Event Handler method.""" # noqa: D401
70
70
  self._check_calculation()
71
71
 
72
72
  def __init__(
@@ -115,9 +115,9 @@ class _PickleCore(_BaseCore):
115
115
  self._reload_cache()
116
116
  return self.cache
117
117
 
118
- def _get_cache_by_key(self, key=None, hash=None):
118
+ def _get_cache_by_key(self, key=None, hash_str=None):
119
119
  fpath = self.cache_fpath
120
- fpath += f"_{key}" if hash is None else f"_{hash}"
120
+ fpath += f"_{hash_str or key}"
121
121
  try:
122
122
  with portalocker.Lock(fpath, mode="rb") as cache_file:
123
123
  return pickle.load(cache_file) # noqa: S301
@@ -134,17 +134,17 @@ class _PickleCore(_BaseCore):
134
134
  path, name = os.path.split(self.cache_fpath)
135
135
  for subpath in os.listdir(path):
136
136
  if subpath.startswith(name):
137
- entry = self._get_cache_by_key(hash=subpath.split("_")[-1])
137
+ entry = self._get_cache_by_key(hash_str=subpath.split("_")[-1])
138
138
  if entry is not None:
139
139
  entry["being_calculated"] = False
140
- self._save_cache(entry, hash=subpath.split("_")[-1])
140
+ self._save_cache(entry, hash_str=subpath.split("_")[-1])
141
141
 
142
- def _save_cache(self, cache, key=None, hash=None):
142
+ def _save_cache(self, cache, key=None, hash_str=None):
143
143
  fpath = self.cache_fpath
144
144
  if key is not None:
145
145
  fpath += f"_{key}"
146
- elif hash is not None:
147
- fpath += f"_{hash}"
146
+ elif hash_str is not None:
147
+ fpath += f"_{hash_str}"
148
148
  with self.lock:
149
149
  self.cache = cache
150
150
  with portalocker.Lock(fpath, mode="wb") as cache_file:
cachier/version.info CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.0.1
@@ -1,33 +1,50 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cachier
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Persistent, stale-free, local and cross-machine caching for Python functions.
5
- Home-page: https://github.com/python-cachier/cachier
6
- Author: Shay Palachy & al.
7
- Author-email: shay.palachy@gmail.com
8
- License: MIT
9
- Keywords: cache,persistence,mongo,memoization,decorator
10
- Platform: linux
11
- Platform: osx
12
- Platform: windows
5
+ Author-email: Shay Palachy Affek <shay.palachy@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2016 Shay Palachy
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Source, https://github.com/python-cachier/cachier
29
+ Keywords: cache,caching,cross-machine,decorator,local,memoization,mongo,persistent
13
30
  Classifier: Development Status :: 4 - Beta
31
+ Classifier: Intended Audience :: Developers
14
32
  Classifier: License :: OSI Approved :: MIT License
15
33
  Classifier: Programming Language :: Python
16
- Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3 :: Only
17
35
  Classifier: Programming Language :: Python :: 3.8
18
36
  Classifier: Programming Language :: Python :: 3.9
19
37
  Classifier: Programming Language :: Python :: 3.10
20
38
  Classifier: Programming Language :: Python :: 3.11
21
39
  Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Topic :: Other/Nonlisted Topic
22
41
  Classifier: Topic :: Software Development :: Libraries
23
42
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
43
  Classifier: Topic :: Utilities
25
- Classifier: Topic :: Other/Nonlisted Topic
26
- Classifier: Intended Audience :: Developers
44
+ Description-Content-Type: text/x-rst
27
45
  License-File: LICENSE
28
- Requires-Dist: watchdog >=2.3.1
29
- Requires-Dist: portalocker >=2.3.2
30
- Requires-Dist: setuptools >=67.6.0
46
+ Requires-Dist: portalocker>=2.3.2
47
+ Requires-Dist: watchdog>=2.3.1
31
48
 
32
49
  Cachier
33
50
  #######
@@ -492,8 +509,8 @@ Notable bugfixers:
492
509
  .. |PyPI-Versions| image:: https://img.shields.io/pypi/pyversions/cachier.svg
493
510
  :target: https://pypi.python.org/pypi/cachier
494
511
 
495
- .. |Build-Status| image:: https://github.com/python-cachier/cachier/actions/workflows/test.yml/badge.svg
496
- :target: https://github.com/python-cachier/cachier/actions/workflows/test.yml
512
+ .. |Build-Status| image:: https://github.com/python-cachier/cachier/actions/workflows/ci-test.yml/badge.svg
513
+ :target: https://github.com/python-cachier/cachier/actions/workflows/ci-test.yml
497
514
 
498
515
  .. |LICENCE| image:: https://img.shields.io/pypi/l/cachier.svg
499
516
  :target: https://pypi.python.org/pypi/cachier
@@ -0,0 +1,19 @@
1
+ cachier/__init__.py,sha256=6i43oFM_ZTp47b6R8Ws2vvf2JXLvbn-TKzWESwBDb-M,304
2
+ cachier/__main__.py,sha256=upg-TlHs1vngKYvkjoPpl3Pvl6xOx4ut-M1mElMiAo0,443
3
+ cachier/_types.py,sha256=EGJMiw-oCIC_cDLyzw7YC40lfo8jnD3zMmoJpA9Y8Iw,238
4
+ cachier/_version.py,sha256=yE6UYwvdoIRpw3HmNifiGwV3fqVea5PwZj_EvyosiZ8,1079
5
+ cachier/config.py,sha256=JJutAeOlNjDobNWKteTvcvdj_Pfemk6_dMKIGFtW6UM,2754
6
+ cachier/core.py,sha256=x0I-Ot2dt7wThu2j8iLXPYvv8exwp4xXMUQIQyImr64,13261
7
+ cachier/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ cachier/version.info,sha256=BuP-SnoYhNINgcxwZcqM_Uw5TsYCxNGA3cObvU99pSE,6
9
+ cachier/cores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ cachier/cores/base.py,sha256=i6xlR3Em_s6rVER5Uyf1kK86KcaWtb84iKwS9bgDZGI,3465
11
+ cachier/cores/memory.py,sha256=JFXnXBAeP0nOXOf_vNgpcEuRNjxre8WQjiUBa7yEYmY,3128
12
+ cachier/cores/mongo.py,sha256=Ez3SNZzAzELO9c_SrGlOX855-5UEPBViabWPjkQnFc0,4917
13
+ cachier/cores/pickle.py,sha256=fVajLzlhUkQ9ochLWAZnDQQZJPXj0lWl7mgalI-z2x0,8903
14
+ cachier-3.0.1.dist-info/LICENSE,sha256=-2WrMJkIa0gVP6YQHXXDT7ws-S3M2NEVEF4XF3K8qrY,1069
15
+ cachier-3.0.1.dist-info/METADATA,sha256=JZCfPStwVwwhYrdvT_Vkmm2FrfqYc2rUGtExGh86DGI,20102
16
+ cachier-3.0.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
17
+ cachier-3.0.1.dist-info/entry_points.txt,sha256=x4Y7t6Y0Qev_3fgG-Jv7TrsvVdJty3FnGAdkT8-_5mY,49
18
+ cachier-3.0.1.dist-info/top_level.txt,sha256=_rW_HiJumDCch67YT-WAgzcyvKg5RiYDMZq9d-0ZpaE,8
19
+ cachier-3.0.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ cachier = cachier.__main__:cli
@@ -1,19 +0,0 @@
1
- cachier/__init__.py,sha256=6i43oFM_ZTp47b6R8Ws2vvf2JXLvbn-TKzWESwBDb-M,304
2
- cachier/__main__.py,sha256=g8dgovKdDgOMgNIpnmzVRuI5Dj5xODTav45TpZlH_iA,429
3
- cachier/_types.py,sha256=EGJMiw-oCIC_cDLyzw7YC40lfo8jnD3zMmoJpA9Y8Iw,238
4
- cachier/_version.py,sha256=yE6UYwvdoIRpw3HmNifiGwV3fqVea5PwZj_EvyosiZ8,1079
5
- cachier/config.py,sha256=xEWpt_BeaqtrdDdZPnvZN_O3Wp4h6X9_6FfBpMeQZPw,2703
6
- cachier/core.py,sha256=IdLT2sfguDSvtCyX1EJfgCQnbEDECil1U2JhO5wBP5U,13080
7
- cachier/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- cachier/version.info,sha256=KYW-iyjTrehY6Nj7S8IvVlsb9gIN_5gtzhQfdyG5mZw,6
9
- cachier/cores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- cachier/cores/base.py,sha256=cxtcDfRttGU6YBtq7aO9mAqzEza2y7KhHDZhRbv-aOU,3324
11
- cachier/cores/memory.py,sha256=JFXnXBAeP0nOXOf_vNgpcEuRNjxre8WQjiUBa7yEYmY,3128
12
- cachier/cores/mongo.py,sha256=jOcqxIU8wqF2jS2lOfp-VFk5iyVMKHm6AzhFGkxGm0k,4889
13
- cachier/cores/pickle.py,sha256=dZXUBv7xZKg39IaUERnjPEAcjpDS8sBuObrnxMTqMmk,8871
14
- cachier-3.0.0.dist-info/LICENSE,sha256=-2WrMJkIa0gVP6YQHXXDT7ws-S3M2NEVEF4XF3K8qrY,1069
15
- cachier-3.0.0.dist-info/METADATA,sha256=-hfKZSKXrKC7m102SRmJjpcelAZDtD6DoS0gSgm_wv8,18871
16
- cachier-3.0.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
17
- cachier-3.0.0.dist-info/entry_points.txt,sha256=16JU8wc6a62BLuOXVNjAiXJRp0AB5LtEwiKGYMjZjv0,49
18
- cachier-3.0.0.dist-info/top_level.txt,sha256=_rW_HiJumDCch67YT-WAgzcyvKg5RiYDMZq9d-0ZpaE,8
19
- cachier-3.0.0.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- cachier = cachier.__naim__:cli