my.core: deprecate Path/dataclass imports from my.core during type checking

runtime still works for backwards compatibility
This commit is contained in:
Dima Gerasimov 2024-08-16 00:14:44 +03:00 committed by karlicoss
parent 7f8a502310
commit 2b0f92c883
10 changed files with 34 additions and 18 deletions

View file

@ -6,6 +6,7 @@ REQUIRES = ['ijson', 'cffi']
# NOTE likely also needs libyajl2 from apt or elsewhere? # NOTE likely also needs libyajl2 from apt or elsewhere?
from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import Sequence, Iterable, List, Optional from typing import Sequence, Iterable, List, Optional
@ -22,8 +23,9 @@ def inputs() -> Sequence[Path]:
return get_files(user_config.logfiles) return get_files(user_config.logfiles)
from .core import dataclass, Json, PathIsh, datetime_aware
from .core.compat import fromisoformat from my.core import Json, PathIsh, datetime_aware
from my.core.compat import fromisoformat
@dataclass @dataclass

View file

@ -4,9 +4,10 @@ Parses active browser history by backing it up with [[http://github.com/seanbrec
REQUIRES = ["browserexport", "sqlite_backup"] REQUIRES = ["browserexport", "sqlite_backup"]
from dataclasses import dataclass
from my.config import browser as user_config from my.config import browser as user_config
from my.core import Paths, dataclass from my.core import Paths
@dataclass @dataclass

View file

@ -1,4 +1,6 @@
# this file only keeps the most common & critical types/utility functions # this file only keeps the most common & critical types/utility functions
from typing import TYPE_CHECKING
from .common import get_files, PathIsh, Paths from .common import get_files, PathIsh, Paths
from .common import Json from .common import Json
from .stats import stat, Stats from .stats import stat, Stats
@ -12,8 +14,10 @@ from .logging import make_logger, LazyLogger
from .util import __NOT_HPI_MODULE__ from .util import __NOT_HPI_MODULE__
# just for brevity in modules if not TYPE_CHECKING:
# todo not sure about these.. maybe best to rely on regular imports.. perhaps compare? # 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
# so best to prefer explicit behaviour
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
@ -34,7 +38,7 @@ __all__ = [
'Res', 'unwrap', 'Res', 'unwrap',
'dataclass', 'Path', # TODO deprecate these from use in my.core 'dataclass', 'Path',
] ]

View file

@ -1,10 +1,13 @@
''' '''
Bindings for the 'core' HPI configuration Bindings for the 'core' HPI configuration
''' '''
from dataclasses import dataclass
from pathlib import Path
import re import re
from typing import Sequence, Optional from typing import Sequence, Optional
from . import warnings, PathIsh, Path from . import warnings, PathIsh
try: try:
from my.config import core as user_config # type: ignore[attr-defined] from my.config import core as user_config # type: ignore[attr-defined]
@ -21,7 +24,6 @@ except Exception as e:
_HPI_CACHE_DIR_DEFAULT = '' _HPI_CACHE_DIR_DEFAULT = ''
from dataclasses import dataclass
@dataclass @dataclass
class Config(user_config): class Config(user_config):
''' '''

View file

@ -15,10 +15,11 @@ the cachew cache
REQUIRES = ["git+https://github.com/seanbreckenridge/google_takeout_parser"] REQUIRES = ["git+https://github.com/seanbreckenridge/google_takeout_parser"]
from contextlib import ExitStack from contextlib import ExitStack
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, dataclass, stat, Stats from my.core import make_config, stat, Stats
from my.core.cachew import mcachew from my.core.cachew import mcachew
from my.core.common import LazyLogger, get_files, Paths from my.core.common import LazyLogger, get_files, Paths
from my.core.error import ErrorPolicy from my.core.error import ErrorPolicy

View file

@ -2,7 +2,8 @@
Last.fm scrobbles Last.fm scrobbles
''' '''
from my.core import Paths, dataclass, make_logger from dataclasses import dataclass
from my.core import Paths, make_logger
from my.config import lastfm as user_config from my.config import lastfm as user_config

View file

@ -4,9 +4,10 @@ Converts IP addresses provided by my.location.ip to estimated locations
REQUIRES = ["git+https://github.com/seanbreckenridge/ipgeocache"] REQUIRES = ["git+https://github.com/seanbreckenridge/ipgeocache"]
from dataclasses import dataclass
from datetime import timedelta from datetime import timedelta
from my.core import dataclass, Stats, make_config from my.core import Stats, make_config
from my.config import location from my.config import location
from my.core.warnings import medium from my.core.warnings import medium

View file

@ -7,12 +7,13 @@ Extracts semantic location history using google_takeout_parser
REQUIRES = ["git+https://github.com/seanbreckenridge/google_takeout_parser"] REQUIRES = ["git+https://github.com/seanbreckenridge/google_takeout_parser"]
from dataclasses import dataclass
from typing import Iterator, List from typing import Iterator, List
from my.google.takeout.parser import events, _cachew_depends_on as _parser_cachew_depends_on from my.google.takeout.parser import events, _cachew_depends_on as _parser_cachew_depends_on
from google_takeout_parser.models import PlaceVisit as SemanticLocation from google_takeout_parser.models import PlaceVisit as SemanticLocation
from my.core import dataclass, make_config, stat, LazyLogger, Stats from my.core import make_config, stat, LazyLogger, Stats
from my.core.cachew import mcachew from my.core.cachew import mcachew
from my.core.error import Res from my.core.error import Res
from .common import Location from .common import Location

View file

@ -4,8 +4,11 @@ Parse [[https://github.com/mendhak/gpslogger][gpslogger]] .gpx (xml) files
REQUIRES = ["gpxpy"] REQUIRES = ["gpxpy"]
from dataclasses import dataclass
from my.config import location from my.config import location
from my.core import Paths, dataclass from my.core import Paths
@dataclass @dataclass

View file

@ -5,8 +5,9 @@ Stackexchange data (uses [[https://stackoverflow.com/legal/gdpr/request][officia
# TODO need to merge gdpr and stexport # TODO need to merge gdpr and stexport
### config ### config
from dataclasses import dataclass
from my.config import stackexchange as user_config from my.config import stackexchange as user_config
from ..core import dataclass, PathIsh, make_config, get_files from my.core import PathIsh, make_config, get_files, Json
@dataclass @dataclass
class stackexchange(user_config): class stackexchange(user_config):
gdpr_path: PathIsh # path to GDPR zip file gdpr_path: PathIsh # path to GDPR zip file
@ -16,8 +17,7 @@ config = make_config(stackexchange)
# TODO just merge all of them and then filter?.. not sure # TODO just merge all of them and then filter?.. not sure
from ..core.common import Json from my.core.compat import fromisoformat
from ..core.compat import fromisoformat
from typing import NamedTuple, Iterable from typing import NamedTuple, Iterable
from datetime import datetime from datetime import datetime
class Vote(NamedTuple): class Vote(NamedTuple):