From ddc5f2b4410236f2b524effd2457f8d70b39f005 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 7 Jul 2023 19:00:35 -0400 Subject: [PATCH] Use `MktPair.from_msg()` in symcache Since we now fully support interchange-as-dict-msg, use the msg codec API and drop manual `Asset` unpacking. Also, wrap `get_symcache()` in a `pdbp` crash handler block for now B) --- piker/data/_symcache.py | 80 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/piker/data/_symcache.py b/piker/data/_symcache.py index 799f2422..ad3c7004 100644 --- a/piker/data/_symcache.py +++ b/piker/data/_symcache.py @@ -239,40 +239,6 @@ def open_symcache( data: dict[str, dict] = tomllib.load(existing_fp) log.runtime(f'SYMCACHE TOML LOAD TIME: {time.time() - now}') - # load `dict` -> `Asset` - assettable = data.pop('assets') - for name, asdict in assettable.items(): - cache.assets[name] = Asset.from_msg(asdict) - - # load `dict` -> `MktPair` - dne: list[str] = [] - mkttable = data.pop('mktmaps') - for fqme, mktdict in mkttable.items(): - - # pull asset refs from (presumably) now previously - # loaded asset set above B) - src_k: str = mktdict.pop('src') - dst_k: str = mktdict.pop('dst') - src: Asset = cache.assets[src_k] - - dst: Asset - if not (dst := cache.assets.get(dst_k)): - dne.append(dst_k) - continue - - mkt = MktPair( - src=src, - dst=dst, - **mktdict, - ) - assert mkt.fqme == fqme - cache.mktmaps[fqme] = mkt - - log.warning( - f'These `MktPair.dst: Asset`s DNE says `{mod.name}` ?\n' - f'{pformat(dne)}' - ) - # copy in backend specific pairs table directly without # struct loading for now.. pairtable = data.pop('pairs') @@ -284,6 +250,38 @@ def open_symcache( # pair: Struct = cache.mod.load_pair(pairtable) # cache.pairs[key] = pair + # load `dict` -> `Asset` + assettable = data.pop('assets') + for name, asdict in assettable.items(): + cache.assets[name] = Asset.from_msg(asdict) + + # load `dict` -> `MktPair` + dne: list[str] = [] + mkttable = data.pop('mktmaps') + for fqme, mktdict in mkttable.items(): + + mkt = MktPair.from_msg(mktdict) + assert mkt.fqme == fqme + + # sanity check asset refs from those (presumably) + # loaded asset set above. + # src_k: str = pairtable.get('bs_src_asset, + src: Asset = cache.assets[mkt.src.name] + assert src == mkt.src + dst: Asset + if not (dst := cache.assets.get(mkt.dst.name)): + dne.append(mkt.dst.name) + continue + else: + assert dst.name == mkt.dst.name + + cache.mktmaps[fqme] = mkt + + log.warning( + f'These `MktPair.dst: Asset`s DNE says `{mod.name}` ?\n' + f'{pformat(dne)}' + ) + # TODO: use a real profiling sys.. # https://github.com/pikers/piker/issues/337 log.info(f'SYMCACHE LOAD TIME: {time.time() - now}') @@ -307,9 +305,13 @@ def get_symcache( ''' from ..brokers import get_brokermod - with open_symcache( - get_brokermod(provider), - reload=force_reload, + try: + with open_symcache( + get_brokermod(provider), + reload=force_reload, - ) as symcache: - return symcache + ) as symcache: + return symcache + except BaseException: + import pdbp + pdbp.xpm()