From 923b4de296390f18197d673ea15ebd74c78db5f6 Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 31 Mar 2026 14:16:40 -0400 Subject: [PATCH] Improve `load_accounts()` logging and defaults Move `'paper'` default entry into the initial `bidict` instead of appending post-loop. Add per-provider branch logging: an `info`-level msg accumulating each loaded `account_alias` and a `debug`-level msg (using `ppfmt()`) when a provider is skipped bc it wasn't requested. Also, - Early-`continue` when `accounts_section is None` instead of nesting inside an `else`. - Import `ppfmt` from `tractor.devx.pformat`. - Tighten union-type annotations to `X|Y` style. - De-structure loop vars for readability. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- piker/config.py | 63 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/piker/config.py b/piker/config.py index 80d094f2..4e286bd8 100644 --- a/piker/config.py +++ b/piker/config.py @@ -37,6 +37,7 @@ except ModuleNotFoundError: from tractor._exceptions import reg_err_types +from tractor.devx.pformat import ppfmt from .log import get_logger log = get_logger('broker-config') @@ -357,30 +358,56 @@ def write( def load_accounts( - providers: list[str] | None = None - -) -> bidict[str, str | None]: + providers: list[str]|None = None +) -> bidict[str, str|None]: conf, path = load( conf_name='brokers', ) - accounts = bidict() - for provider_name, section in conf.items(): - accounts_section = section.get('accounts') + accounts = bidict({ + # XXX, default paper-engine entry; this MUST be set. + 'paper': None, + }) + msg: str = ( + 'Loading account(s) from `brokers.toml`,\n' + ) + for ( + provider_name, + section, + ) in conf.items(): + accounts_section: dict[str, str] = section.get('accounts') + if accounts_section is None: + msg += f'No accounts declared for {provider_name!r}?\n' + continue + + # msg += f'Loaded accounts for {provider_name!r}?\n' if ( - providers is None or - providers and provider_name in providers + providers is None + or ( + providers + and + provider_name in providers + ) ): - if accounts_section is None: - log.warning(f'No accounts named for {provider_name}?') - continue - else: - for label, value in accounts_section.items(): - accounts[ - f'{provider_name}.{label}' - ] = value + for ( + label, + value, + ) in accounts_section.items(): + account_alias: str = f'{provider_name}.{label}' + accounts[account_alias] = value + msg += f'{account_alias} = {value!r}\n' - # our default paper engine entry - accounts['paper'] = None + else: + log.debug( + f'NOT loading account(s) for entry in `brokers.toml`,\n' + f'The account provider was not requested for loading.\n' + f'requested-providers: {providers!r}\n' + f'this-provider: {provider_name!r}\n' + f'\n' + f'{ppfmt(accounts_section)}\n' + ) + # ?TODO? mk this bp work? + # breakpoint() + log.info(msg) return accounts