core.common: deprecate outdated LazyLogger alias

This commit is contained in:
Dima Gerasimov 2024-08-16 12:12:40 +03:00 committed by karlicoss
parent 614c929f95
commit 7023088d13
13 changed files with 50 additions and 30 deletions

View file

@ -13,10 +13,15 @@ from .utils.itertools import warn_if_empty
from .cfg import make_config from .cfg import make_config
from .error import Res, unwrap from .error import Res, unwrap
from .logging import make_logger, LazyLogger from .logging import (
make_logger,
)
from .util import __NOT_HPI_MODULE__ from .util import __NOT_HPI_MODULE__
LazyLogger = make_logger # TODO deprecate this in favor of make_logger
if not TYPE_CHECKING: if not TYPE_CHECKING:
# we used to keep these here for brevity, but feels like it only adds confusion, # we used to keep these here for brevity, but feels like it only adds confusion,
# e.g. suggest that we perhaps somehow modify builtin behaviour or whatever # e.g. suggest that we perhaps somehow modify builtin behaviour or whatever

View file

@ -485,8 +485,8 @@ def _locate_functions_or_prompt(qualified_names: List[str], prompt: bool = True)
def _warn_exceptions(exc: Exception) -> None: def _warn_exceptions(exc: Exception) -> None:
from my.core.common import LazyLogger from my.core import make_logger
logger = LazyLogger('CLI', level='warning') logger = make_logger('CLI', level='warning')
logger.exception(f'hpi query: {exc}') logger.exception(f'hpi query: {exc}')

View file

@ -15,14 +15,11 @@ import warnings
from . import warnings as core_warnings from . import warnings as core_warnings
from . import compat from . import compat
from .compat import deprecated
# some helper functions # some helper functions
# TODO start deprecating this? soon we'd be able to use Path | str syntax which is shorter and more explicit
PathIsh = Union[Path, str] PathIsh = Union[Path, str]
from .logging import setup_logger, LazyLogger
Paths = Union[Sequence[PathIsh], PathIsh] Paths = Union[Sequence[PathIsh], PathIsh]
@ -152,6 +149,7 @@ from .utils.itertools import unique_everseen
## perhaps it doesn't work when it's used from typing_extensions ## perhaps it doesn't work when it's used from typing_extensions
if not TYPE_CHECKING: if not TYPE_CHECKING:
from .compat import deprecated
@deprecated('use my.core.compat.assert_never instead') @deprecated('use my.core.compat.assert_never instead')
def assert_never(*args, **kwargs): def assert_never(*args, **kwargs):
@ -207,9 +205,18 @@ if not TYPE_CHECKING:
return stats.stat(*args, **kwargs) return stats.stat(*args, **kwargs)
@deprecated('use my.core.make_logger instead')
def LazyLogger(*args, **kwargs):
from . import logging
return logging.LazyLogger(*args, **kwargs)
# todo wrap these in deprecated decorator as well? # todo wrap these in deprecated decorator as well?
from .cachew import mcachew # noqa: F401 from .cachew import mcachew # noqa: F401
# this is kinda internal, should just use my.core.logging.setup_logger if necessary
from .logging import setup_logger
# TODO hmm how to deprecate these in runtime? # TODO hmm how to deprecate these in runtime?
# tricky cause they are actually classes/types # tricky cause they are actually classes/types

View file

@ -6,11 +6,11 @@ from .internal import assert_subpackage; assert_subpackage(__name__)
from typing import Iterable, Any, Optional, Dict from typing import Iterable, Any, Optional, Dict
from .common import LazyLogger from .logging import make_logger
from .types import asdict, Json from .types import asdict, Json
logger = LazyLogger(__name__) logger = make_logger(__name__)
class config: class config:

View file

@ -4,7 +4,7 @@ from functools import lru_cache
import logging import logging
import os import os
import sys import sys
from typing import Union from typing import Union, TYPE_CHECKING
import warnings import warnings
@ -249,6 +249,16 @@ if __name__ == '__main__':
## legacy/deprecated methods for backwards compatilibity ## legacy/deprecated methods for backwards compatilibity
LazyLogger = make_logger if not TYPE_CHECKING:
logger = make_logger from .compat import deprecated
@deprecated('use make_logger instead')
def LazyLogger(*args, **kwargs):
return make_logger(*args, **kwargs)
@deprecated('use make_logger instead')
def logger(*args, **kwargs):
return make_logger(*args, **kwargs)
## ##

View file

