reflect cachew changes of exception handling and temporary suppression

This commit is contained in:
Dima Gerasimov 2020-10-04 21:35:24 +01:00 committed by karlicoss
parent d3f2551560
commit ced93e6942
12 changed files with 29 additions and 46 deletions

View file

@ -1,40 +1,29 @@
# TODO this probably belongs to cachew? or cachew.experimental
from contextlib import contextmanager
from pathlib import Path
def disable_cachew():
'''
NOTE: you need to use it before importing any function using @cachew.cachew
'''
# TODO not sure... maybe it should instead use some hook.. it's a ibt ugly do
try:
import cachew
except ImportError:
# nothing to disable
return
@cachew.doublewrap
def cachew_off(func=None, *args, **kwargs):
return func
old = cachew.cachew
cachew.cachew = cachew_off
return old
from cachew import settings
settings.ENABLE = False
@contextmanager
def disabled_cachew():
try:
import cachew
except ModuleNotFoundError:
# no need to disable anything
except ImportError:
# nothing to disable
yield
return
old = disable_cachew()
try:
from cachew.extra import disabled_cachew
with disabled_cachew():
yield
finally:
cachew.cachew = old
def cache_dir() -> Path: