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-codefix_kraken_account_alias_mismatch_reporting
parent
ebc5bbd42b
commit
923b4de296
|
|
@ -37,6 +37,7 @@ except ModuleNotFoundError:
|
||||||
|
|
||||||
|
|
||||||
from tractor._exceptions import reg_err_types
|
from tractor._exceptions import reg_err_types
|
||||||
|
from tractor.devx.pformat import ppfmt
|
||||||
from .log import get_logger
|
from .log import get_logger
|
||||||
|
|
||||||
log = get_logger('broker-config')
|
log = get_logger('broker-config')
|
||||||
|
|
@ -357,30 +358,56 @@ def write(
|
||||||
|
|
||||||
|
|
||||||
def load_accounts(
|
def load_accounts(
|
||||||
providers: list[str] | None = None
|
providers: list[str]|None = None
|
||||||
|
) -> bidict[str, str|None]:
|
||||||
) -> bidict[str, str | None]:
|
|
||||||
|
|
||||||
conf, path = load(
|
conf, path = load(
|
||||||
conf_name='brokers',
|
conf_name='brokers',
|
||||||
)
|
)
|
||||||
accounts = bidict()
|
accounts = bidict({
|
||||||
for provider_name, section in conf.items():
|
# XXX, default paper-engine entry; this MUST be set.
|
||||||
accounts_section = section.get('accounts')
|
'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 (
|
if (
|
||||||
providers is None or
|
providers is None
|
||||||
providers and provider_name in providers
|
or (
|
||||||
|
providers
|
||||||
|
and
|
||||||
|
provider_name in providers
|
||||||
|
)
|
||||||
):
|
):
|
||||||
if accounts_section is None:
|
for (
|
||||||
log.warning(f'No accounts named for {provider_name}?')
|
label,
|
||||||
continue
|
value,
|
||||||
else:
|
) in accounts_section.items():
|
||||||
for label, value in accounts_section.items():
|
account_alias: str = f'{provider_name}.{label}'
|
||||||
accounts[
|
accounts[account_alias] = value
|
||||||
f'{provider_name}.{label}'
|
msg += f'{account_alias} = {value!r}\n'
|
||||||
] = value
|
|
||||||
|
|
||||||
# our default paper engine entry
|
else:
|
||||||
accounts['paper'] = None
|
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
|
return accounts
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue