diff --git a/piker/cli/__init__.py b/piker/cli/__init__.py index 1386bc83..c1b8aab0 100644 --- a/piker/cli/__init__.py +++ b/piker/cli/__init__.py @@ -36,7 +36,6 @@ from .. import config log = get_logger('cli') -DEFAULT_BROKER = 'questrade' @click.command() @@ -118,7 +117,7 @@ def pikerd( @click.group(context_settings=config._context_defaults) @click.option( '--brokers', '-b', - default=[DEFAULT_BROKER], + default=None, multiple=True, help='Broker backend to use' ) @@ -144,10 +143,13 @@ def cli( ctx.ensure_object(dict) - if len(brokers) == 1: - brokermods = [get_brokermod(brokers[0])] - else: - brokermods = [get_brokermod(broker) for broker in brokers] + if not brokers: + # (try to) load all (supposedly) supported data/broker backends + from piker.brokers import __brokers__ + brokers = __brokers__ + + brokermods = [get_brokermod(broker) for broker in brokers] + assert brokermods reg_addr: None | tuple[str, int] = None if host or port: diff --git a/piker/ui/_app.py b/piker/ui/_app.py index 38a4db20..23a9d2ed 100644 --- a/piker/ui/_app.py +++ b/piker/ui/_app.py @@ -19,15 +19,16 @@ Main app startup and run. ''' from functools import partial +from types import ModuleType from PyQt5.QtCore import QEvent import trio from .._daemon import maybe_spawn_brokerd -from ..brokers import get_brokermod from . import _event from ._exec import run_qtractor from ..data.feed import install_brokerd_search +from ..data._source import unpack_fqsn from . import _search from ._chart import GodWidget from ..log import get_logger @@ -36,27 +37,26 @@ log = get_logger(__name__) async def load_provider_search( - - broker: str, + brokermod: str, loglevel: str, ) -> None: - log.info(f'loading brokerd for {broker}..') + name = brokermod.name + log.info(f'loading brokerd for {name}..') async with ( maybe_spawn_brokerd( - broker, + name, loglevel=loglevel ) as portal, install_brokerd_search( portal, - get_brokermod(broker), + brokermod, ), ): - # keep search engine stream up until cancelled await trio.sleep_forever() @@ -67,7 +67,7 @@ async def _async_main( main_widget: GodWidget, syms: list[str], - brokernames: str, + brokers: dict[str, ModuleType], loglevel: str, ) -> None: @@ -99,6 +99,11 @@ async def _async_main( sbar = godwidget.window.status_bar starting_done = sbar.open_status('starting ze sexy chartz') + needed_brokermods: dict[str, ModuleType] = {} + for fqsn in syms: + brokername, *_ = unpack_fqsn(fqsn) + needed_brokermods[brokername] = brokers[brokername] + async with ( trio.open_nursery() as root_n, ): @@ -140,8 +145,12 @@ async def _async_main( ): # load other providers into search **after** # the chart's select cache - for broker in brokernames: - root_n.start_soon(load_provider_search, broker, loglevel) + for brokername, mod in needed_brokermods.items(): + root_n.start_soon( + load_provider_search, + mod, + loglevel, + ) await order_mode_ready.wait() @@ -171,7 +180,7 @@ async def _async_main( def _main( syms: list[str], - brokernames: [str], + brokermods: list[ModuleType], piker_loglevel: str, tractor_kwargs, ) -> None: @@ -182,7 +191,11 @@ def _main( ''' run_qtractor( func=_async_main, - args=(syms, brokernames, piker_loglevel), + args=( + syms, + {mod.name: mod for mod in brokermods}, + piker_loglevel, + ), main_widget_type=GodWidget, tractor_kwargs=tractor_kwargs, ) diff --git a/piker/ui/cli.py b/piker/ui/cli.py index 6716607a..a72c2f5c 100644 --- a/piker/ui/cli.py +++ b/piker/ui/cli.py @@ -166,16 +166,16 @@ def chart( )) return - # global opts brokernames = config['brokers'] + brokermods = config['brokermods'] + assert brokermods tractorloglevel = config['tractorloglevel'] pikerloglevel = config['loglevel'] - _main( syms=symbols, - brokernames=brokernames, + brokermods=brokermods, piker_loglevel=pikerloglevel, tractor_kwargs={ 'debug_mode': pdb,