From 53a41ba93d4ce2bbb561d66fe1fab28357838c48 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 18 Apr 2023 18:17:45 -0400 Subject: [PATCH] Add subsys log to new `.data._util` --- piker/data/__init__.py | 2 +- piker/data/_m4.py | 5 +---- piker/data/_sampling.py | 6 ++---- piker/data/_sharedmem.py | 5 +---- piker/data/_source.py | 14 +------------- piker/data/_util.py | 34 ++++++++++++++++++++++++++++++++++ piker/data/_web_bs.py | 5 +---- piker/data/cli.py | 7 ++----- piker/data/flows.py | 8 +++----- piker/data/ingest.py | 2 +- 10 files changed, 47 insertions(+), 41 deletions(-) create mode 100644 piker/data/_util.py diff --git a/piker/data/__init__.py b/piker/data/__init__.py index 74eefb83..37da54b0 100644 --- a/piker/data/__init__.py +++ b/piker/data/__init__.py @@ -25,7 +25,7 @@ sharing live streams over a network. import tractor import trio -from ..log import ( +from ._util import ( get_console_log, ) from ._normalize import iterticks diff --git a/piker/data/_m4.py b/piker/data/_m4.py index 8452e022..3c23d966 100644 --- a/piker/data/_m4.py +++ b/piker/data/_m4.py @@ -42,10 +42,7 @@ from numba import ( # float64, optional, int64, ) -from ..log import get_logger - - -log = get_logger(__name__) +from ._util import log def ds_m4( diff --git a/piker/data/_sampling.py b/piker/data/_sampling.py index 208a686b..3c769551 100644 --- a/piker/data/_sampling.py +++ b/piker/data/_sampling.py @@ -38,8 +38,8 @@ from tractor.trionics import ( import trio from trio_typing import TaskStatus -from ..log import ( - get_logger, +from ._util import ( + log, get_console_log, ) from ..service import maybe_spawn_daemon @@ -50,8 +50,6 @@ if TYPE_CHECKING: ) from .feed import _FeedsBus -log = get_logger(__name__) - # highest frequency sample step is 1 second by default, though in # the future we may want to support shorter periods or a dynamic style diff --git a/piker/data/_sharedmem.py b/piker/data/_sharedmem.py index 00865731..2ed1c892 100644 --- a/piker/data/_sharedmem.py +++ b/piker/data/_sharedmem.py @@ -32,14 +32,11 @@ import numpy as np from numpy.lib import recfunctions as rfn import tractor -from ..log import get_logger +from ._util import log from ._source import base_iohlc_dtype from .types import Struct -log = get_logger(__name__) - - # how much is probably dependent on lifestyle _secs_in_day = int(60 * 60 * 24) # we try for a buncha times, but only on a run-every-other-day kinda week. diff --git a/piker/data/_source.py b/piker/data/_source.py index 61c2e52f..d1d8be02 100644 --- a/piker/data/_source.py +++ b/piker/data/_source.py @@ -1,5 +1,5 @@ # piker: trading gear for hackers -# Copyright (C) 2018-present Tyler Goodlet (in stewardship for piker0) +# Copyright (C) 2018-present Tyler Goodlet (in stewardship for pikers) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -18,22 +18,10 @@ numpy data source coversion helpers. """ from __future__ import annotations -from decimal import ( - Decimal, - ROUND_HALF_EVEN, -) -from typing import Any from bidict import bidict import numpy as np -from .types import Struct -from ..accounting._mktinfo import ( - # mkfqsn, - unpack_fqsn, - # digits_to_dec, - float_digits, -) ohlc_fields = [ ('time', float), diff --git a/piker/data/_util.py b/piker/data/_util.py new file mode 100644 index 00000000..8c78255f --- /dev/null +++ b/piker/data/_util.py @@ -0,0 +1,34 @@ +# piker: trading gear for hackers +# Copyright (C) Tyler Goodlet (in stewardship for pikers) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +''' +Data layer module commons. + +''' +from functools import partial + +from ..log import ( + get_logger, + get_console_log, +) +subsys: str = 'piker.data' + +log = get_logger(subsys) + +get_console_log = partial( + get_console_log, + name=subsys, +) diff --git a/piker/data/_web_bs.py b/piker/data/_web_bs.py index 21b06d68..864ca651 100644 --- a/piker/data/_web_bs.py +++ b/piker/data/_web_bs.py @@ -44,12 +44,9 @@ from trio_websocket._impl import ( ConnectionTimeout, ) -from ..log import get_logger - +from ._util import log from .types import Struct -log = get_logger(__name__) - class NoBsWs: ''' diff --git a/piker/data/cli.py b/piker/data/cli.py index 6984d9ff..cee729e5 100644 --- a/piker/data/cli.py +++ b/piker/data/cli.py @@ -32,14 +32,11 @@ from ..service.marketstore import ( ) from ..cli import cli from .. import watchlists as wl -from ..log import ( - get_logger, +from ._util import ( + log, ) -log = get_logger(__name__) - - @cli.command() @click.option( '--url', diff --git a/piker/data/flows.py b/piker/data/flows.py index 1ddd35c2..ecb727e8 100644 --- a/piker/data/flows.py +++ b/piker/data/flows.py @@ -15,7 +15,7 @@ # along with this program. If not, see . """ -abstractions for organizing, managing and generally operating-on +Public abstractions for organizing, managing and generally operating-on real-time data processing data-structures. "Streams, flumes, cascades and flows.." @@ -35,8 +35,8 @@ from ..accounting._mktinfo import ( MktPair, Symbol, ) -from ..log import ( - get_logger, +from ._util import ( + log, ) from .types import Struct from ._sharedmem import ( @@ -53,8 +53,6 @@ if TYPE_CHECKING: # from pyqtgraph import PlotItem from .feed import Feed -log = get_logger(__name__) - # TODO: ideas for further abstractions as per # https://github.com/pikers/piker/issues/216 and diff --git a/piker/data/ingest.py b/piker/data/ingest.py index afb5fc4a..c6f50135 100644 --- a/piker/data/ingest.py +++ b/piker/data/ingest.py @@ -23,7 +23,7 @@ Api layer likely in here... from types import ModuleType from importlib import import_module -from ..log import get_logger +from ._util import get_logger log = get_logger(__name__)