@ -13,12 +13,12 @@ from typing import TYPE_CHECKING, Any, Iterable, Type, Dict, Literal, Callable,
from decorator import decorator from decorator import decorator
from . import warnings, Res from . import warnings, Res
from .common import LazyLogger from .logging import make_logger
from .types import Json, asdict from .types import Json, asdict
from .error import error_to_json, extract_error_datetime from .error import error_to_json, extract_error_datetime
logger = LazyLogger(__name__) logger = make_logger(__name__)
if TYPE_CHECKING: if TYPE_CHECKING:

View file

@ -8,10 +8,10 @@ from typing import Sequence, Generator, List, Union, Tuple
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path from pathlib import Path
from .common import LazyLogger from .logging import make_logger
logger = LazyLogger(__name__, level="info") logger = make_logger(__name__, level="info")
def _structure_exists(base_dir: Path, paths: Sequence[str], partial: bool = False) -> bool: def _structure_exists(base_dir: Path, paths: Sequence[str], partial: bool = False) -> bool:

View file

@ -9,11 +9,11 @@ import json
# TODO pytz for timezone??? # TODO pytz for timezone???
from .core.common import get_files, LazyLogger from my.core import get_files, make_logger
from my.config import foursquare as config from my.config import foursquare as config
logger = LazyLogger(__name__) logger = make_logger(__name__)
def inputs(): def inputs():

View file

@ -19,9 +19,8 @@ from dataclasses import dataclass
import os import os
from typing import List, Sequence, cast from typing import List, Sequence, cast
from pathlib import Path from pathlib import Path
from my.core import make_config, stat, Stats from my.core import make_config, stat, Stats, get_files, Paths, make_logger
from my.core.cachew import mcachew from my.core.cachew import mcachew
from my.core.common import LazyLogger, get_files, Paths
from my.core.error import ErrorPolicy from my.core.error import ErrorPolicy
from my.core.structure import match_structure from my.core.structure import match_structure
@ -52,7 +51,7 @@ class google(user_config):
config = make_config(google) config = make_config(google)
logger = LazyLogger(__name__, level="warning") logger = make_logger(__name__, level="warning")
# patch the takeout parser logger to match the computed loglevel # patch the takeout parser logger to match the computed loglevel
from google_takeout_parser.log import setup as setup_takeout_logger from google_takeout_parser.log import setup as setup_takeout_logger

View file

@ -8,9 +8,9 @@ from pathlib import Path
import pytz import pytz
from ..core.common import LazyLogger from my.core import make_logger
logger = LazyLogger(__name__) logger = make_logger(__name__)
from my.config import jawbone as config # type: ignore[attr-defined] from my.config import jawbone as config # type: ignore[attr-defined]

View file

@ -27,13 +27,13 @@ config = make_config(ip_config)
from functools import lru_cache from functools import lru_cache
from typing import Iterator, List from typing import Iterator, List
from my.core.common import LazyLogger from my.core import make_logger
from my.core.compat import bisect_left from my.core.compat import bisect_left
from my.ip.all import ips from my.ip.all import ips
from my.location.common import Location from my.location.common import Location
from my.location.fallback.common import FallbackLocation, DateExact, _datetime_timestamp from my.location.fallback.common import FallbackLocation, DateExact, _datetime_timestamp
logger = LazyLogger(__name__, level="warning") logger = make_logger(__name__, level="warning")
def fallback_locations() -> Iterator[FallbackLocation]: def fallback_locations() -> Iterator[FallbackLocation]:

View file

@ -19,8 +19,7 @@ import re
# pip3 install geopy # pip3 install geopy
import geopy # type: ignore import geopy # type: ignore
from my.core import stat, Stats from my.core import stat, Stats, make_logger
from my.core.common import LazyLogger
from my.core.cachew import cache_dir, mcachew from my.core.cachew import cache_dir, mcachew
from my.core.warnings import high from my.core.warnings import high
@ -33,7 +32,7 @@ high("Please set up my.google.takeout.parser module for better takeout support")
USE_GREP = False USE_GREP = False
logger = LazyLogger(__name__) logger = make_logger(__name__)
class Location(NamedTuple): class Location(NamedTuple):

View file

@ -11,7 +11,7 @@ from functools import cached_property
import re import re
from typing import Dict, List, Iterator from typing import Dict, List, Iterator
from my.core.common import LazyLogger, get_files from my.core import make_logger, get_files
from my.core.utils.itertools import make_dict from my.core.utils.itertools import make_dict
from my.config import rtm as config from my.config import rtm as config
@ -22,7 +22,7 @@ import icalendar # type: ignore
from icalendar.cal import Todo # type: ignore from icalendar.cal import Todo # type: ignore
logger = LazyLogger(__name__) logger = make_logger(__name__)
# TODO extract in a module to parse RTM's ical? # TODO extract in a module to parse RTM's ical?