From 7ff3280fd4939eae673c8d809286d9c431c0da68 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Sat, 27 Nov 2021 16:47:22 -0600 Subject: [PATCH] MNT #588 no more circular imports reported --- apstools/utils.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/apstools/utils.py b/apstools/utils.py index cbc781e41..57b9d4e0a 100644 --- a/apstools/utils.py +++ b/apstools/utils.py @@ -126,18 +126,12 @@ # The full license is in the file LICENSE.txt, distributed with this software. # ----------------------------------------------------------------------------- -from bluesky import plan_stubs as bps -from bluesky.callbacks.best_effort import BestEffortCallback -from collections import defaultdict -from collections import OrderedDict -from databroker._drivers.mongo_normalized import BlueskyMongoCatalog -from dataclasses import dataclass -from email.mime.text import MIMEText -from event_model import NumpyEncoder - import databroker import databroker.queries +import databroker._drivers.mongo_normalized +import databroker._drivers.msgpack import datetime +import intake import json import logging import math @@ -158,6 +152,14 @@ import warnings import zipfile +from bluesky import plan_stubs as bps +from bluesky.callbacks.best_effort import BestEffortCallback +from collections import defaultdict +from collections import OrderedDict +from dataclasses import dataclass +from email.mime.text import MIMEText +from event_model import NumpyEncoder + from .filewriters import _rebuild_scan_command from ._utils import * from ._utils import getDefaultNamespace @@ -166,10 +168,20 @@ logger = logging.getLogger(__name__) -MAX_EPICS_STRINGOUT_LENGTH = 40 - +CATALOG_CLASSES = ( + databroker.Broker, + databroker._drivers.mongo_normalized.BlueskyMongoCatalog, + databroker._drivers.msgpack.BlueskyMsgpackCatalog, + intake.Catalog, +) +MONGO_CATALOG_CLASSES = ( + databroker.Broker, + databroker._drivers.mongo_normalized.BlueskyMongoCatalog, + # intake.Catalog, +) FIRST_DATA = "1995-01-01" LAST_DATA = "2100-12-31" +MAX_EPICS_STRINGOUT_LENGTH = 40 class ExcelReadError(openpyxl.utils.exceptions.InvalidFileException): @@ -356,11 +368,9 @@ def getDefaultDatabase(): # note all database instances in memory db_list = [] - for k, v in g.items(): - if hasattr(v, "__class__") and not k.startswith("_"): - end = v.__class__.__name__.split(".")[-1] - if end in ("Broker", "BlueskyMongoCatalog"): - db_list.append(v) + for v in g.values(): + if isinstance(v, CATALOG_CLASSES): + db_list.append(v) # easy decisions first if len(db_list) == 0: @@ -943,7 +953,7 @@ def _sort(uid): exc, ) else: - if isinstance(cat, BlueskyMongoCatalog) and self.sortby == "time": + if isinstance(cat, MONGO_CATALOG_CLASSES) and self.sortby == "time": if self.reverse: # the default rendering: from MongoDB in reverse time order sequence = iter(cat)