core: add base cachew directory
This commit is contained in:
parent
10a8ebaae4
commit
c54d85037c
4 changed files with 24 additions and 2 deletions
|
@ -13,6 +13,7 @@ from typing import Iterable, NamedTuple, Sequence, Set
|
|||
from ..common import mcachew, LazyLogger, get_files
|
||||
|
||||
|
||||
from ..core.cachew import cache_dir
|
||||
from my.config import bluemaestro as config
|
||||
|
||||
|
||||
|
@ -28,7 +29,7 @@ class Measurement(NamedTuple):
|
|||
temp: float
|
||||
|
||||
|
||||
@mcachew(cache_path=config.cache_path)
|
||||
@mcachew(cache_path=cache_dir() / 'bluemaestro.cache')
|
||||
def measurements(dbs=inputs()) -> Iterable[Measurement]:
|
||||
emitted: Set[datetime] = set()
|
||||
for f in dbs:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# TODO this probably belongs to cachew? or cachew.experimental
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def disable_cachew():
|
||||
|
@ -25,3 +26,21 @@ def disabled_cachew():
|
|||
yield
|
||||
finally:
|
||||
cachew.cachew = old
|
||||
|
||||
|
||||
def cache_dir() -> Path:
|
||||
'''
|
||||
Base directory for cachew.
|
||||
To override, add to your config file:
|
||||
class config:
|
||||
cache_dir = '/your/custom/cache/path'
|
||||
'''
|
||||
import my.config as C
|
||||
common_config = getattr(C, 'common', object())
|
||||
# TODO if attr is set _and_ it's none, disable cache?
|
||||
cdir = getattr(common_config, 'cache_dir', None)
|
||||
if cdir is None:
|
||||
# TODO fallback to default cachew dir instead?
|
||||
return Path('/var/tmp/cachew')
|
||||
else:
|
||||
return Path(cdir)
|
||||
|
|
|
@ -15,6 +15,7 @@ import pytz
|
|||
from more_itertools import bucket
|
||||
|
||||
from ..common import get_files, LazyLogger, cproperty, mcachew
|
||||
from ..core.cachew import cache_dir
|
||||
|
||||
from my.config import emfit as config
|
||||
|
||||
|
@ -292,7 +293,7 @@ def dir_hash(path: Path):
|
|||
|
||||
|
||||
# TODO take __file__ into account somehow?
|
||||
@mcachew(cache_path=config.cache_path, hashf=dir_hash, logger=logger)
|
||||
@mcachew(cache_path=cache_dir() / 'emfit.cache', hashf=dir_hash, logger=logger)
|
||||
def iter_datas(path: Path=config.export_path) -> Iterator[Emfit]:
|
||||
for f in get_files(path, glob='*.json'):
|
||||
sid = f.stem
|
||||
|
|
|
@ -30,6 +30,7 @@ from ..kython import kompress
|
|||
logger = LazyLogger(__name__)
|
||||
|
||||
|
||||
# todo switch to use cachew.cache_dir
|
||||
def cache_path(*args, **kwargs):
|
||||
from my.config import location as config
|
||||
return config.cache_path
|
||||
|
|
Loading…
Add table
Reference in a new issue