reflect cachew changes of exception handling and temporary suppression
This commit is contained in:
parent
d3f2551560
commit
ced93e6942
12 changed files with 29 additions and 46 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue